Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix includePath code actions and configuration actions. #3576

Merged
merged 2 commits into from
May 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Extension/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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).

Expand Down
6 changes: 3 additions & 3 deletions Extension/src/LanguageServer/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
40 changes: 25 additions & 15 deletions Extension/src/LanguageServer/configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<void> {
return new Promise<void>((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) {
Expand All @@ -441,7 +441,7 @@ export class CppProperties {
this.writeToJson();
this.handleConfigurationChange();
resolve();
});
}, null);
} else {
let settings: CppSettings = new CppSettings(this.rootUri);
if (providerId) {
Expand All @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
});
}
}
Expand Down
10 changes: 10 additions & 0 deletions Extension/src/LanguageServer/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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');
Expand Down