Skip to content

Commit

Permalink
Add Validation for VS Code Settings (#12454)
Browse files Browse the repository at this point in the history
  • Loading branch information
browntarik authored Aug 9, 2024
1 parent 99af8d8 commit 3cf9a99
Show file tree
Hide file tree
Showing 10 changed files with 643 additions and 581 deletions.
2 changes: 1 addition & 1 deletion Extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -827,8 +827,8 @@
"items": {
"type": "string"
},
"default": null,
"uniqueItems": true,
"default": null,
"markdownDescription": "%c_cpp.configuration.default.browse.path.markdownDescription%",
"scope": "machine-overridable"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class CodeActionProvider implements vscode.CodeActionProvider {

let hasSelectIntelliSenseConfiguration: boolean = false;
const settings: CppSettings = new CppSettings(this.client.RootUri);
const hasConfigurationSet: boolean = settings.defaultCompilerPath !== undefined ||
const hasConfigurationSet: boolean = settings.defaultCompilerPath !== null ||
!!settings.defaultCompileCommands || !!settings.defaultConfigurationProvider ||
this.client.configuration.CurrentConfiguration?.compilerPath !== undefined ||
!!this.client.configuration.CurrentConfiguration?.compileCommands ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ export class FoldingRangeProvider implements vscode.FoldingRangeProvider {
return promise;
}

private async requestRanges(uri: string, token: vscode.CancellationToken): Promise<vscode.FoldingRange[] | undefined>
{
private async requestRanges(uri: string, token: vscode.CancellationToken): Promise<vscode.FoldingRange[] | undefined> {
const params: GetFoldingRangesParams = {
uri
};
Expand Down
3 changes: 1 addition & 2 deletions Extension/src/LanguageServer/Providers/inlayHintProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import * as vscode from 'vscode';
import { ManualPromise } from '../../Utility/Async/manualPromise';
import { CppSettings } from '../settings';

interface FileData
{
interface FileData {
version: number;
promise: ManualPromise<vscode.InlayHint[]>;
typeHints: CppInlayHint[];
Expand Down
30 changes: 12 additions & 18 deletions Extension/src/LanguageServer/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,13 +533,11 @@ interface DidChangeActiveEditorParams {
selection?: Range;
}

interface GetIncludesParams
{
interface GetIncludesParams {
maxDepth: number;
}

interface GetIncludesResult
{
interface GetIncludesResult {
includedFiles: string[];
}

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

const settings: CppSettings = new CppSettings();
if (settings.enhancedColorization && semanticTokensLegend) {
if (settings.isEnhancedColorizationEnabled && semanticTokensLegend) {
this.semanticTokensProvider = new SemanticTokensProvider();
this.semanticTokensProviderDisposable = vscode.languages.registerDocumentSemanticTokensProvider(util.documentSelector, this.semanticTokensProvider, semanticTokensLegend);
}
Expand Down Expand Up @@ -1352,9 +1350,6 @@ export class DefaultClient implements Client {
clangTidyHeaderFilter: settings.clangTidyHeaderFilter !== null ? util.resolveVariables(settings.clangTidyHeaderFilter, this.AdditionalEnvironment) : null,
clangTidyArgs: util.resolveVariablesArray(settings.clangTidyArgs, this.AdditionalEnvironment),
clangTidyUseBuildPath: settings.clangTidyUseBuildPath,
clangTidyFixWarnings: settings.clangTidyFixWarnings,
clangTidyFixErrors: settings.clangTidyFixErrors,
clangTidyFixNotes: settings.clangTidyFixNotes,
clangTidyChecksEnabled: settings.clangTidyChecksEnabled,
clangTidyChecksDisabled: settings.clangTidyChecksDisabled,
markdownInComments: settings.markdownInComments,
Expand Down Expand Up @@ -1463,7 +1458,7 @@ export class DefaultClient implements Client {
simplifyStructuredComments: workspaceSettings.simplifyStructuredComments,
intelliSenseUpdateDelay: workspaceSettings.intelliSenseUpdateDelay,
experimentalFeatures: workspaceSettings.experimentalFeatures,
enhancedColorization: workspaceSettings.enhancedColorization,
enhancedColorization: workspaceSettings.isEnhancedColorizationEnabled,
intellisenseMaxCachedProcesses: workspaceSettings.intelliSenseMaxCachedProcesses,
intellisenseMaxMemory: workspaceSettings.intelliSenseMaxMemory,
referencesMaxConcurrentThreads: workspaceSettings.referencesMaxConcurrentThreads,
Expand Down Expand Up @@ -1520,9 +1515,9 @@ export class DefaultClient implements Client {
}

const workspaceSettings: CppSettings = new CppSettings();
if (workspaceSettings.caseSensitiveFileSupport !== currentCaseSensitiveFileSupport.Value) {
if (workspaceSettings.isCaseSensitiveFileSupportEnabled !== currentCaseSensitiveFileSupport.Value) {
resetDatabase = true;
currentCaseSensitiveFileSupport.Value = workspaceSettings.caseSensitiveFileSupport;
currentCaseSensitiveFileSupport.Value = workspaceSettings.isCaseSensitiveFileSupportEnabled;
}

const cacheStoragePath: string = util.getCacheStoragePath();
Expand All @@ -1537,7 +1532,7 @@ export class DefaultClient implements Client {
cacheStoragePath: cacheStoragePath,
vcpkgRoot: util.getVcpkgRoot(),
intelliSenseCacheDisabled: intelliSenseCacheDisabled,
caseSensitiveFileSupport: workspaceSettings.caseSensitiveFileSupport,
caseSensitiveFileSupport: workspaceSettings.isCaseSensitiveFileSupportEnabled,
resetDatabase: resetDatabase,
edgeMessagesDirectory: path.join(util.getExtensionFilePath("bin"), "messages", getLocaleId()),
localizedStrings: localizedStrings,
Expand Down Expand Up @@ -1635,7 +1630,7 @@ export class DefaultClient implements Client {
}
const settings: CppSettings = new CppSettings();
if (changedSettings.enhancedColorization) {
if (settings.enhancedColorization && semanticTokensLegend) {
if (settings.isEnhancedColorizationEnabled && semanticTokensLegend) {
this.semanticTokensProvider = new SemanticTokensProvider();
this.semanticTokensProviderDisposable = vscode.languages.registerDocumentSemanticTokensProvider(util.documentSelector, this.semanticTokensProvider, semanticTokensLegend);
} else if (this.semanticTokensProviderDisposable) {
Expand Down Expand Up @@ -2101,7 +2096,7 @@ export class DefaultClient implements Client {
result = "timeout";
if (!requestFile) {
const settings: CppSettings = new CppSettings(this.RootUri);
if (settings.configurationWarnings && !this.isExternalHeader(docUri) && !vscode.debug.activeDebugSession) {
if (settings.isConfigurationWarningsEnabled && !this.isExternalHeader(docUri) && !vscode.debug.activeDebugSession) {
const dismiss: string = localize("dismiss.button", "Dismiss");
const disable: string = localize("disable.warnings.button", "Disable Warnings");
const configName: string | undefined = this.configuration.CurrentConfiguration?.name;
Expand Down Expand Up @@ -2171,7 +2166,7 @@ export class DefaultClient implements Client {

public getVcpkgEnabled(): Promise<boolean> {
const cppSettings: CppSettings = new CppSettings(this.RootUri);
return Promise.resolve(!!cppSettings.vcpkgEnabled);
return Promise.resolve(cppSettings.vcpkgEnabled);
}

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

const compilerPathNotSet: boolean = settings.defaultCompilerPath === undefined && this.configuration.CurrentConfiguration?.compilerPath === undefined && this.configuration.CurrentConfiguration?.compilerPathInCppPropertiesJson === undefined;
const compilerPathNotSet: boolean = settings.defaultCompilerPath === null && this.configuration.CurrentConfiguration?.compilerPath === undefined && this.configuration.CurrentConfiguration?.compilerPathInCppPropertiesJson === undefined;
const configurationNotSet: boolean = configProviderNotSetAndNoCache && compileCommandsNotSet && compilerPathNotSet;

showConfigStatus = showConfigStatus || (configurationNotSet &&
Expand Down Expand Up @@ -3476,8 +3471,7 @@ export class DefaultClient implements Client {
}

let formatParams: FormatParams | undefined;
if (cppSettings.useVcFormat(editor.document))
{
if (cppSettings.useVcFormat(editor.document)) {
const editorConfigSettings: any = getEditorConfigSettings(uri.fsPath);
formatParams = {
editorConfigSettings: editorConfigSettings,
Expand Down
28 changes: 14 additions & 14 deletions Extension/src/LanguageServer/configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ export class CppProperties {
// compile_commands.json already specifies a compiler. compilerPath overrides the compile_commands.json compiler so
// don't set a default when compileCommands is in use.
configuration.compilerPath = this.updateConfigurationString(configuration.compilerPath, settings.defaultCompilerPath, env, true);
configuration.compilerPathIsExplicit = configuration.compilerPathIsExplicit || settings.defaultCompilerPath !== undefined;
configuration.compilerPathIsExplicit = configuration.compilerPathIsExplicit || settings.defaultCompilerPath !== null;
if (configuration.compilerPath === undefined) {
if (!!this.defaultCompilerPath && this.trustedCompilerFound) {
// If no config value yet set for these, pick up values from the defaults, but don't consider them explicit.
Expand Down Expand Up @@ -988,7 +988,7 @@ export class CppProperties {
} else {
// However, if compileCommands are used and compilerPath is explicitly set, it's still necessary to resolve variables in it.
if (configuration.compilerPath === "${default}") {
configuration.compilerPath = settings.defaultCompilerPath;
configuration.compilerPath = settings.defaultCompilerPath ?? undefined;
}
if (configuration.compilerPath === null) {
configuration.compilerPath = undefined;
Expand Down Expand Up @@ -1041,8 +1041,8 @@ export class CppProperties {
&& !settings.defaultForcedInclude
&& !settings.defaultCompileCommands
&& !settings.defaultCompilerArgs
&& settings.defaultCStandard === ""
&& settings.defaultCppStandard === ""
&& !settings.defaultCStandard
&& !settings.defaultCppStandard
&& settings.defaultIntelliSenseMode === ""
&& !settings.defaultConfigurationProvider;

Expand Down Expand Up @@ -1640,15 +1640,15 @@ export class CppProperties {
}

// Validate paths (directories)
errors.includePath = this.validatePath(config.includePath, {globPaths: true});
errors.includePath = this.validatePath(config.includePath, { globPaths: true });
errors.macFrameworkPath = this.validatePath(config.macFrameworkPath);
errors.browsePath = this.validatePath(config.browse ? config.browse.path : undefined);

// Validate files
errors.forcedInclude = this.validatePath(config.forcedInclude, {isDirectory: false, assumeRelative: false});
errors.compileCommands = this.validatePath(config.compileCommands, {isDirectory: false});
errors.dotConfig = this.validatePath(config.dotConfig, {isDirectory: false});
errors.databaseFilename = this.validatePath(config.browse ? config.browse.databaseFilename : undefined, {isDirectory: false});
errors.forcedInclude = this.validatePath(config.forcedInclude, { isDirectory: false, assumeRelative: false });
errors.compileCommands = this.validatePath(config.compileCommands, { isDirectory: false });
errors.dotConfig = this.validatePath(config.dotConfig, { isDirectory: false });
errors.databaseFilename = this.validatePath(config.browse ? config.browse.databaseFilename : undefined, { isDirectory: false });

// Validate intelliSenseMode
if (isWindows) {
Expand All @@ -1661,7 +1661,7 @@ export class CppProperties {
return errors;
}

private validatePath(input: string | string[] | undefined, {isDirectory = true, assumeRelative = true, globPaths = false} = {}): string | undefined {
private validatePath(input: string | string[] | undefined, { isDirectory = true, assumeRelative = true, globPaths = false } = {}): string | undefined {
if (!input) {
return undefined;
}
Expand Down Expand Up @@ -1877,8 +1877,8 @@ export class CppProperties {
// Check for path-related squiggles.
const paths: string[] = [];
let compilerPath: string | undefined;
for (const pathArray of [ currentConfiguration.browse ? currentConfiguration.browse.path : undefined,
currentConfiguration.includePath, currentConfiguration.macFrameworkPath ]) {
for (const pathArray of [currentConfiguration.browse ? currentConfiguration.browse.path : undefined,
currentConfiguration.includePath, currentConfiguration.macFrameworkPath]) {
if (pathArray) {
for (const curPath of pathArray) {
paths.push(`${curPath}`);
Expand Down Expand Up @@ -2075,7 +2075,7 @@ export class CppProperties {
let message: string = "";
if (!pathExists) {
if (curOffset >= forcedIncludeStart && curOffset <= forcedeIncludeEnd
&& !path.isAbsolute(expandedPaths[0])) {
&& !path.isAbsolute(expandedPaths[0])) {
continue; // Skip the error, because it could be resolved recursively.
}
let badPath = "";
Expand All @@ -2089,7 +2089,7 @@ export class CppProperties {
} else {
// Check for file versus path mismatches.
if ((curOffset >= forcedIncludeStart && curOffset <= forcedeIncludeEnd) ||
(curOffset >= compileCommandsStart && curOffset <= compileCommandsEnd)) {
(curOffset >= compileCommandsStart && curOffset <= compileCommandsEnd)) {
if (expandedPaths.length > 1) {
message = localize("multiple.paths.not.allowed", "Multiple paths are not allowed.");
newSquiggleMetrics.MultiplePathsNotAllowed++;
Expand Down
2 changes: 1 addition & 1 deletion Extension/src/LanguageServer/cppBuildTaskProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ class CustomBuildTaskTerminal implements Pseudoterminal {
}
});
if (this.options === undefined) {
this.options = { };
this.options = {};
}
if (this.options.cwd) {
this.options.cwd = util.resolveVariables(this.options.cwd.toString());
Expand Down
2 changes: 1 addition & 1 deletion Extension/src/LanguageServer/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1319,7 +1319,7 @@ export function UpdateInsidersAccess(): void {
const insidersMitigationDone: PersistentState<boolean> = new PersistentState<boolean>("CPP.insidersMitigationDone", false);
if (!insidersMitigationDone.Value) {
if (vscode.workspace.getConfiguration("extensions", null).get<boolean>("autoUpdate")) {
if (settings.getWithUndefinedDefault<string>("updateChannel") === undefined) {
if (settings.getStringWithUndefinedDefault("updateChannel") === undefined) {
installPrerelease = true;
}
}
Expand Down
Loading

0 comments on commit 3cf9a99

Please sign in to comment.