Skip to content

Commit 3cf9a99

Browse files
authored
Add Validation for VS Code Settings (#12454)
1 parent 99af8d8 commit 3cf9a99

File tree

10 files changed

+643
-581
lines changed

10 files changed

+643
-581
lines changed

Extension/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,8 +827,8 @@
827827
"items": {
828828
"type": "string"
829829
},
830-
"default": null,
831830
"uniqueItems": true,
831+
"default": null,
832832
"markdownDescription": "%c_cpp.configuration.default.browse.path.markdownDescription%",
833833
"scope": "machine-overridable"
834834
},

Extension/src/LanguageServer/Providers/codeActionProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
8080

8181
let hasSelectIntelliSenseConfiguration: boolean = false;
8282
const settings: CppSettings = new CppSettings(this.client.RootUri);
83-
const hasConfigurationSet: boolean = settings.defaultCompilerPath !== undefined ||
83+
const hasConfigurationSet: boolean = settings.defaultCompilerPath !== null ||
8484
!!settings.defaultCompileCommands || !!settings.defaultConfigurationProvider ||
8585
this.client.configuration.CurrentConfiguration?.compilerPath !== undefined ||
8686
!!this.client.configuration.CurrentConfiguration?.compileCommands ||

Extension/src/LanguageServer/Providers/foldingRangeProvider.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ export class FoldingRangeProvider implements vscode.FoldingRangeProvider {
5757
return promise;
5858
}
5959

