Skip to content

Commit 9c835e5

Browse files
authored
Add logging/warnings when compile probing alters explicit user configuration details (#6180)
1 parent 0a09372 commit 9c835e5

File tree

7 files changed

+84
-39
lines changed

7 files changed

+84
-39
lines changed

Extension/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
## Version 0.28.0: May 12, 2020
139139
### New Features
140140
* Add C/C++ language-aware code folding. [#407](https://github.com/microsoft/vscode-cpptools/issues/407)
141-
* Add GNU (and C18) language standard options. [#2782](https://github.com/microsoft/vscode-cpptools/issues/2782)
141+
* Add GNU (and C17) language standard options. [#2782](https://github.com/microsoft/vscode-cpptools/issues/2782)
142142
* Add ARM and ARM64 IntelliSense modes. [#4271](https://github.com/microsoft/vscode-cpptools/issues/4271), [PR #5250](https://github.com/microsoft/vscode-cpptools/pull/5250)
143143

144144
### Enhancements

Extension/c_cpp_properties.schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"c89",
3333
"c99",
3434
"c11",
35-
"c18",
35+
"c17",
3636
"gnu89",
3737
"gnu99",
3838
"gnu11",

Extension/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,7 @@
955955
"c89",
956956
"c99",
957957
"c11",
958-
"c18",
958+
"c17",
959959
"gnu89",
960960
"gnu99",
961961
"gnu11",

Extension/src/LanguageServer/client.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ let compilerDefaults: configs.CompilerDefaults;
6262
let diagnosticsChannel: vscode.OutputChannel;
6363
let outputChannel: vscode.OutputChannel;
6464
let debugChannel: vscode.OutputChannel;
65+
let warningChannel: vscode.OutputChannel;
6566
let diagnosticsCollection: vscode.DiagnosticCollection;
6667
let workspaceDisposables: vscode.Disposable[] = [];
6768
export let workspaceReferences: refs.ReferencesManager;
@@ -127,6 +128,16 @@ function showMessageWindow(params: ShowMessageWindowParams): void {
127128
}
128129
}
129130

131+
function showWarning(params: ShowWarningParams): void {
132+
const message: string = util.getLocalizedString(params.localizeStringParams);
133+
if (!warningChannel) {
134+
warningChannel = vscode.window.createOutputChannel(`${localize("c.cpp.warnings", "C/C++ Configuration Warnings")}`);
135+
workspaceDisposables.push(warningChannel);
136+
}
137+
warningChannel.appendLine(message);
138+
warningChannel.show(false);
139+
}
140+
130141
function publishDiagnostics(params: PublishDiagnosticsParams): void {
131142
if (!diagnosticsCollection) {
132143
diagnosticsCollection = vscode.languages.createDiagnosticCollection("C/C++");
@@ -263,6 +274,10 @@ interface ShowMessageWindowParams {
263274
localizeStringParams: LocalizeStringParams;
264275
}
265276

277+
interface ShowWarningParams {
278+
localizeStringParams: LocalizeStringParams;
279+
}
280+
266281
export interface GetDocumentSymbolRequestParams {
267282
uri: string;
268283
}
@@ -459,6 +474,7 @@ const ReportReferencesProgressNotification: NotificationType<refs.ReportReferenc
459474
const RequestCustomConfig: NotificationType<string, void> = new NotificationType<string, void>('cpptools/requestCustomConfig');
460475
const PublishDiagnosticsNotification: NotificationType<PublishDiagnosticsParams, void> = new NotificationType<PublishDiagnosticsParams, void>('cpptools/publishDiagnostics');
461476
const ShowMessageWindowNotification: NotificationType<ShowMessageWindowParams, void> = new NotificationType<ShowMessageWindowParams, void>('cpptools/showMessageWindow');
477+
const ShowWarningNotification: NotificationType<ShowWarningParams, void> = new NotificationType<ShowWarningParams, void>('cpptools/showWarning');
462478
const ReportTextDocumentLanguage: NotificationType<string, void> = new NotificationType<string, void>('cpptools/reportTextDocumentLanguage');
463479
const SemanticTokensChanged: NotificationType<string, void> = new NotificationType<string, void>('cpptools/semanticTokensChanged');
464480

@@ -1865,6 +1881,7 @@ export class DefaultClient implements Client {
18651881
});
18661882
this.languageClient.onNotification(PublishDiagnosticsNotification, publishDiagnostics);
18671883
this.languageClient.onNotification(ShowMessageWindowNotification, showMessageWindow);
1884+
this.languageClient.onNotification(ShowWarningNotification, showWarning);
18681885
this.languageClient.onNotification(ReportTextDocumentLanguage, (e) => this.setTextDocumentLanguage(e));
18691886
this.languageClient.onNotification(SemanticTokensChanged, (e) => this.semanticTokensProvider?.invalidateFile(e));
18701887
setupOutputHandlers();

Extension/src/LanguageServer/configurations.ts

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,18 @@ export interface ConfigurationJson {
5858
export interface Configuration {
5959
name: string;
6060
compilerPath?: string;
61+
compilerPathIsExplicit?: boolean;
6162
compilerArgs?: string[];
6263
cStandard?: string;
64+
cStandardIsExplicit?: boolean;
6365
cppStandard?: string;
66+
cppStandardIsExplicit?: boolean;
6467
includePath?: string[];
6568
macFrameworkPath?: string[];
6669
windowsSdkVersion?: string;
6770
defines?: string[];
6871
intelliSenseMode?: string;
72+
intelliSenseModeIsExplicit?: boolean;
6973
compileCommands?: string;
7074
forcedInclude?: string[];
7175
configurationProvider?: string;
@@ -630,29 +634,39 @@ export class CppProperties {
630634
configuration.cStandard = this.updateConfigurationString(configuration.cStandard, settings.defaultCStandard, env);
631635
configuration.cppStandard = this.updateConfigurationString(configuration.cppStandard, settings.defaultCppStandard, env);
632636
configuration.intelliSenseMode = this.updateConfigurationString(configuration.intelliSenseMode, settings.defaultIntelliSenseMode, env);
637+
configuration.intelliSenseModeIsExplicit = true;
638+
configuration.cStandardIsExplicit = true;
639+
configuration.cppStandardIsExplicit = true;
640+
configuration.compilerPathIsExplicit = true;
633641
if (!configuration.compileCommands) {
634642
// compile_commands.json already specifies a compiler. compilerPath overrides the compile_commands.json compiler so
635643
// don't set a default when compileCommands is in use.
636644
configuration.compilerPath = this.updateConfigurationString(configuration.compilerPath, settings.defaultCompilerPath, env, true);
637-
if (configuration.compilerPath === undefined && !!this.defaultCompilerPath) {
638-
configuration.compilerPath = this.defaultCompilerPath;
639-
if (!configuration.cStandard && !!this.defaultCStandard) {
640-
configuration.cStandard = this.defaultCStandard;
641-
}
642-
if (!configuration.cppStandard && !!this.defaultCppStandard) {
643-
configuration.cppStandard = this.defaultCppStandard;
644-
}
645-
if (!configuration.intelliSenseMode && !!this.defaultIntelliSenseMode) {
646-
configuration.intelliSenseMode = this.defaultIntelliSenseMode;
647-
}
648-
if (!configuration.windowsSdkVersion && !!this.defaultWindowsSdkVersion) {
649-
configuration.windowsSdkVersion = this.defaultWindowsSdkVersion;
650-
}
651-
if (!configuration.includePath && !!this.defaultIncludes) {
652-
configuration.includePath = this.defaultIncludes;
653-
}
654-
if (!configuration.macFrameworkPath && !!this.defaultFrameworks) {
655-
configuration.macFrameworkPath = this.defaultFrameworks;
645+
if (configuration.compilerPath === undefined) {
646+
configuration.compilerPathIsExplicit = false;
647+
if (!!this.defaultCompilerPath) {
648+
configuration.compilerPath = this.defaultCompilerPath;
649+
if (!configuration.cStandard && !!this.defaultCStandard) {
650+
configuration.cStandard = this.defaultCStandard;
651+
configuration.cStandardIsExplicit = false;
652+
}
653+
if (!configuration.cppStandard && !!this.defaultCppStandard) {
654+
configuration.cppStandard = this.defaultCppStandard;
655+
configuration.cppStandardIsExplicit = false;
656+
}
657+
if (!configuration.intelliSenseMode && !!this.defaultIntelliSenseMode) {
658+
configuration.intelliSenseMode = this.defaultIntelliSenseMode;
659+
configuration.intelliSenseModeIsExplicit = false;
660+
}
661+
if (!configuration.windowsSdkVersion && !!this.defaultWindowsSdkVersion) {
662+
configuration.windowsSdkVersion = this.defaultWindowsSdkVersion;
663+
}
664+
if (!configuration.includePath && !!this.defaultIncludes) {
665+
configuration.includePath = this.defaultIncludes;
666+
}
667+
if (!configuration.macFrameworkPath && !!this.defaultFrameworks) {
668+
configuration.macFrameworkPath = this.defaultFrameworks;
669+
}
656670
}
657671
}
658672
} else {
@@ -667,18 +681,6 @@ export class CppProperties {
667681
}
668682
}
669683

670-
if (configuration.compilerPath
671-
&& configuration.compilerPath.length > 0
672-
&& configuration.compilerPath[0] !== '/'
673-
&& !fs.existsSync(configuration.compilerPath)) {
674-
// If a compiler path is specified, and it doesn't resolve to a file,
675-
// try looking for it in the current path.
676-
try {
677-
configuration.compilerPath = which.sync(configuration.compilerPath);
678-
} catch {
679-
}
680-
}
681-
682684
configuration.customConfigurationVariables = this.updateConfigurationStringDictionary(configuration.customConfigurationVariables, settings.defaultCustomConfigurationVariables, env);
683685
configuration.configurationProvider = this.updateConfigurationString(configuration.configurationProvider, settings.defaultConfigurationProvider, env);
684686

Extension/src/nativeStrings.json

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@
8888
"not_exited_yet": "not exited yet. Will sleep for {0} milliseconds and try again.",
8989
"failed_to_spawn_process": "Failed to spawn process. Error: {0} ({1})",
9090
"offering_completion": "Offering completion",
91-
"compiler_from_compiler_path": "Attempting to get defaults from compiler in \"compilerPath\" property: '{0}'",
92-
"compiler_from_compile_commands": "Attempting to get defaults from compiler in compile_commands.json file: '{0}'",
9391
"compiler_on_machine": "Attempting to get defaults from compiler found on the machine: '{0}'",
9492
"unable_to_resolve_include_path": "Unable to resolve include path: {0}",
9593
"error_searching_for_intellisense_client": "Error searching for IntelliSense client: {0}",
@@ -143,7 +141,7 @@
143141
"timed_out_attempting_to_communicate_with_process": "Timed out attempting to communicate with process!",
144142
"process_failed_to_run": "Process has failed to run",
145143
"wsl_not_detected": "WSL not detected",
146-
"compiler_in_compilerpath_not_found": "Compiler in \"compilerPath\" property not found: {0}",
144+
"compiler_in_compilerpath_not_found": "Specified compiler was not found: {0}",
147145
"config_data_invalid": "Config data invalid, {0}",
148146
"cmake_executable_not_found": "CMake executable not found at {0}",
149147
"no_args_provider": "No args provider",
@@ -191,5 +189,33 @@
191189
"deprecated_label": "Deprecated:",
192190
"exceptions_label": "Exceptions:",
193191
"template_parameters_label": "Template Parameters:",
194-
"compiler_probe_command_line": "Compiler probe command line: {0}"
192+
"compiler_probe_command_line": "Compiler probe command line: {0}",
193+
"c_compiler_from_compiler_path": "Attempting to get defaults from C compiler in \"compilerPath\" property: '{0}'",
194+
"cpp_compiler_from_compiler_path": "Attempting to get defaults from C++ compiler in \"compilerPath\" property: '{0}'",
195+
"c_compiler_from_compile_commands": "Attempting to get defaults from C compiler in compile_commands.json file: '{0}'",
196+
"cpp_compiler_from_compile_commands": "Attempting to get defaults from C++ compiler in compile_commands.json file: '{0}'",
197+
"c_intellisense_mode_changed": "For C source files, IntelliSenseMode was changed from \"{0}\" to \"{1}\".",
198+
"cpp_intellisense_mode_changed": "For C++ source files, IntelliSenseMode was changed from \"{0}\" to \"{1}\".",
199+
"c_std_version_changed": "For C source files, the cStandard was changed from \"{0}\" to \"{1}\".",
200+
"cpp_std_version_changed": "For C++ source files, the cppStandard was changed from \"{0}\" to \"{1}\".",
201+
"c_intellisense_mode_and_std_version_changed": "For C source files, IntelliSenseMode was changed from \"{0}\" to \"{1}\" and cStandard was changed from \"{2}\" to \"{3}\".",
202+
"cpp_intellisense_mode_and_std_version_changed": "For C++ source files, IntelliSenseMode was changed from \"{0}\" to \"{1}\" and cppStandard changed from \"{2}\" to \"{3}\".",
203+
"c_intellisense_mode_changed_with_path": "For C source files, IntelliSenseMode was changed from \"{0}\" to \"{1}\" based on compiler args and probing compilerPath: \"{2}\"",
204+
"cpp_intellisense_mode_changed_with_path": "For C++ source files, IntelliSenseMode was changed from \"{0}\" to \"{1}\" based on compiler args and probing compilerPath: \"{2}\"",
205+
"c_std_version_changed_with_path": "For C source files, the cStandard was changed from \"{0}\" to \"{1}\" based on compiler args and probing compilerPath: \"{2}\"",
206+
"cpp_std_version_changed_with_path": "For C++ source files, the cppStandard was changed from \"{0}\" to \"{1}\" based on compiler args and probing compilerPath: \"{2}\"",
207+
"c_intellisense_mode_and_std_version_changed_with_path": "For C source files, IntelliSenseMode was changed from \"{0}\" to \"{1}\" and cStandard was changed from \"{2}\" to \"{3}\" based on compiler args and probing compilerPath: \"{4}\"",
208+
"cpp_intellisense_mode_and_std_version_changed_with_path": "For C++ source files, IntelliSenseMode was changed from \"{0}\" to \"{1}\" and cppStandard changed from \"{2}\" to \"{3}\" based on compiler args and probing compilerPath: \"{4}\"",
209+
"compiler_path_changed": "Unable to resolve configuration with compilerPath \"{0}\". Using \"{1}\" instead.",
210+
"compiler_path_invalid": "Unable to resolve configuration with compilerPath: \"{0}\"",
211+
"compiler_path_empty": "Skipping probe of compiler due to explicitly empty compilerPath",
212+
"msvc_intellisense_specified": "MSVC intelliSenseMode specified. Configuring for compiler cl.exe.",
213+
"unable_to_configure_cl_exe": "Unable to configure for compiler cl.exe.",
214+
"probing_compiler_default_target": "Probing compiler's default target using command line: \"{0}\" {1}",
215+
"compiler_default_target": "Compiler returned default target value: {0}",
216+
"c_probing_compiler_default_standard": "Probing compiler for default C language standard using command line: {0}",
217+
"cpp_probing_compiler_default_standard": "Probing compiler for default C++ language standard using command line: {0}",
218+
"detected_language_standard_version": "Detected language standard version: {0}",
219+
"unhandled_default_target_detected": "Unhandled default compiler target value detected: {0}",
220+
"unhandled_target_arg_detected": "Unhandled target argument value detected: {0}"
195221
}

Extension/ui/settings.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@
552552
<div class="section-text" data-loc-id="c.standard.description">The version of the C language standard to use for IntelliSense. Note: GNU standards are only used to query the set compiler to get GNU defines, and IntelliSense will emulate the equivalent C standard version.</div>
553553
<div>
554554
<select name="inputValue" id="cStandard" class="select-default">
555-
<option value="c18">c18</option>
555+
<option value="c17">c17</option>
556556
<option value="c11">c11</option>
557557
<option value="c99">c99</option>
558558
<option value="c89">c89</option>

0 commit comments

Comments
 (0)