Skip to content

Commit 856471f

Browse files
authored
Merge branch 'main' into seanmcm/improveDiagnosticsSource
2 parents f52fea2 + d83faa2 commit 856471f

6 files changed

Lines changed: 82 additions & 44 deletions

File tree

.github/actions/.npmrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
registry=https://pkgs.dev.azure.com/azure-public/VisualCpp/_packaging/cpp_PublicPackages/npm/registry/
2-
always-auth=true
32
# Disable postinstall scripts for supply chain security. Allowlist exceptions with npm trust: https://docs.npmjs.com/cli/v11/commands/npm-trust
43
ignore-scripts=true

Extension/.npmrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
registry=https://pkgs.dev.azure.com/azure-public/VisualCpp/_packaging/cpp_PublicPackages/npm/registry/
2-
always-auth=true
32
# Disable postinstall scripts for supply chain security. Allowlist exceptions with npm trust: https://docs.npmjs.com/cli/v11/commands/npm-trust
43
ignore-scripts=true

Extension/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"license": "SEE LICENSE IN LICENSE.txt",
1313
"engines": {
14-
"vscode": "^1.67.0"
14+
"vscode": "^1.77.0"
1515
},
1616
"bugs": {
1717
"url": "https://github.com/Microsoft/vscode-cpptools/issues",
@@ -6920,7 +6920,7 @@
69206920
"ssh-config": "^4.4.4",
69216921
"tmp": "^0.2.6",
69226922
"vscode-cpptools": "^7.1.1",
6923-
"vscode-languageclient": "^8.1.0",
6923+
"vscode-languageclient": "^9.0.1",
69246924
"vscode-nls": "^5.2.0",
69256925
"vscode-tas-client": "^0.1.84",
69266926
"which": "^2.0.2"

Extension/src/LanguageServer/client.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ export interface Client {
818818
getKnownCompilers(): Thenable<configs.KnownCompiler[] | undefined>;
819819
takeOwnership(document: vscode.TextDocument): void;
820820
sendDidOpen(document: vscode.TextDocument): Promise<void>;
821-
requestSwitchHeaderSource(rootUri: vscode.Uri, fileName: string): Thenable<string>;
821+
requestSwitchHeaderSource(rootUri: vscode.Uri, fileName: string, token: vscode.CancellationToken): Thenable<string>;
822822
updateActiveDocumentTextOptions(): void;
823823
didChangeActiveEditor(editor?: vscode.TextEditor, selection?: Range): Promise<void>;
824824
restartIntelliSenseForFile(document: vscode.TextDocument): Promise<void>;
@@ -3105,12 +3105,23 @@ export class DefaultClient implements Client {
31053105
/**
31063106
* requests to the language server
31073107
*/
3108-
public async requestSwitchHeaderSource(rootUri: vscode.Uri, fileName: string): Promise<string> {
3108+
public async requestSwitchHeaderSource(rootUri: vscode.Uri, fileName: string, token: vscode.CancellationToken): Promise<string> {
31093109
const params: SwitchHeaderSourceParams = {
31103110
switchHeaderSourceFileName: fileName,
31113111
workspaceFolderUri: rootUri.toString()
31123112
};
3113-
return this.enqueue(async () => this.languageClient.sendRequest(SwitchHeaderSourceRequest, params));
3113+
return this.enqueue(async () => {
3114+
// Don't use withLspCancellationHandling() or withCancellation() here. If the switch target is already known,
3115+
// the caller should still be able to use it even if the progress notification was just cancelled.
3116+
try {
3117+
return await this.languageClient.sendRequest(SwitchHeaderSourceRequest, params, token);
3118+
} catch (e: any) {
3119+
if (e instanceof ResponseError && (e.code === RequestCancelled || e.code === ServerCancelled)) {
3120+
throw new vscode.CancellationError();
3121+
}
3122+
throw e;
3123+
}
3124+
});
31143125
}
31153126

31163127
public async requestCompiler(newCompilerPath?: string): Promise<configs.CompilerDefaults> {
@@ -4461,7 +4472,7 @@ class NullClient implements Client {
44614472
getKnownCompilers(): Thenable<configs.KnownCompiler[] | undefined> { return Promise.resolve([]); }
44624473
takeOwnership(document: vscode.TextDocument): void { }
44634474
sendDidOpen(document: vscode.TextDocument): Promise<void> { return Promise.resolve(); }
4464-
requestSwitchHeaderSource(rootUri: vscode.Uri, fileName: string): Thenable<string> { return Promise.resolve(""); }
4475+
requestSwitchHeaderSource(rootUri: vscode.Uri, fileName: string, token: vscode.CancellationToken): Thenable<string> { return Promise.resolve(""); }
44654476
updateActiveDocumentTextOptions(): void { }
44664477
didChangeActiveEditor(editor?: vscode.TextEditor): Promise<void> { return Promise.resolve(); }
44674478
restartIntelliSenseForFile(document: vscode.TextDocument): Promise<void> { return Promise.resolve(); }

Extension/src/LanguageServer/extension.ts

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -480,19 +480,66 @@ async function onSwitchHeaderSource(): Promise<void> {
480480
rootUri = vscode.Uri.file(path.dirname(fileName)); // When switching without a folder open.
481481
}
482482

483-
let targetFileName: string = await clients.ActiveClient.requestSwitchHeaderSource(rootUri, fileName);
484-
// If the targetFileName has a path that is a symlink target of a workspace folder,
485-
// then replace the RootRealPath with the RootPath (the symlink path).
486-
let targetFileNameReplaced: boolean = false;
487-
clients.forEach(client => {
488-
if (!targetFileNameReplaced && client.RootRealPath && client.RootPath !== client.RootRealPath
489-
&& targetFileName.startsWith(client.RootRealPath)) {
490-
targetFileName = client.RootPath + targetFileName.substring(client.RootRealPath.length);
491-
targetFileNameReplaced = true;
483+
const switchHeaderSource: (token: vscode.CancellationToken) => Promise<void> = async (token: vscode.CancellationToken) => {
484+
try {
485+
let targetFileName: string = await clients.ActiveClient.requestSwitchHeaderSource(rootUri, fileName, token);
486+
if (!targetFileName) {
487+
return;
488+
}
489+
// If the targetFileName has a path that is a symlink target of a workspace folder,
490+
// then replace the RootRealPath with the RootPath (the symlink path).
491+
let targetFileNameReplaced: boolean = false;
492+
clients.forEach(client => {
493+
if (!targetFileNameReplaced && client.RootRealPath && client.RootPath !== client.RootRealPath
494+
&& targetFileName.startsWith(client.RootRealPath)) {
495+
targetFileName = client.RootPath + targetFileName.substring(client.RootRealPath.length);
496+
targetFileNameReplaced = true;
497+
}
498+
});
499+
const document: vscode.TextDocument = await vscode.workspace.openTextDocument(targetFileName);
500+
await vscode.window.showTextDocument(document).then(undefined, logAndReturn.undefined);
501+
} catch (e) {
502+
if (e instanceof vscode.CancellationError) {
503+
return;
504+
}
505+
throw e;
492506
}
493-
});
494-
const document: vscode.TextDocument = await vscode.workspace.openTextDocument(targetFileName);
495-
void vscode.window.showTextDocument(document).then(undefined, logAndReturn.undefined);
507+
};
508+
509+
const tokenSource: vscode.CancellationTokenSource = new vscode.CancellationTokenSource();
510+
try {
511+
const switchHeaderSourcePromise: Promise<void> = switchHeaderSource(tokenSource.token);
512+
const showProgress: boolean = await new Promise<boolean>((resolve, reject) => {
513+
const timer: NodeJS.Timeout = global.setTimeout(() => resolve(true), 2000);
514+
void switchHeaderSourcePromise.then(() => {
515+
clearTimeout(timer);
516+
resolve(false);
517+
}, (e) => {
518+
clearTimeout(timer);
519+
reject(e);
520+
});
521+
});
522+
523+
if (!showProgress) {
524+
await switchHeaderSourcePromise;
525+
return;
526+
}
527+
528+
await vscode.window.withProgress({
529+
location: vscode.ProgressLocation.Notification,
530+
title: localize('switch.header.source', 'Switching Header/Source...'),
531+
cancellable: true
532+
}, async (_progress, token) => {
533+
const cancellationListener: vscode.Disposable = token.onCancellationRequested(() => tokenSource.cancel());
534+
try {
535+
await switchHeaderSourcePromise;
536+
} finally {
537+
cancellationListener.dispose();
538+
}
539+
});
540+
} finally {
541+
tokenSource.dispose();
542+
}
496543
}
497544

498545
/**

Extension/yarn.lock

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6471,46 +6471,28 @@ vscode-cpptools@^7.1.1:
64716471
resolved "https://pkgs.dev.azure.com/azure-public/VisualCpp/_packaging/cpp_PublicPackages/npm/registry/vscode-cpptools/-/vscode-cpptools-7.1.1.tgz#adde3b6d627ddae5397224daa3e41952b219126b"
64726472
integrity sha1-rd47bWJ92uU5ciTao+QZUrIZEms=
64736473

6474-
vscode-jsonrpc@8.1.0:
6475-
version "8.1.0"
6476-
resolved "https://pkgs.dev.azure.com/azure-public/VisualCpp/_packaging/cpp_PublicPackages/npm/registry/vscode-jsonrpc/-/vscode-jsonrpc-8.1.0.tgz#cb9989c65e219e18533cc38e767611272d274c94"
6477-
integrity sha1-y5mJxl4hnhhTPMOOdnYRJy0nTJQ=
6478-
64796474
vscode-jsonrpc@8.2.0:
64806475
version "8.2.0"
64816476
resolved "https://pkgs.dev.azure.com/azure-public/VisualCpp/_packaging/cpp_PublicPackages/npm/registry/vscode-jsonrpc/-/vscode-jsonrpc-8.2.0.tgz#f43dfa35fb51e763d17cd94dcca0c9458f35abf9"
64826477
integrity sha1-9D36NftR52PRfNlNzKDJRY81q/k=
64836478

6484-
vscode-languageclient@^8.1.0:
6485-
version "8.1.0"
6486-
resolved "https://pkgs.dev.azure.com/azure-public/VisualCpp/_packaging/cpp_PublicPackages/npm/registry/vscode-languageclient/-/vscode-languageclient-8.1.0.tgz#3e67d5d841481ac66ddbdaa55b4118742f6a9f3f"
6487-
integrity sha1-PmfV2EFIGsZt29qlW0EYdC9qnz8=
6479+
vscode-languageclient@^9.0.1:
6480+
version "9.0.1"
6481+
resolved "https://pkgs.dev.azure.com/azure-public/VisualCpp/_packaging/cpp_PublicPackages/npm/registry/vscode-languageclient/-/vscode-languageclient-9.0.1.tgz#cdfe20267726c8d4db839dc1e9d1816e1296e854"
6482+
integrity sha1-zf4gJncmyNTbg53B6dGBbhKW6FQ=
64886483
dependencies:
64896484
minimatch "^5.1.0"
64906485
semver "^7.3.7"
6491-
vscode-languageserver-protocol "3.17.3"
6486+
vscode-languageserver-protocol "3.17.5"
64926487

6493-
vscode-languageserver-protocol@3.17.3:
6494-
version "3.17.3"
6495-
resolved "https://pkgs.dev.azure.com/azure-public/VisualCpp/_packaging/cpp_PublicPackages/npm/registry/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.17.3.tgz#6d0d54da093f0c0ee3060b81612cce0f11060d57"
6496-
integrity sha1-bQ1U2gk/DA7jBguBYSzODxEGDVc=
6497-
dependencies:
6498-
vscode-jsonrpc "8.1.0"
6499-
vscode-languageserver-types "3.17.3"
6500-
6501-
vscode-languageserver-protocol@^3.17.5:
6488+
vscode-languageserver-protocol@3.17.5, vscode-languageserver-protocol@^3.17.5:
65026489
version "3.17.5"
65036490
resolved "https://pkgs.dev.azure.com/azure-public/VisualCpp/_packaging/cpp_PublicPackages/npm/registry/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.17.5.tgz#864a8b8f390835572f4e13bd9f8313d0e3ac4bea"
65046491
integrity sha1-hkqLjzkINVcvThO9n4MT0OOsS+o=
65056492
dependencies:
65066493
vscode-jsonrpc "8.2.0"
65076494
vscode-languageserver-types "3.17.5"
65086495

6509-
vscode-languageserver-types@3.17.3:
6510-
version "3.17.3"
6511-
resolved "https://pkgs.dev.azure.com/azure-public/VisualCpp/_packaging/cpp_PublicPackages/npm/registry/vscode-languageserver-types/-/vscode-languageserver-types-3.17.3.tgz#72d05e47b73be93acb84d6e311b5786390f13f64"
6512-
integrity sha1-ctBeR7c76TrLhNbjEbV4Y5DxP2Q=
6513-
65146496
vscode-languageserver-types@3.17.5:
65156497
version "3.17.5"
65166498
resolved "https://pkgs.dev.azure.com/azure-public/VisualCpp/_packaging/cpp_PublicPackages/npm/registry/vscode-languageserver-types/-/vscode-languageserver-types-3.17.5.tgz#3273676f0cf2eab40b3f44d085acbb7f08a39d8a"

0 commit comments

Comments
 (0)