60-
private async requestRanges(uri: string, token: vscode.CancellationToken): Promise<vscode.FoldingRange[] | undefined>
61-
{
60+
private async requestRanges(uri: string, token: vscode.CancellationToken): Promise<vscode.FoldingRange[] | undefined> {
6261
const params: GetFoldingRangesParams = {
6362
uri
6463
};

Extension/src/LanguageServer/Providers/inlayHintProvider.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import * as vscode from 'vscode';
66
import { ManualPromise } from '../../Utility/Async/manualPromise';
77
import { CppSettings } from '../settings';
88

9-
interface FileData
10-
{
9+
interface FileData {
1110
version: number;
1211
promise: ManualPromise<vscode.InlayHint[]>;
1312
typeHints: CppInlayHint[];

Extension/src/LanguageServer/client.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -533,13 +533,11 @@ interface DidChangeActiveEditorParams {
533533
selection?: Range;
534534
}
535535

536-
interface GetIncludesParams
537-
{
536+
interface GetIncludesParams {
538537
maxDepth: number;
539538
}
540539

541-
interface GetIncludesResult
542-
{
540+
interface GetIncludesResult {
543541
includedFiles: string[];
544542
}
545543

@@ -1275,7 +1273,7 @@ export class DefaultClient implements Client {
12751273
this.codeFoldingProviderDisposable = vscode.languages.registerFoldingRangeProvider(util.documentSelector, this.codeFoldingProvider);
12761274

12771275
const settings: CppSettings = new CppSettings();
1278-
if (settings.enhancedColorization && semanticTokensLegend) {
1276+
if (settings.isEnhancedColorizationEnabled && semanticTokensLegend) {
12791277
this.semanticTokensProvider = new SemanticTokensProvider();
12801278
this.semanticTokensProviderDisposable = vscode.languages.registerDocumentSemanticTokensProvider(util.documentSelector, this.semanticTokensProvider, semanticTokensLegend);
12811279
}
@@ -1352,9 +1350,6 @@ export class DefaultClient implements Client {
13521350
clangTidyHeaderFilter: settings.clangTidyHeaderFilter !== null ? util.resolveVariables(settings.clangTidyHeaderFilter, this.AdditionalEnvironment) : null,
13531351
clangTidyArgs: util.resolveVariablesArray(settings.clangTidyArgs, this.AdditionalEnvironment),
13541352
clangTidyUseBuildPath: settings.clangTidyUseBuildPath,
1355-
clangTidyFixWarnings: settings.clangTidyFixWarnings,
1356-
clangTidyFixErrors: settings.clangTidyFixErrors,
1357-
clangTidyFixNotes: settings.clangTidyFixNotes,
13581353
clangTidyChecksEnabled: settings.clangTidyChecksEnabled,
13591354
clangTidyChecksDisabled: settings.clangTidyChecksDisabled,
13601355
markdownInComments: settings.markdownInComments,
@@ -1463,7 +1458,7 @@ export class DefaultClient implements Client {
14631458
simplifyStructuredComments: workspaceSettings.simplifyStructuredComments,
14641459
intelliSenseUpdateDelay: workspaceSettings.intelliSenseUpdateDelay,
14651460
experimentalFeatures: workspaceSettings.experimentalFeatures,
1466-
enhancedColorization: workspaceSettings.enhancedColorization,
1461+
enhancedColorization: workspaceSettings.isEnhancedColorizationEnabled,
14671462
intellisenseMaxCachedProcesses: workspaceSettings.intelliSenseMaxCachedProcesses,
14681463
intellisenseMaxMemory: workspaceSettings.intelliSenseMaxMemory,
14691464
referencesMaxConcurrentThreads: workspaceSettings.referencesMaxConcurrentThreads,
@@ -1520,9 +1515,9 @@ export class DefaultClient implements Client {
15201515
}
15211516

15221517
const workspaceSettings: CppSettings = new CppSettings();
1523-
if (workspaceSettings.caseSensitiveFileSupport !== currentCaseSensitiveFileSupport.Value) {
1518+
if (workspaceSettings.isCaseSensitiveFileSupportEnabled !== currentCaseSensitiveFileSupport.Value) {
15241519
resetDatabase = true;
1525-
currentCaseSensitiveFileSupport.Value = workspaceSettings.caseSensitiveFileSupport;
1520+
currentCaseSensitiveFileSupport.Value = workspaceSettings.isCaseSensitiveFileSupportEnabled;
15261521
}
15271522

15281523
const cacheStoragePath: string = util.getCacheStoragePath();
@@ -1537,7 +1532,7 @@ export class DefaultClient implements Client {
15371532
cacheStoragePath: cacheStoragePath,
15381533
vcpkgRoot: util.getVcpkgRoot(),
15391534
intelliSenseCacheDisabled: intelliSenseCacheDisabled,
1540-
caseSensitiveFileSupport: workspaceSettings.caseSensitiveFileSupport,
1535+
caseSensitiveFileSupport: workspaceSettings.isCaseSensitiveFileSupportEnabled,
15411536
resetDatabase: resetDatabase,
15421537
edgeMessagesDirectory: path.join(util.getExtensionFilePath("bin"), "messages", getLocaleId()),
15431538
localizedStrings: localizedStrings,
@@ -1635,7 +1630,7 @@ export class DefaultClient implements Client {
16351630
}
16361631
const settings: CppSettings = new CppSettings();
16371632
if (changedSettings.enhancedColorization) {
1638-
if (settings.enhancedColorization && semanticTokensLegend) {
1633+
if (settings.isEnhancedColorizationEnabled && semanticTokensLegend) {
16391634
this.semanticTokensProvider = new SemanticTokensProvider();
16401635
this.semanticTokensProviderDisposable = vscode.languages.registerDocumentSemanticTokensProvider(util.documentSelector, this.semanticTokensProvider, semanticTokensLegend);
16411636
} else if (this.semanticTokensProviderDisposable) {
@@ -2101,7 +2096,7 @@ export class DefaultClient implements Client {
21012096
result = "timeout";
21022097
if (!requestFile) {
21032098
const settings: CppSettings = new CppSettings(this.RootUri);
2104-
if (settings.configurationWarnings && !this.isExternalHeader(docUri) && !vscode.debug.activeDebugSession) {
2099+
if (settings.isConfigurationWarningsEnabled && !this.isExternalHeader(docUri) && !vscode.debug.activeDebugSession) {
21052100
const dismiss: string = localize("dismiss.button", "Dismiss");
21062101
const disable: string = localize("disable.warnings.button", "Disable Warnings");
21072102
const configName: string | undefined = this.configuration.CurrentConfiguration?.name;
@@ -2171,7 +2166,7 @@ export class DefaultClient implements Client {
21712166

21722167
public getVcpkgEnabled(): Promise<boolean> {
21732168
const cppSettings: CppSettings = new CppSettings(this.RootUri);
2174-
return Promise.resolve(!!cppSettings.vcpkgEnabled);
2169+
return Promise.resolve(cppSettings.vcpkgEnabled);
21752170
}
21762171

21772172
public async getKnownCompilers(): Promise<configs.KnownCompiler[] | undefined> {
@@ -2731,7 +2726,7 @@ export class DefaultClient implements Client {
27312726
showConfigStatus = ask.Value;
27322727
}
27332728

2734-
const compilerPathNotSet: boolean = settings.defaultCompilerPath === undefined && this.configuration.CurrentConfiguration?.compilerPath === undefined && this.configuration.CurrentConfiguration?.compilerPathInCppPropertiesJson === undefined;
2729+
const compilerPathNotSet: boolean = settings.defaultCompilerPath === null && this.configuration.CurrentConfiguration?.compilerPath === undefined && this.configuration.CurrentConfiguration?.compilerPathInCppPropertiesJson === undefined;
27352730
const configurationNotSet: boolean = configProviderNotSetAndNoCache && compileCommandsNotSet && compilerPathNotSet;
27362731

27372732
showConfigStatus = showConfigStatus || (configurationNotSet &&
@@ -3476,8 +3471,7 @@ export class DefaultClient implements Client {
34763471
}
34773472

34783473
let formatParams: FormatParams | undefined;
3479-
if (cppSettings.useVcFormat(editor.document))
3480-
{
3474+
if (cppSettings.useVcFormat(editor.document)) {
34813475
const editorConfigSettings: any = getEditorConfigSettings(uri.fsPath);
34823476
formatParams = {
34833477
editorConfigSettings: editorConfigSettings,

Extension/src/LanguageServer/configurations.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ export class CppProperties {
951951
// compile_commands.json already specifies a compiler. compilerPath overrides the compile_commands.json compiler so
952952
// don't set a default when compileCommands is in use.
953953
configuration.compilerPath = this.updateConfigurationString(configuration.compilerPath, settings.defaultCompilerPath, env, true);
954-
configuration.compilerPathIsExplicit = configuration.compilerPathIsExplicit || settings.defaultCompilerPath !== undefined;
954+
configuration.compilerPathIsExplicit = configuration.compilerPathIsExplicit || settings.defaultCompilerPath !== null;
955955
if (configuration.compilerPath === undefined) {
956956
if (!!this.defaultCompilerPath && this.trustedCompilerFound) {
957957
// If no config value yet set for these, pick up values from the defaults, but don't consider them explicit.
@@ -988,7 +988,7 @@ export class CppProperties {
988988
} else {
989989
// However, if compileCommands are used and compilerPath is explicitly set, it's still necessary to resolve variables in it.
990990
if (configuration.compilerPath === "${default}") {
991-
configuration.compilerPath = settings.defaultCompilerPath;
991+
configuration.compilerPath = settings.defaultCompilerPath ?? undefined;
992992
}
993993
if (configuration.compilerPath === null) {
994994
configuration.compilerPath = undefined;
@@ -1041,8 +1041,8 @@ export class CppProperties {
10411041
&& !settings.defaultForcedInclude
10421042
&& !settings.defaultCompileCommands
10431043
&& !settings.defaultCompilerArgs
1044-
&& settings.defaultCStandard === ""
1045-
&& settings.defaultCppStandard === ""
1044+
&& !settings.defaultCStandard
1045+
&& !settings.defaultCppStandard
10461046
&& settings.defaultIntelliSenseMode === ""
10471047
&& !settings.defaultConfigurationProvider;
10481048

@@ -1640,15 +1640,15 @@ export class CppProperties {
16401640
}
16411641

16421642
// Validate paths (directories)
1643-
errors.includePath = this.validatePath(config.includePath, {globPaths: true});
1643+
errors.includePath = this.validatePath(config.includePath, { globPaths: true });
16441644
errors.macFrameworkPath = this.validatePath(config.macFrameworkPath);
16451645
errors.browsePath = this.validatePath(config.browse ? config.browse.path : undefined);
16461646

16471647
// Validate files
1648-
errors.forcedInclude = this.validatePath(config.forcedInclude, {isDirectory: false, assumeRelative: false});
1649-
errors.compileCommands = this.validatePath(config.compileCommands, {isDirectory: false});
1650-
errors.dotConfig = this.validatePath(config.dotConfig, {isDirectory: false});
1651-
errors.databaseFilename = this.validatePath(config.browse ? config.browse.databaseFilename : undefined, {isDirectory: false});
1648+
errors.forcedInclude = this.validatePath(config.forcedInclude, { isDirectory: false, assumeRelative: false });
1649+
errors.compileCommands = this.validatePath(config.compileCommands, { isDirectory: false });
1650+
errors.dotConfig = this.validatePath(config.dotConfig, { isDirectory: false });
1651+
errors.databaseFilename = this.validatePath(config.browse ? config.browse.databaseFilename : undefined, { isDirectory: false });
16521652

16531653
// Validate intelliSenseMode
16541654
if (isWindows) {
@@ -1661,7 +1661,7 @@ export class CppProperties {
16611661
return errors;
16621662
}
16631663

1664-
private validatePath(input: string | string[] | undefined, {isDirectory = true, assumeRelative = true, globPaths = false} = {}): string | undefined {
1664+
private validatePath(input: string | string[] | undefined, { isDirectory = true, assumeRelative = true, globPaths = false } = {}): string | undefined {
16651665
if (!input) {
16661666
return undefined;
16671667
}
@@ -1877,8 +1877,8 @@ export class CppProperties {
18771877
// Check for path-related squiggles.
18781878
const paths: string[] = [];
18791879
let compilerPath: string | undefined;
1880-
for (const pathArray of [ currentConfiguration.browse ? currentConfiguration.browse.path : undefined,
1881-
currentConfiguration.includePath, currentConfiguration.macFrameworkPath ]) {
1880+
for (const pathArray of [currentConfiguration.browse ? currentConfiguration.browse.path : undefined,
1881+
currentConfiguration.includePath, currentConfiguration.macFrameworkPath]) {
18821882
if (pathArray) {
18831883
for (const curPath of pathArray) {
18841884
paths.push(`${curPath}`);
@@ -2075,7 +2075,7 @@ export class CppProperties {
20752075
let message: string = "";
20762076
if (!pathExists) {
20772077
if (curOffset >= forcedIncludeStart && curOffset <= forcedeIncludeEnd
2078-
&& !path.isAbsolute(expandedPaths[0])) {
2078+
&& !path.isAbsolute(expandedPaths[0])) {
20792079
continue; // Skip the error, because it could be resolved recursively.
20802080
}
20812081
let badPath = "";
@@ -2089,7 +2089,7 @@ export class CppProperties {
20892089
} else {
20902090
// Check for file versus path mismatches.
20912091
if ((curOffset >= forcedIncludeStart && curOffset <= forcedeIncludeEnd) ||
2092-
(curOffset >= compileCommandsStart && curOffset <= compileCommandsEnd)) {
2092+
(curOffset >= compileCommandsStart && curOffset <= compileCommandsEnd)) {
20932093
if (expandedPaths.length > 1) {
20942094
message = localize("multiple.paths.not.allowed", "Multiple paths are not allowed.");
20952095
newSquiggleMetrics.MultiplePathsNotAllowed++;

Extension/src/LanguageServer/cppBuildTaskProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ class CustomBuildTaskTerminal implements Pseudoterminal {
414414
}
415415
});
416416
if (this.options === undefined) {
417-
this.options = { };
417+
this.options = {};
418418
}
419419
if (this.options.cwd) {
420420
this.options.cwd = util.resolveVariables(this.options.cwd.toString());

Extension/src/LanguageServer/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1319,7 +1319,7 @@ export function UpdateInsidersAccess(): void {
13191319
const insidersMitigationDone: PersistentState<boolean> = new PersistentState<boolean>("CPP.insidersMitigationDone", false);
13201320
if (!insidersMitigationDone.Value) {
13211321
if (vscode.workspace.getConfiguration("extensions", null).get<boolean>("autoUpdate")) {
1322-
if (settings.getWithUndefinedDefault<string>("updateChannel") === undefined) {
1322+
if (settings.getStringWithUndefinedDefault("updateChannel") === undefined) {
13231323
installPrerelease = true;
13241324
}
13251325
}

0 commit comments

Comments
 (0)