Skip to content

Commit 77f3747

Browse files
authored
Fix includePath code actions and configuration actions. (#3576)
* Fix `includePath` code actions amd configuration actions.
1 parent dc8813f commit 77f3747

4 files changed

Lines changed: 41 additions & 19 deletions

File tree

Extension/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# C/C++ for Visual Studio Code Change Log
22

3-
## Version 0.23.0-insiders2: April 30, 2019
3+
## Version 0.23.0-insiders2: May 1, 2019
44
### New Features
55
* Add support for `.env` files for `cppvsdbg`. [#3490](https://github.com/Microsoft/vscode-cpptools/issues/3490)
66

@@ -20,6 +20,8 @@
2020
* Fix backslashes getting added each time settings are saved. [#3526](https://github.com/Microsoft/vscode-cpptools/issues/3526)
2121
* Fix regression with some C++17 features with `msvc-x64` mode. [#3541](https://github.com/Microsoft/vscode-cpptools/issues/3541)
2222
* Fix `Go to Definition` giving no results when IntelliSense doesn't find the symbol. [#3549](https://github.com/Microsoft/vscode-cpptools/issues/3549)
23+
* Fix configuration squiggles with trailing backslashes. [PR #3573](https://github.com/Microsoft/vscode-cpptools/pull/3573)
24+
* Fix `includePath` code actions, configuration prompts, and the `C/C++: Change configuration provider...` command. [PR #3576](https://github.com/Microsoft/vscode-cpptools/pull/3576)
2325
* Fix crash on hover (that could occur when document comments have blank lines).
2426
* Fix randomly occurring crash (that could occur when opening files while IntelliSense squiggles are pending).
2527

Extension/src/LanguageServer/client.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,15 +1397,15 @@ class DefaultClient implements Client {
13971397
}
13981398

13991399
public handleConfigurationEditCommand(): void {
1400-
this.notifyWhenReady(() => this.configuration.handleConfigurationEditCommand(vscode.window.showTextDocument));
1400+
this.notifyWhenReady(() => this.configuration.handleConfigurationEditCommand(null, vscode.window.showTextDocument));
14011401
}
14021402

14031403
public handleConfigurationEditJSONCommand(): void {
1404-
this.notifyWhenReady(() => this.configuration.handleConfigurationEditJSONCommand(vscode.window.showTextDocument));
1404+
this.notifyWhenReady(() => this.configuration.handleConfigurationEditJSONCommand(null, vscode.window.showTextDocument));
14051405
}
14061406

14071407
public handleConfigurationEditUICommand(): void {
1408-
this.notifyWhenReady(() => this.configuration.handleConfigurationEditUICommand(vscode.window.showTextDocument));
1408+
this.notifyWhenReady(() => this.configuration.handleConfigurationEditUICommand(null, vscode.window.showTextDocument));
14091409
}
14101410

14111411
public handleAddToIncludePathCommand(path: string): void {

Extension/src/LanguageServer/configurations.ts

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ export class CppProperties {
414414
}
415415

416416
public addToIncludePathCommand(path: string): void {
417-
this.handleConfigurationEditCommand((document: vscode.TextDocument) => {
417+
this.handleConfigurationEditCommand(() => {
418418
telemetry.logLanguageServerEvent("addToIncludePath");
419419
this.parsePropertiesFile(true); // Clear out any modifications we may have made internally.
420420
let config: Configuration = this.CurrentConfiguration;
@@ -424,13 +424,13 @@ export class CppProperties {
424424
config.includePath.splice(config.includePath.length, 0, path);
425425
this.writeToJson();
426426
this.handleConfigurationChange();
427-
});
427+
}, null);
428428
}
429429

430430
public updateCustomConfigurationProvider(providerId: string): Thenable<void> {
431431
return new Promise<void>((resolve) => {
432432
if (this.propertiesFile) {
433-
this.handleConfigurationEditCommand((document: vscode.TextDocument) => {
433+
this.handleConfigurationEditJSONCommand(() => {
434434
this.parsePropertiesFile(true); // Clear out any modifications we may have made internally.
435435
let config: Configuration = this.CurrentConfiguration;
436436
if (providerId) {
@@ -441,7 +441,7 @@ export class CppProperties {
441441
this.writeToJson();
442442
this.handleConfigurationChange();
443443
resolve();
444-
});
444+
}, null);
445445
} else {
446446
let settings: CppSettings = new CppSettings(this.rootUri);
447447
if (providerId) {
@@ -456,22 +456,22 @@ export class CppProperties {
456456
}
457457

458458
public setCompileCommands(path: string): void {
459-
this.handleConfigurationEditCommand((document: vscode.TextDocument) => {
459+
this.handleConfigurationEditJSONCommand(() => {
460460
this.parsePropertiesFile(true); // Clear out any modifications we may have made internally.
461461
let config: Configuration = this.CurrentConfiguration;
462462
config.compileCommands = path;
463463
this.writeToJson();
464464
this.handleConfigurationChange();
465-
});
465+
}, null);
466466
}
467467

468468
public select(index: number): Configuration {
469469
if (index === this.configurationJson.configurations.length) {
470-
this.handleConfigurationEditUICommand(vscode.window.showTextDocument);
470+
this.handleConfigurationEditUICommand(null, vscode.window.showTextDocument);
471471
return;
472472
}
473473
if (index === this.configurationJson.configurations.length + 1) {
474-
this.handleConfigurationEditJSONCommand(vscode.window.showTextDocument);
474+
this.handleConfigurationEditJSONCommand(null, vscode.window.showTextDocument);
475475
return;
476476
}
477477

@@ -611,28 +611,36 @@ export class CppProperties {
611611
}
612612
}
613613

614-
public handleConfigurationEditCommand(onSuccess: (document: vscode.TextDocument) => void): void {
614+
public handleConfigurationEditCommand(onCreation: () => void, showDocument: (document: vscode.TextDocument) => void): void {
615615
let otherSettings: OtherSettings = new OtherSettings(this.rootUri);
616616
if (otherSettings.settingsEditor === "ui") {
617-
this.handleConfigurationEditUICommand(onSuccess);
617+
this.handleConfigurationEditUICommand(onCreation, showDocument);
618618
} else {
619-
this.handleConfigurationEditJSONCommand(onSuccess);
619+
this.handleConfigurationEditJSONCommand(onCreation, showDocument);
620620
}
621621
}
622622

623-
public handleConfigurationEditJSONCommand(onSuccess: (document: vscode.TextDocument) => void): void {
623+
public handleConfigurationEditJSONCommand(onCreation: () => void, showDocument: (document: vscode.TextDocument) => void): void {
624624
this.ensurePropertiesFile().then(() => {
625625
console.assert(this.propertiesFile);
626+
if (onCreation) {
627+
onCreation();
628+
}
626629
// Directly open the json file
627630
vscode.workspace.openTextDocument(this.propertiesFile).then((document: vscode.TextDocument) => {
628-
onSuccess(document);
631+
if (showDocument) {
632+
showDocument(document);
633+
}
629634
});
630635
});
631636
}
632637

633-
public handleConfigurationEditUICommand(onSuccess: (document: vscode.TextDocument) => void): void {
638+
public handleConfigurationEditUICommand(onCreation: () => void, showDocument: (document: vscode.TextDocument) => void): void {
634639
this.ensurePropertiesFile().then(() => {
635640
if (this.propertiesFile) {
641+
if (onCreation) {
642+
onCreation();
643+
}
636644
if (this.parsePropertiesFile(false)) {
637645
// Parse successful, show UI
638646
if (this.settingsPanel === undefined) {
@@ -647,7 +655,9 @@ export class CppProperties {
647655
} else {
648656
// Parse failed, open json file
649657
vscode.workspace.openTextDocument(this.propertiesFile).then((document: vscode.TextDocument) => {
650-
onSuccess(document);
658+
if (showDocument) {
659+
showDocument(document);
660+
}
651661
});
652662
}
653663
}

Extension/src/LanguageServer/extension.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,7 @@ export function registerCommands(): void {
673673
disposables.push(vscode.commands.registerCommand('C_Cpp.ConfigurationProviderSelect', onSelectConfigurationProvider));
674674
disposables.push(vscode.commands.registerCommand('C_Cpp.ConfigurationEditJSON', onEditConfigurationJSON));
675675
disposables.push(vscode.commands.registerCommand('C_Cpp.ConfigurationEditUI', onEditConfigurationUI));
676+
disposables.push(vscode.commands.registerCommand('C_Cpp.ConfigurationEdit', onEditConfiguration));
676677
disposables.push(vscode.commands.registerCommand('C_Cpp.AddToIncludePath', onAddToIncludePath));
677678
disposables.push(vscode.commands.registerCommand('C_Cpp.EnableErrorSquiggles', onEnableSquiggles));
678679
disposables.push(vscode.commands.registerCommand('C_Cpp.DisableErrorSquiggles', onDisableSquiggles));
@@ -819,6 +820,15 @@ function onEditConfigurationUI(): void {
819820
}
820821
}
821822

823+
function onEditConfiguration(): void {
824+
onActivationEvent();
825+
if (!isFolderOpen()) {
826+
vscode.window.showInformationMessage('Open a folder first to edit configurations');
827+
} else {
828+
selectClient().then(client => client.handleConfigurationEditCommand(), rejected => {});
829+
}
830+
}
831+
822832
function onAddToIncludePath(path: string): void {
823833
if (!isFolderOpen()) {
824834
vscode.window.showInformationMessage('Open a folder first to add to includePath');

0 commit comments

Comments
 (0)