Skip to content

Commit 32b9947

Browse files
authored
Don't show the 'select a compiler' code action if the default compiler is already set (and other quick fixes) (#10670)
* Stop showing the code action if the default compiler is already set. * Multiple other fixes. * Fix clang-tidy 'clang-analyzer-' documentation links not working.
1 parent 7b03e02 commit 32b9947

File tree

6 files changed

+43
-16
lines changed

6 files changed

+43
-16
lines changed

Extension/CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# C/C++ for Visual Studio Code Changelog
22

3-
## Version 1.15.0: March 14, 2023
3+
## Version 1.15.0: March 15, 2023
44
### Enhancements
55
* Support multiple natvis files in `visualizerFile`. [#925](https://github.com/microsoft/vscode-cpptools/issues/925)
66
* Enable error squiggles for single file mode if includes resolve. [#10062](https://github.com/microsoft/vscode-cpptools/issues/10062)
7+
* Improve the description of the `C_Cpp.codeAnalysis.clangTidy.enabled` setting. [#10454](https://github.com/microsoft/vscode-cpptools/issues/10454)
78
* Add a 'Select Default Compiler' code action and error message for standard headers which can't be found. [#10531](https://github.com/microsoft/vscode-cpptools/issues/10531)
9+
* Change the 'Edit "includePath" setting' code action to reference "compilerPath" for missing system includes. [#10675](https://github.com/microsoft/vscode-cpptools/issues/10675)
810

911
### Bug Fixes
1012
* Enable `-fms-extensions` by default for Cygwin and MinGW. [#8353](https://github.com/microsoft/vscode-cpptools/issues/8353)
@@ -20,9 +22,11 @@
2022
* Fix 'Reset IntelliSense Database' being delayed until parsing is finished. [#10616](https://github.com/microsoft/vscode-cpptools/issues/10616)
2123
* Fix uncaught exception with some configuration providers. [PR #10629](https://github.com/microsoft/vscode-cpptools/pull/10629)
2224
* Fix bugs with the "You do not have IntelliSense configured" prompt. [#10658](https://github.com/microsoft/vscode-cpptools/issues/10658), [#10659](https://github.com/microsoft/vscode-cpptools/issues/10659)
25+
* Fix random failures when adding or removing workspace folders. [PR #10665](https://github.com/microsoft/vscode-cpptools/pull/10665)
2326
* Fix missing clang-tidy checks setting values. [#10667](https://github.com/microsoft/vscode-cpptools/issues/10667)
27+
* Fix 'Select Default Compiler' so that it works if it's already set in the workspace or workspace folder settings. [#10674](https://github.com/microsoft/vscode-cpptools/issues/10674)
28+
* Fix clang-tidy 'clang-analyzer-' documentation links not working. [#10678](https://github.com/microsoft/vscode-cpptools/issues/10678)
2429
* Fix `__GXX_RTTI` incorrectly being defined by IntelliSense with clang and `-fms-compatibility`.
25-
* Fix random failures when adding or removing workspace folders.
2630
* Reduce the likelihood of an `onWillSaveWaitUntil` timeout.
2731
* Fix an IntelliSense crash with C++20 concepts.
2832
* Stop querying clang-cl.exe as C.

Extension/src/LanguageServer/Providers/codeActionProvider.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,12 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
6767
throw new vscode.CancellationError();
6868
}
6969

70+
let hasSelectDefaultCompiler: boolean = false;
71+
let hasConfigurationCompilerPath: boolean = false;
72+
7073
// Convert to vscode.CodeAction array
7174
response.commands.forEach((command) => {
72-
const title: string = getLocalizedString(command.localizeStringParams);
75+
let title: string = getLocalizedString(command.localizeStringParams);
7376
let wsEdit: vscode.WorkspaceEdit | undefined;
7477
let codeActionKind: vscode.CodeActionKind = vscode.CodeActionKind.QuickFix;
7578
if (command.edit) {
@@ -168,9 +171,20 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
168171
resultCodeActions.push(...disableCodeActions);
169172
resultCodeActions.push(...docCodeActions);
170173
return;
171-
}
172-
if (command.command === 'C_Cpp.CreateDeclarationOrDefinition' && (command.arguments ?? []).length === 0) {
174+
} else if (command.command === 'C_Cpp.CreateDeclarationOrDefinition' && (command.arguments ?? []).length === 0) {
173175
command.arguments = ['codeAction']; // We report the sender of the command
176+
} else if (command.command === "C_Cpp.SelectDefaultCompiler") {
177+
hasSelectDefaultCompiler = true;
178+
if (this.client.configuration.CurrentConfiguration?.rawCompilerPath !== undefined) {
179+
hasConfigurationCompilerPath = true;
180+
return;
181+
}
182+
} else if (command.command === "C_Cpp.ConfigurationEdit" && hasSelectDefaultCompiler) {
183+
if (hasConfigurationCompilerPath) {
184+
title = title.replace("includePath", "compilerPath");
185+
} else {
186+
return;
187+
}
174188
}
175189
const vscodeCodeAction: vscode.CodeAction = {
176190
title: title,

Extension/src/LanguageServer/client.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ export class DefaultClient implements Client {
953953
}
954954

955955
public async handleCompilerQuickPick(showSecondPrompt: boolean): Promise<void> {
956-
const settings: OtherSettings = new OtherSettings();
956+
const settings: CppSettings = new CppSettings();
957957
const selectCompiler: string = localize("selectCompiler.string", "Select Compiler");
958958
const paths: string[] = [];
959959
if (compilerDefaults.knownCompilers !== undefined) {
@@ -988,7 +988,7 @@ export class DefaultClient implements Client {
988988
}
989989
if (index === paths.length - 1) {
990990
action = "disable";
991-
settings.defaultCompiler = "";
991+
settings.defaultCompilerPath = "";
992992
if (showSecondPrompt) {
993993
this.showPrompt(selectCompiler, true);
994994
}
@@ -1018,13 +1018,13 @@ export class DefaultClient implements Client {
10181018
return;
10191019
}
10201020
action = "compiler browsed";
1021-
settings.defaultCompiler = result[0].fsPath;
1021+
settings.defaultCompilerPath = result[0].fsPath;
10221022
} else {
10231023
action = "select compiler";
1024-
settings.defaultCompiler = util.isCl(paths[index]) ? "cl.exe" : paths[index];
1024+
settings.defaultCompilerPath = util.isCl(paths[index]) ? "cl.exe" : paths[index];
10251025
}
10261026

1027-
util.addTrustedCompiler(compilerPaths, settings.defaultCompiler);
1027+
util.addTrustedCompiler(compilerPaths, settings.defaultCompilerPath);
10281028
compilerDefaults = await this.requestCompiler(compilerPaths);
10291029
DefaultClient.updateClientConfigurations();
10301030
} finally {
@@ -1040,13 +1040,13 @@ export class DefaultClient implements Client {
10401040
const selectCompiler: string = localize("selectCompiler.string", "Select Compiler");
10411041
const confirmCompiler: string = localize("confirmCompiler.string", "Yes");
10421042
let action: string;
1043-
const settings: OtherSettings = new OtherSettings();
1043+
const settings: CppSettings = new CppSettings();
10441044
if (isCommand || compilerDefaults.compilerPath !== "") {
10451045
if (!isCommand && (compilerDefaults.compilerPath !== undefined)) {
10461046
const value: string | undefined = await vscode.window.showInformationMessage(localize("selectCompiler.message", "The compiler {0} was found. Do you want to configure IntelliSense with this compiler?", compilerDefaults.compilerPath), confirmCompiler, selectCompiler);
10471047
if (value === confirmCompiler) {
10481048
compilerPaths = await util.addTrustedCompiler(compilerPaths, compilerDefaults.compilerPath);
1049-
settings.defaultCompiler = compilerDefaults.compilerPath;
1049+
settings.defaultCompilerPath = compilerDefaults.compilerPath;
10501050
compilerDefaults = await this.requestCompiler(compilerPaths);
10511051
DefaultClient.updateClientConfigurations();
10521052
action = "confirm compiler";

Extension/src/LanguageServer/codeAnalysis.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,9 @@ export function publishCodeAnalysisDiagnostics(params: PublishCodeAnalysisDiagno
349349
if (primaryCode === "clang-tidy-nolint") {
350350
docPage = "index.html#suppressing-undesired-diagnostics";
351351
} else {
352-
const dashIndex: number = primaryCode.indexOf("-");
352+
const clangAnalyzerString: string = "clang-analyzer";
353+
const clangAnalyzerIndex: number = primaryCode.indexOf(clangAnalyzerString);
354+
const dashIndex: number = clangAnalyzerIndex === 0 ? clangAnalyzerString.length : primaryCode.indexOf("-");
353355
const checksGroup: string = dashIndex > 0 ? `/${primaryCode.substring(0, dashIndex)}` : "";
354356
const checksPage: string = dashIndex > 0 ? primaryCode.substring(dashIndex + 1) : primaryCode;
355357
docPage = `checks${checksGroup}/${checksPage}.html`;

Extension/src/LanguageServer/configurations.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export interface ConfigurationJson {
5858

5959
export interface Configuration {
6060
name: string;
61+
rawCompilerPath?: string;
6162
compilerPath?: string;
6263
compilerPathIsExplicit?: boolean;
6364
compilerArgs?: string[];
@@ -837,6 +838,7 @@ export class CppProperties {
837838
const env: Environment = this.ExtendedEnvironment;
838839
for (let i: number = 0; i < this.configurationJson.configurations.length; i++) {
839840
const configuration: Configuration = this.configurationJson.configurations[i];
841+
configuration.rawCompilerPath = configuration.compilerPath;
840842

841843
configuration.includePath = this.updateConfigurationPathsArray(configuration.includePath, settings.defaultIncludePath, env);
842844
// in case includePath is reset below

Extension/src/LanguageServer/settings.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,14 @@ export class CppSettings extends Settings {
379379
public get defaultForcedInclude(): string[] | undefined { return super.getWithUndefinedDefault<string[]>("default.forcedInclude"); }
380380
public get defaultIntelliSenseMode(): string | undefined { return super.Section.get<string>("default.intelliSenseMode"); }
381381
public get defaultCompilerPath(): string | undefined { return super.Section.get<string | null>("default.compilerPath") ?? undefined; }
382+
public set defaultCompilerPath(value: string | undefined) {
383+
const defaultCompilerPathStr: string = "default.compilerPath";
384+
const compilerPathInfo: any = this.Section.inspect(defaultCompilerPathStr);
385+
this.Section.update(defaultCompilerPathStr, value,
386+
compilerPathInfo.workspaceFolderValue !== undefined ? vscode.ConfigurationTarget.WorkspaceFolder :
387+
(compilerPathInfo.workspaceValue !== undefined ? vscode.ConfigurationTarget.Workspace :
388+
vscode.ConfigurationTarget.Global));
389+
}
382390
public get defaultCompilerArgs(): string[] | undefined { return super.getWithUndefinedDefault<string[]>("default.compilerArgs"); }
383391
public get defaultCStandard(): string | undefined { return super.Section.get<string>("default.cStandard"); }
384392
public get defaultCppStandard(): string | undefined { return super.Section.get<string>("default.cppStandard"); }
@@ -964,9 +972,6 @@ export class OtherSettings {
964972
public set filesAssociations(value: any) {
965973
vscode.workspace.getConfiguration("files").update("associations", value, vscode.ConfigurationTarget.Workspace);
966974
}
967-
public set defaultCompiler(value: string) {
968-
vscode.workspace.getConfiguration("C_Cpp.default").update("compilerPath", value, vscode.ConfigurationTarget.Global);
969-
}
970975
public get filesExclude(): vscode.WorkspaceConfiguration | undefined { return vscode.workspace.getConfiguration("files", this.resource).get("exclude"); }
971976
public get filesAutoSaveAfterDelay(): boolean { return vscode.workspace.getConfiguration("files").get("autoSave") === "afterDelay"; }
972977
public get editorInlayHintsEnabled(): boolean { return vscode.workspace.getConfiguration("editor.inlayHints").get<string>("enabled") !== "off"; }

0 commit comments

Comments
 (0)