From 77f37476300171b7f8696c313e477f08901fe764 Mon Sep 17 00:00:00 2001 From: Sean McManus Date: Wed, 1 May 2019 14:26:55 -0700 Subject: [PATCH] Fix `includePath` code actions and configuration actions. (#3576) * Fix `includePath` code actions amd configuration actions. --- Extension/CHANGELOG.md | 4 +- Extension/src/LanguageServer/client.ts | 6 +-- .../src/LanguageServer/configurations.ts | 40 ++++++++++++------- Extension/src/LanguageServer/extension.ts | 10 +++++ 4 files changed, 41 insertions(+), 19 deletions(-) diff --git a/Extension/CHANGELOG.md b/Extension/CHANGELOG.md index 5174ad8e25..a207fd1886 100644 --- a/Extension/CHANGELOG.md +++ b/Extension/CHANGELOG.md @@ -1,6 +1,6 @@ # C/C++ for Visual Studio Code Change Log -## Version 0.23.0-insiders2: April 30, 2019 +## Version 0.23.0-insiders2: May 1, 2019 ### New Features * Add support for `.env` files for `cppvsdbg`. [#3490](https://github.com/Microsoft/vscode-cpptools/issues/3490) @@ -20,6 +20,8 @@ * Fix backslashes getting added each time settings are saved. [#3526](https://github.com/Microsoft/vscode-cpptools/issues/3526) * Fix regression with some C++17 features with `msvc-x64` mode. [#3541](https://github.com/Microsoft/vscode-cpptools/issues/3541) * Fix `Go to Definition` giving no results when IntelliSense doesn't find the symbol. [#3549](https://github.com/Microsoft/vscode-cpptools/issues/3549) +* Fix configuration squiggles with trailing backslashes. [PR #3573](https://github.com/Microsoft/vscode-cpptools/pull/3573) +* Fix `includePath` code actions, configuration prompts, and the `C/C++: Change configuration provider...` command. [PR #3576](https://github.com/Microsoft/vscode-cpptools/pull/3576) * Fix crash on hover (that could occur when document comments have blank lines). * Fix randomly occurring crash (that could occur when opening files while IntelliSense squiggles are pending). diff --git a/Extension/src/LanguageServer/client.ts b/Extension/src/LanguageServer/client.ts index 98677c6e32..53b5cec656 100644 --- a/Extension/src/LanguageServer/client.ts +++ b/Extension/src/LanguageServer/client.ts @@ -1397,15 +1397,15 @@ class DefaultClient implements Client { } public handleConfigurationEditCommand(): void { - this.notifyWhenReady(() => this.configuration.handleConfigurationEditCommand(vscode.window.showTextDocument)); + this.notifyWhenReady(() => this.configuration.handleConfigurationEditCommand(null, vscode.window.showTextDocument)); } public handleConfigurationEditJSONCommand(): void { - this.notifyWhenReady(() => this.configuration.handleConfigurationEditJSONCommand(vscode.window.showTextDocument)); + this.notifyWhenReady(() => this.configuration.handleConfigurationEditJSONCommand(null, vscode.window.showTextDocument)); } public handleConfigurationEditUICommand(): void { - this.notifyWhenReady(() => this.configuration.handleConfigurationEditUICommand(vscode.window.showTextDocument)); + this.notifyWhenReady(() => this.configuration.handleConfigurationEditUICommand(null, vscode.window.showTextDocument)); } public handleAddToIncludePathCommand(path: string): void { diff --git a/Extension/src/LanguageServer/configurations.ts b/Extension/src/LanguageServer/configurations.ts index f1bb85bb28..cfb5c45015 100644 --- a/Extension/src/LanguageServer/configurations.ts +++ b/Extension/src/LanguageServer/configurations.ts @@ -414,7 +414,7 @@ export class CppProperties { } public addToIncludePathCommand(path: string): void { - this.handleConfigurationEditCommand((document: vscode.TextDocument) => { + this.handleConfigurationEditCommand(() => { telemetry.logLanguageServerEvent("addToIncludePath"); this.parsePropertiesFile(true); // Clear out any modifications we may have made internally. let config: Configuration = this.CurrentConfiguration; @@ -424,13 +424,13 @@ export class CppProperties { config.includePath.splice(config.includePath.length, 0, path); this.writeToJson(); this.handleConfigurationChange(); - }); + }, null); } public updateCustomConfigurationProvider(providerId: string): Thenable { return new Promise((resolve) => { if (this.propertiesFile) { - this.handleConfigurationEditCommand((document: vscode.TextDocument) => { + this.handleConfigurationEditJSONCommand(() => { this.parsePropertiesFile(true); // Clear out any modifications we may have made internally. let config: Configuration = this.CurrentConfiguration; if (providerId) { @@ -441,7 +441,7 @@ export class CppProperties { this.writeToJson(); this.handleConfigurationChange(); resolve(); - }); + }, null); } else { let settings: CppSettings = new CppSettings(this.rootUri); if (providerId) { @@ -456,22 +456,22 @@ export class CppProperties { } public setCompileCommands(path: string): void { - this.handleConfigurationEditCommand((document: vscode.TextDocument) => { + this.handleConfigurationEditJSONCommand(() => { this.parsePropertiesFile(true); // Clear out any modifications we may have made internally. let config: Configuration = this.CurrentConfiguration; config.compileCommands = path; this.writeToJson(); this.handleConfigurationChange(); - }); + }, null); } public select(index: number): Configuration { if (index === this.configurationJson.configurations.length) { - this.handleConfigurationEditUICommand(vscode.window.showTextDocument); + this.handleConfigurationEditUICommand(null, vscode.window.showTextDocument); return; } if (index === this.configurationJson.configurations.length + 1) { - this.handleConfigurationEditJSONCommand(vscode.window.showTextDocument); + this.handleConfigurationEditJSONCommand(null, vscode.window.showTextDocument); return; } @@ -611,28 +611,36 @@ export class CppProperties { } } - public handleConfigurationEditCommand(onSuccess: (document: vscode.TextDocument) => void): void { + public handleConfigurationEditCommand(onCreation: () => void, showDocument: (document: vscode.TextDocument) => void): void { let otherSettings: OtherSettings = new OtherSettings(this.rootUri); if (otherSettings.settingsEditor === "ui") { - this.handleConfigurationEditUICommand(onSuccess); + this.handleConfigurationEditUICommand(onCreation, showDocument); } else { - this.handleConfigurationEditJSONCommand(onSuccess); + this.handleConfigurationEditJSONCommand(onCreation, showDocument); } } - public handleConfigurationEditJSONCommand(onSuccess: (document: vscode.TextDocument) => void): void { + public handleConfigurationEditJSONCommand(onCreation: () => void, showDocument: (document: vscode.TextDocument) => void): void { this.ensurePropertiesFile().then(() => { console.assert(this.propertiesFile); + if (onCreation) { + onCreation(); + } // Directly open the json file vscode.workspace.openTextDocument(this.propertiesFile).then((document: vscode.TextDocument) => { - onSuccess(document); + if (showDocument) { + showDocument(document); + } }); }); } - public handleConfigurationEditUICommand(onSuccess: (document: vscode.TextDocument) => void): void { + public handleConfigurationEditUICommand(onCreation: () => void, showDocument: (document: vscode.TextDocument) => void): void { this.ensurePropertiesFile().then(() => { if (this.propertiesFile) { + if (onCreation) { + onCreation(); + } if (this.parsePropertiesFile(false)) { // Parse successful, show UI if (this.settingsPanel === undefined) { @@ -647,7 +655,9 @@ export class CppProperties { } else { // Parse failed, open json file vscode.workspace.openTextDocument(this.propertiesFile).then((document: vscode.TextDocument) => { - onSuccess(document); + if (showDocument) { + showDocument(document); + } }); } } diff --git a/Extension/src/LanguageServer/extension.ts b/Extension/src/LanguageServer/extension.ts index f24309ad22..6e82068075 100644 --- a/Extension/src/LanguageServer/extension.ts +++ b/Extension/src/LanguageServer/extension.ts @@ -673,6 +673,7 @@ export function registerCommands(): void { disposables.push(vscode.commands.registerCommand('C_Cpp.ConfigurationProviderSelect', onSelectConfigurationProvider)); disposables.push(vscode.commands.registerCommand('C_Cpp.ConfigurationEditJSON', onEditConfigurationJSON)); disposables.push(vscode.commands.registerCommand('C_Cpp.ConfigurationEditUI', onEditConfigurationUI)); + disposables.push(vscode.commands.registerCommand('C_Cpp.ConfigurationEdit', onEditConfiguration)); disposables.push(vscode.commands.registerCommand('C_Cpp.AddToIncludePath', onAddToIncludePath)); disposables.push(vscode.commands.registerCommand('C_Cpp.EnableErrorSquiggles', onEnableSquiggles)); disposables.push(vscode.commands.registerCommand('C_Cpp.DisableErrorSquiggles', onDisableSquiggles)); @@ -819,6 +820,15 @@ function onEditConfigurationUI(): void { } } +function onEditConfiguration(): void { + onActivationEvent(); + if (!isFolderOpen()) { + vscode.window.showInformationMessage('Open a folder first to edit configurations'); + } else { + selectClient().then(client => client.handleConfigurationEditCommand(), rejected => {}); + } +} + function onAddToIncludePath(path: string): void { if (!isFolderOpen()) { vscode.window.showInformationMessage('Open a folder first to add to includePath');