Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Validation for VS Code Settings #12454

Merged
merged 67 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
704334b
Add initial type and enum validation for extension settings
browntarik Jun 25, 2024
9bce0a4
Add Enum Validation
browntarik Jun 26, 2024
cd24fbf
Reformat settings and add ToLowerCase to enum values
browntarik Jun 26, 2024
dafb549
Revert package.json changes and add Object type validation.
browntarik Jun 26, 2024
cf9d1fc
Refactor settings to account for min/max values and handle vs code st…
browntarik Jul 8, 2024
1e913c9
Add comments + fix formatting
browntarik Jul 8, 2024
3d388a8
Fix lint issues
browntarik Jul 8, 2024
1c4acab
Merge branch 'main' into browntarik/settingValidation
browntarik Jul 8, 2024
0a9b17e
Fix minor issues found in initial code review
browntarik Jul 9, 2024
f37af58
Add minor refactors to validation logic
browntarik Jul 10, 2024
d80a7b7
Merge branch 'browntarik/settingValidation' of https://github.com/Mic…
browntarik Jul 10, 2024
74ff65f
Merge branch 'main' into browntarik/settingValidation
browntarik Jul 10, 2024
013e1f7
Provide minor refactoring + minor fixes
browntarik Jul 11, 2024
f1898b2
Merge branch 'browntarik/settingValidation' of https://github.com/Mic…
browntarik Jul 11, 2024
6398d45
Provide refactoring, add helper functions + minor fixes
browntarik Jul 12, 2024
f154510
Merge branch 'main' into browntarik/settingValidation
browntarik Jul 12, 2024
f1b6f09
Add missing toLowerCase calls
browntarik Jul 12, 2024
509b011
Merge branch 'browntarik/settingValidation' of https://github.com/Mic…
browntarik Jul 12, 2024
0fd0d77
Fix function comment
browntarik Jul 12, 2024
d8c8ea8
Remove unused setting getters, minor refactorings + minor fixes.
browntarik Jul 15, 2024
806a5ad
Remove usage of the undefined type where possible
browntarik Jul 15, 2024
6f48a05
Refactor unnessecary overloads caught by linter
browntarik Jul 16, 2024
945b77f
minor changes
bobbrow Jul 16, 2024
c9b50ca
Update the default values for editor settings and make them required.
browntarik Jul 16, 2024
7407466
Fix lint issues
browntarik Jul 16, 2024
3eaecdb
Remove unused TextMateRule interface, Refactor KeyValueObject validat…
browntarik Jul 16, 2024
f0e0e34
Fix lint issues
browntarik Jul 16, 2024
728a991
Use clamping to process min and max value, add null types + minor ref…
browntarik Jul 17, 2024
77dcd17
Properly propagate null types from null related settings.
browntarik Jul 18, 2024
0a569e0
Merge branch 'main' into browntarik/settingValidation
browntarik Jul 18, 2024
aacd9c3
Merge branch 'main' into browntarik/settingValidation
bobbrow Jul 19, 2024
64e0d6e
Refactor usage of null and undefined types in settings.
browntarik Jul 19, 2024
efa07d5
Merge branch 'browntarik/settingValidation' of https://github.com/Mic…
browntarik Jul 19, 2024
5021632
Fix lint issues and formatting.
browntarik Jul 19, 2024
5186b16
Fix lint issues
browntarik Jul 19, 2024
85d2825
Remove uneeded null value
browntarik Jul 19, 2024
4eb61d7
Revert null propogation and refactor helper functions to allow null i…
browntarik Jul 23, 2024
440625b
Fix lint issues
browntarik Jul 23, 2024
8ceb992
move the helper functions down to try to help the diff
bobbrow Jul 23, 2024
93a22bf
Merge branch 'main' into browntarik/settingValidation
browntarik Jul 26, 2024
845f25a
Add oneOf to package.json
browntarik Jul 29, 2024
b7059b7
Merge branch 'browntarik/settingValidation' of https://github.com/Mic…
browntarik Jul 29, 2024
e674422
change type to array
browntarik Jul 29, 2024
6012a44
Add undefined types to neccessary settings + minor refactoring + fixes
browntarik Jul 31, 2024
11955b1
Merge branch 'main' into browntarik/settingValidation
browntarik Jul 31, 2024
7f3970d
Change string to correct case
browntarik Jul 31, 2024
b317f9a
Merge branch 'browntarik/settingValidation' of https://github.com/Mic…
browntarik Jul 31, 2024
2405597
Correct package.json syntax and refactor settings.ts
browntarik Jul 31, 2024
5402801
Fix lint issues
browntarik Jul 31, 2024
11df9d4
Refactor helper functions + minor fixes
browntarik Aug 1, 2024
ddfc703
Remove null type
browntarik Aug 2, 2024
a4f1501
Refactor setting validation for VS Code settings to include telemetry…
browntarik Aug 5, 2024
862b8e3
Merge branch 'main' into browntarik/settingValidation
browntarik Aug 5, 2024
92e99dc
Refactor loggingLevel fix, refactor setting telemetry into helper fun…
browntarik Aug 6, 2024
514edd5
Merge branch 'browntarik/settingValidation' of https://github.com/Mic…
browntarik Aug 6, 2024
7b21861
Remove unneeded checks for undefined section values.
browntarik Aug 6, 2024
5bd191d
Minor refactorings and renamings
browntarik Aug 6, 2024
31cb939
Ensure clangFormatStyle and clangFormatFallbackStyle returns undefine…
browntarik Aug 6, 2024
4748320
Fix linting issue
browntarik Aug 6, 2024
306e741
Fix issues with sending clangtidy settings.
browntarik Aug 7, 2024
b982174
Refactor clangtidyheaderfilter to return a null typing.
browntarik Aug 7, 2024
9379b2e
Address PR feedback
bobbrow Aug 9, 2024
fe539d5
lint
bobbrow Aug 9, 2024
9866552
PR feedback
bobbrow Aug 9, 2024
29d0bca
Revised break for getRawSetting
bobbrow Aug 9, 2024
f3dbe08
lint
bobbrow Aug 9, 2024
43ce5f9
Fix a few remaining types
bobbrow Aug 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": {
browntarik marked this conversation as resolved.
Show resolved Hide resolved
"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 @@ -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
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
28 changes: 11 additions & 17 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.isVcpkgEnabled);
}

public async getKnownCompilers(): Promise<configs.KnownCompiler[] | undefined> {
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
20 changes: 10 additions & 10 deletions Extension/src/LanguageServer/configurations.ts
Original file line number Diff line number Diff line change
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
Loading