Skip to content

Commit 3790fa9

Browse files
authored
Add intelliSenseEngine "Disabled". (#2392)
* Add intelliSenseEngine "Disabled".
1 parent a088244 commit 3790fa9

File tree

5 files changed

+46
-11
lines changed

5 files changed

+46
-11
lines changed

Extension/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@
104104
"type": "string",
105105
"enum": [
106106
"Default",
107-
"Tag Parser"
107+
"Tag Parser",
108+
"Disabled"
108109
],
109110
"default": "Default",
110111
"description": "Controls the IntelliSense provider. \"Tag Parser\" provides \"fuzzy\" results that are not context-aware. \"Default\" provides context-aware results and is in preview mode - member list, hover tooltips, and error squiggles are currently implemented. Features not yet implemented in the new default engine will use the tag parser engine instead.",

Extension/src/LanguageServer/client.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ class DefaultClient implements Client {
651651
private registerNotifications(): void {
652652
console.assert(this.languageClient !== undefined, "This method must not be called until this.languageClient is set in \"onReady\"");
653653

654-
this.languageClient.onNotification(ReloadWindowNotification, () => this.reloadWindow());
654+
this.languageClient.onNotification(ReloadWindowNotification, () => util.promptForReloadWindowDueToSettingsChange());
655655
this.languageClient.onNotification(LogTelemetryNotification, (e) => this.logTelemetry(e));
656656
this.languageClient.onNotification(ReportNavigationNotification, (e) => this.navigate(e));
657657
this.languageClient.onNotification(ReportStatusNotification, (e) => this.updateStatus(e));
@@ -722,15 +722,6 @@ class DefaultClient implements Client {
722722
* handle notifications coming from the language server
723723
*******************************************************/
724724

725-
private reloadWindow(): void {
726-
let reload: string = "Reload";
727-
vscode.window.showInformationMessage("Reload the workspace for the settings change to take effect.", reload).then((value: string) => {
728-
if (value === reload) {
729-
vscode.commands.executeCommand("workbench.action.reloadWindow");
730-
}
731-
});
732-
}
733-
734725
private logTelemetry(notificationBody: TelemetryPayload): void {
735726
telemetry.logLanguageServerEvent(notificationBody.event, notificationBody.properties, notificationBody.metrics);
736727
}

Extension/src/commands.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class TemporaryCommandRegistrar {
1111
// Used to save/re-execute commands used before the extension has activated (e.g. delayed by dependency downloading).
1212
private delayedCommandsToExecute: Set<string>;
1313
private tempCommands: vscode.Disposable[]; // Need to save this to unregister/dispose the temporary commands.
14+
private isLanguageServerDisabled: boolean;
1415

1516
private commandsToRegister: string[] = [
1617
"C_Cpp.ConfigurationEdit",
@@ -44,10 +45,18 @@ class TemporaryCommandRegistrar {
4445

4546
public registerTempCommand(command: string): void {
4647
this.tempCommands.push(vscode.commands.registerCommand(command, () => {
48+
if (this.isLanguageServerDisabled) {
49+
vscode.window.showInformationMessage("The command is disabled because \"C_Cpp.intelliSenseEngine\" is set to \"Disabled\".");
50+
return;
51+
}
4752
this.delayedCommandsToExecute.add(command);
4853
}));
4954
}
5055

56+
public disableLanguageServer(): void {
57+
this.isLanguageServerDisabled = true;
58+
}
59+
5160
public activateLanguageServer(): void {
5261
// Main activation code.
5362
this.tempCommands.forEach((command) => {

Extension/src/common.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,3 +548,12 @@ export async function renamePromise(oldName: string, newName: string): Promise<v
548548
});
549549
});
550550
}
551+
552+
export function promptForReloadWindowDueToSettingsChange(): void {
553+
let reload: string = "Reload";
554+
vscode.window.showInformationMessage("Reload the workspace for the settings change to take effect.", reload).then((value: string) => {
555+
if (value === reload) {
556+
vscode.commands.executeCommand("workbench.action.reloadWindow");
557+
}
558+
});
559+
}

Extension/src/main.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ import { CppTools1 } from './cppTools1';
2424

2525
const releaseNotesVersion: number = 3;
2626
const cppTools: CppTools1 = new CppTools1();
27+
let languageServiceDisabled: boolean = false;
28+
let reloadMessageShown: boolean = false;
29+
let disposables: vscode.Disposable[] = [];
2730

2831
export async function activate(context: vscode.ExtensionContext): Promise<CppToolsApi & CppToolsExtension> {
2932
initializeTemporaryCommandRegistrar();
@@ -42,6 +45,11 @@ export async function activate(context: vscode.ExtensionContext): Promise<CppToo
4245
export function deactivate(): Thenable<void> {
4346
DebuggerExtension.dispose();
4447
Telemetry.deactivate();
48+
disposables.forEach(d => d.dispose());
49+
50+
if (languageServiceDisabled) {
51+
return;
52+
}
4553
return LanguageServer.deactivate();
4654
}
4755

@@ -279,6 +287,23 @@ async function postInstall(info: PlatformInformation): Promise<void> {
279287
}
280288

281289
async function finalizeExtensionActivation(): Promise<void> {
290+
if (vscode.workspace.getConfiguration("C_Cpp", null).get<string>("intelliSenseEngine") === "Disabled") {
291+
languageServiceDisabled = true;
292+
getTemporaryCommandRegistrarInstance().disableLanguageServer();
293+
disposables.push(vscode.workspace.onDidChangeConfiguration(() => {
294+
if (!reloadMessageShown && vscode.workspace.getConfiguration("C_Cpp", null).get<string>("intelliSenseEngine") !== "Disabled") {
295+
reloadMessageShown = true;
296+
util.promptForReloadWindowDueToSettingsChange();
297+
}
298+
}));
299+
return;
300+
}
301+
disposables.push(vscode.workspace.onDidChangeConfiguration(() => {
302+
if (!reloadMessageShown && vscode.workspace.getConfiguration("C_Cpp", null).get<string>("intelliSenseEngine") === "Disabled") {
303+
reloadMessageShown = true;
304+
util.promptForReloadWindowDueToSettingsChange();
305+
}
306+
}));
282307
getTemporaryCommandRegistrarInstance().activateLanguageServer();
283308

284309
// Update default for C_Cpp.intelliSenseEngine based on A/B testing settings.

0 commit comments

Comments
 (0)