Skip to content

Commit c3e3bd3

Browse files
"Select IntelliSense Configuration" updates compilerPath in c_cpp_properties.json (#11255)
1 parent 4f805c4 commit c3e3bd3

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

Extension/src/LanguageServer/client.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,7 @@ export class DefaultClient implements Client {
10571057
if (index === paths.length - 1) {
10581058
action = "disable";
10591059
settings.defaultCompilerPath = "";
1060+
await this.configuration.updateCompilerPathIfSet(settings.defaultCompilerPath);
10601061
configurationSelected = true;
10611062
if (showSecondPrompt) {
10621063
void this.showPrompt(selectIntelliSenseConfig, true, sender);
@@ -1112,6 +1113,7 @@ export class DefaultClient implements Client {
11121113
configurationSelected = true;
11131114
action = "compiler browsed";
11141115
settings.defaultCompilerPath = result[0].fsPath;
1116+
await this.configuration.updateCompilerPathIfSet(settings.defaultCompilerPath);
11151117
void vscode.commands.executeCommand('setContext', 'cpptools.trustedCompilerFound', true);
11161118
} else {
11171119
configurationSelected = true;
@@ -1130,6 +1132,7 @@ export class DefaultClient implements Client {
11301132
} else {
11311133
action = "select compiler";
11321134
settings.defaultCompilerPath = util.isCl(paths[index]) ? "cl.exe" : paths[index];
1135+
await this.configuration.updateCompilerPathIfSet(settings.defaultCompilerPath);
11331136
void vscode.commands.executeCommand('setContext', 'cpptools.trustedCompilerFound', true);
11341137
}
11351138
}

Extension/src/LanguageServer/configurations.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,21 @@ export class CppProperties {
624624
}, () => { }).catch(logAndReturn.undefined);
625625
}
626626

627+
public async updateCompilerPathIfSet(path: string): Promise<void> {
628+
return this.handleConfigurationEditJSONCommand(() => {
629+
this.parsePropertiesFile(); // Clear out any modifications we may have made internally.
630+
const config: Configuration | undefined = this.CurrentConfiguration;
631+
// Update compiler path if it's already set.
632+
if (config && config.compilerPath !== undefined) {
633+
config.compilerPath = path;
634+
this.writeToJson();
635+
}
636+
// Any time parsePropertiesFile is called, configurationJson gets
637+
// reverted to an unprocessed state and needs to be reprocessed.
638+
this.handleConfigurationChange();
639+
}, returns.undefined);
640+
}
641+
627642
public async updateCustomConfigurationProvider(providerId: string): Promise<void> {
628643
if (!this.propertiesFile) {
629644
const settings: CppSettings = new CppSettings(this.rootUri);

0 commit comments

Comments
 (0)