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

Handle multiple compile commands on client side (needs native server side support) #12960

Merged
merged 29 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f346723
accept an array in compile commands schema
Nov 10, 2024
2dc0fa3
handle settings.json of multiple compile commands
yiftahw Nov 10, 2024
02a2812
update schemas
yiftahw Nov 10, 2024
280aee1
an array is returned from default settings only if non-empty with non…
yiftahw Nov 10, 2024
b934a92
basic handling of compile commands array in configurations
yiftahw Nov 11, 2024
e273731
Merge branch 'main' into handle-multiple-compile-commands
Nov 13, 2024
0c8ccb1
fixes after merge
Nov 13, 2024
8e84183
yarn lint
yiftahw Nov 14, 2024
22de1e0
unify check behavior
yiftahw Nov 14, 2024
62a8915
update desription in schema
yiftahw Nov 14, 2024
d7e2a4a
handle parsed values from c_cpp_properties.json
yiftahw Nov 14, 2024
b1614de
reverse logic to default as undefined
yiftahw Nov 14, 2024
7fe9904
squiggles for multi paths
yiftahw Nov 14, 2024
82c4e53
remove not needed optional guard
yiftahw Nov 14, 2024
69c4013
squiggles finalized
yiftahw Nov 14, 2024
d2bf51d
paths should be separated telemetry enabled for a single string
yiftahw Nov 14, 2024
6aa66f6
yarn lint
yiftahw Nov 14, 2024
45bb041
update UI to handle multiple compile commands files
yiftahw Nov 14, 2024
fbe7a2b
Merge branch 'main' into handle-multiple-compile-commands
yiftahw Dec 6, 2024
2438391
merge main
yiftahw Dec 12, 2024
dc3e543
typos and linter
yiftahw Dec 13, 2024
82d5c0b
Merge branch 'main' into handle-multiple-compile-commands
yiftahw Dec 13, 2024
c7a9c05
Merge branch 'main' into handle-multiple-compile-commands
yiftahw Dec 18, 2024
cc09fff
Merge branch 'main' into handle-multiple-compile-commands
yiftahw Dec 19, 2024
421300d
Merge branch 'main' into handle-multiple-compile-commands
sean-mcmanus Dec 20, 2024
54af67e
Address issues with C_Cpp.default.compileCommands
bobbrow Dec 20, 2024
d916822
Merge branch 'main' into handle-multiple-compile-commands
yiftahw Dec 21, 2024
ad3073c
remove defaults from c_cpp_properties schema
yiftahw Dec 25, 2024
e4a3ab8
Merge branch 'handle-multiple-compile-commands' of github.com:yiftahw…
yiftahw Dec 25, 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
17 changes: 15 additions & 2 deletions Extension/c_cpp_properties.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,22 @@
]
},
"compileCommands": {
"oneOf": [
{
"type": "string",
"default": ""
bobbrow marked this conversation as resolved.
Show resolved Hide resolved
},
{
"type": "array",
"items": {
"type": "string"
},
"uniqueItems": true,
"default": []
sean-mcmanus marked this conversation as resolved.
Show resolved Hide resolved
}
],
sean-mcmanus marked this conversation as resolved.
Show resolved Hide resolved
"markdownDescription": "Full path to `compile_commands.json` file for the workspace.",
bobbrow marked this conversation as resolved.
Show resolved Hide resolved
"descriptionHint": "Markdown text between `` should not be translated or localized (they represent literal text) and the capitalization, spacing, and punctuation (including the ``) should not be altered.",
"type": "string"
"descriptionHint": "Markdown text between `` should not be translated or localized (they represent literal text) and the capitalization, spacing, and punctuation (including the ``) should not be altered."
},
"includePath": {
"markdownDescription": "A list of paths for the IntelliSense engine to use while searching for included headers. Searching on these paths is not recursive. Specify `**` to indicate recursive search. For example, `${workspaceFolder}/**` will search through all subdirectories while `${workspaceFolder}` will not. Usually, this should not include system includes; instead, set `C_Cpp.default.compilerPath`.",
Expand Down
15 changes: 14 additions & 1 deletion Extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,20 @@
"scope": "machine-overridable"
},
"C_Cpp.default.compileCommands": {
"type": "string",
"oneOf": [
{
"type": "string",
"default": ""
},
{
"type": "array",
"items": {
"type": "string"
},
"uniqueItems": true,
"default": []
}
],
"markdownDescription": "%c_cpp.configuration.default.compileCommands.markdownDescription%",
"scope": "machine-overridable"
},
Expand Down
80 changes: 43 additions & 37 deletions Extension/src/LanguageServer/configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@
defines?: string[];
intelliSenseMode?: string;
intelliSenseModeIsExplicit?: boolean;
compileCommandsInCppPropertiesJson?: string;
compileCommands?: string;
compileCommandsInCppPropertiesJson?: string[];
compileCommands?: string[];
forcedInclude?: string[];
configurationProviderInCppPropertiesJson?: string;
configurationProvider?: string;
Expand Down Expand Up @@ -136,7 +136,7 @@
private currentConfigurationIndex: PersistentFolderState<number> | undefined;
private configFileWatcher: vscode.FileSystemWatcher | null = null;
private configFileWatcherFallbackTime: Date = new Date(); // Used when file watching fails.
private compileCommandsFile: vscode.Uri | undefined | null = undefined;
private compileCommandsFiles: Set<string> = new Set();
private compileCommandsFileWatchers: fs.FSWatcher[] = [];
private compileCommandsFileWatcherFallbackTime: Map<string, Date> = new Map<string, Date>(); // Used when file watching fails.
private defaultCompilerPath: string | null = null;
Expand Down Expand Up @@ -389,7 +389,7 @@
configuration.windowsSdkVersion = this.defaultWindowsSdkVersion;
}
if (isUnset(settings.defaultCompilerPath) && this.defaultCompilerPath &&
(isUnset(settings.defaultCompileCommands) || settings.defaultCompileCommands === "") && !configuration.compileCommands) {
(isUnset(settings.defaultCompileCommands) || settings.defaultCompileCommands?.length === 0) && !configuration.compileCommands) {
// 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.

Expand Down Expand Up @@ -684,7 +684,7 @@
this.parsePropertiesFile(); // Clear out any modifications we may have made internally.
const config: Configuration | undefined = this.CurrentConfiguration;
if (config) {
config.compileCommands = path;
config.compileCommands = [path];
sean-mcmanus marked this conversation as resolved.
Show resolved Hide resolved
this.writeToJson();
}
// Any time parsePropertiesFile is called, configurationJson gets
Expand Down Expand Up @@ -938,7 +938,7 @@
configuration.macFrameworkPath = this.updateConfigurationStringArray(configuration.macFrameworkPath, settings.defaultMacFrameworkPath, env);
configuration.windowsSdkVersion = this.updateConfigurationString(configuration.windowsSdkVersion, settings.defaultWindowsSdkVersion, env);
configuration.forcedInclude = this.updateConfigurationPathsArray(configuration.forcedInclude, settings.defaultForcedInclude, env, false);
configuration.compileCommands = this.updateConfigurationString(configuration.compileCommands, settings.defaultCompileCommands, env);
configuration.compileCommands = this.updateConfigurationStringArray(configuration.compileCommands, settings.defaultCompileCommands, env);
configuration.compilerArgs = this.updateConfigurationStringArray(configuration.compilerArgs, settings.defaultCompilerArgs, env);
configuration.cStandard = this.updateConfigurationString(configuration.cStandard, settings.defaultCStandard, env);
configuration.cppStandard = this.updateConfigurationString(configuration.cppStandard, settings.defaultCppStandard, env);
Expand Down Expand Up @@ -1092,11 +1092,13 @@
}

if (configuration.compileCommands) {
configuration.compileCommands = this.resolvePath(configuration.compileCommands);
if (!this.compileCommandsFileWatcherFallbackTime.has(configuration.compileCommands)) {
// Start tracking the fallback time for a new path.
this.compileCommandsFileWatcherFallbackTime.set(configuration.compileCommands, new Date());
}
configuration.compileCommands = configuration.compileCommands?.map((path: string) => this.resolvePath(path));
bobbrow marked this conversation as resolved.
Show resolved Hide resolved
configuration.compileCommands?.forEach((path: string) => {
if (!this.compileCommandsFileWatcherFallbackTime.has(path)) {
// Start tracking the fallback time for a new path.
this.compileCommandsFileWatcherFallbackTime.set(path, new Date());
}
});
}

if (configuration.forcedInclude) {
Expand All @@ -1120,10 +1122,12 @@
// Instead, we clear entries that are no longer relevant.
const trackedCompileCommandsPaths: Set<string> = new Set();
this.configurationJson?.configurations.forEach((config: Configuration) => {
const path = this.resolvePath(config.compileCommands);
if (path.length > 0) {
trackedCompileCommandsPaths.add(path);
}
config.compileCommands?.forEach((path: string) => {
const compileCommandsFile = this.resolvePath(path);
if (compileCommandsFile.length > 0) {
trackedCompileCommandsPaths.add(compileCommandsFile);
}
});
});

for (const path of this.compileCommandsFileWatcherFallbackTime.keys()) {
Expand All @@ -1144,12 +1148,12 @@
this.compileCommandsFileWatchers = []; // reset it
const filePaths: Set<string> = new Set<string>();
this.configurationJson.configurations.forEach(c => {
if (c.compileCommands) {
const fileSystemCompileCommandsPath: string = this.resolvePath(c.compileCommands);
if (fs.existsSync(fileSystemCompileCommandsPath)) {
filePaths.add(fileSystemCompileCommandsPath);
c.compileCommands?.forEach((path: string) => {
const compileCommandsFile: string = this.resolvePath(path);
if (fs.existsSync(compileCommandsFile)) {
filePaths.add(compileCommandsFile);
}
}
})

Check failure on line 1156 in Extension/src/LanguageServer/configurations.ts

View workflow job for this annotation

GitHub Actions / job / build

Missing semicolon

Check failure on line 1156 in Extension/src/LanguageServer/configurations.ts

View workflow job for this annotation

GitHub Actions / job / build

Missing semicolon

Check failure on line 1156 in Extension/src/LanguageServer/configurations.ts

View workflow job for this annotation

GitHub Actions / job / build

Missing semicolon
});
try {
filePaths.forEach((path: string) => {
Expand Down Expand Up @@ -2325,27 +2329,29 @@

public checkCompileCommands(): void {
// Check for changes in case of file watcher failure.
const compileCommands: string | undefined = this.CurrentConfiguration?.compileCommands;
const compileCommands: string[] | undefined = this.CurrentConfiguration?.compileCommands;
if (!compileCommands) {
return;
}
const compileCommandsFile: string | undefined = this.resolvePath(compileCommands);
fs.stat(compileCommandsFile, (err, stats) => {
if (err) {
if (err.code === "ENOENT" && this.compileCommandsFile) {
this.compileCommandsFileWatchers.forEach((watcher: fs.FSWatcher) => watcher.close());
this.compileCommandsFileWatchers = []; // reset file watchers
this.onCompileCommandsChanged(compileCommandsFile);
this.compileCommandsFile = null; // File deleted
}
} else {
const compileCommandsLastChanged: Date | undefined = this.compileCommandsFileWatcherFallbackTime.get(compileCommandsFile);
if (compileCommandsLastChanged !== undefined && stats.mtime > compileCommandsLastChanged) {
this.compileCommandsFileWatcherFallbackTime.set(compileCommandsFile, new Date());
this.onCompileCommandsChanged(compileCommandsFile);
this.compileCommandsFile = vscode.Uri.file(compileCommandsFile); // File created.
compileCommands.forEach((path: string) => {
const compileCommandsFile: string | undefined = this.resolvePath(path);
fs.stat(compileCommandsFile, (err, stats) => {
if (err) {
if (err.code === "ENOENT" && this.compileCommandsFiles.has(compileCommandsFile)) {
this.compileCommandsFileWatchers.forEach((watcher: fs.FSWatcher) => watcher.close());
this.compileCommandsFileWatchers = []; // reset file watchers
this.onCompileCommandsChanged(compileCommandsFile);
this.compileCommandsFiles.delete(compileCommandsFile); // File deleted
}
} else {
const compileCommandsLastChanged: Date | undefined = this.compileCommandsFileWatcherFallbackTime.get(compileCommandsFile);
if (compileCommandsLastChanged !== undefined && stats.mtime > compileCommandsLastChanged) {
this.compileCommandsFileWatcherFallbackTime.set(compileCommandsFile, new Date());
this.onCompileCommandsChanged(compileCommandsFile);
this.compileCommandsFiles.add(compileCommandsFile); // File created.
}
}
}
});
});
}

Expand Down
22 changes: 20 additions & 2 deletions Extension/src/LanguageServer/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,12 +399,30 @@
public get defaultDotconfig(): string | undefined { return changeBlankStringToUndefined(this.getAsStringOrUndefined("default.dotConfig")); }
public get defaultMacFrameworkPath(): string[] | undefined { return this.getArrayOfStringsWithUndefinedDefault("default.macFrameworkPath"); }
public get defaultWindowsSdkVersion(): string | undefined { return changeBlankStringToUndefined(this.getAsStringOrUndefined("default.windowsSdkVersion")); }
public get defaultCompileCommands(): string | undefined { return changeBlankStringToUndefined(this.getAsStringOrUndefined("default.compileCommands")); }
public get defaultForcedInclude(): string[] | undefined { return this.getArrayOfStringsWithUndefinedDefault("default.forcedInclude"); }
public get defaultIntelliSenseMode(): string | undefined { return this.getAsStringOrUndefined("default.intelliSenseMode"); }
public get defaultCompilerPath(): string | null { return this.getAsString("default.compilerPath", true); }
public get defaultCompileCommands(): string[] | undefined {
// Try to get the value as a string.
const value: string | undefined = this.getAsStringOrUndefined("default.compileCommands");
if (value !== undefined) {
if (changeBlankStringToUndefined(value) === undefined) {
return undefined;
}
return [value];
}

// value is not a string, try to get it as an array of strings instead.
var valueArray: string[] | undefined = this.getAsArrayOfStringsOrUndefined("default.compileCommands");

Check failure on line 416 in Extension/src/LanguageServer/settings.ts

View workflow job for this annotation

GitHub Actions / job / build

Unexpected var, use let or const instead

Check failure on line 416 in Extension/src/LanguageServer/settings.ts

View workflow job for this annotation

GitHub Actions / job / build

Unexpected var, use let or const instead

Check failure on line 416 in Extension/src/LanguageServer/settings.ts

View workflow job for this annotation

GitHub Actions / job / build

Unexpected var, use let or const instead
valueArray = valueArray?.filter((value) => value !== "");
if (valueArray?.length === 0) {
return undefined;
}
return valueArray;
}


Check failure on line 424 in Extension/src/LanguageServer/settings.ts

View workflow job for this annotation

GitHub Actions / job / build

More than 1 blank line not allowed

Check failure on line 424 in Extension/src/LanguageServer/settings.ts

View workflow job for this annotation

GitHub Actions / job / build

More than 1 blank line not allowed

Check failure on line 424 in Extension/src/LanguageServer/settings.ts

View workflow job for this annotation

GitHub Actions / job / build

More than 1 blank line not allowed
public set defaultCompilerPath(value: string) {

Check failure on line 425 in Extension/src/LanguageServer/settings.ts

View workflow job for this annotation

GitHub Actions / job / build

All defaultCompilerPath signatures should be adjacent

Check failure on line 425 in Extension/src/LanguageServer/settings.ts

View workflow job for this annotation

GitHub Actions / job / build

All defaultCompilerPath signatures should be adjacent

Check failure on line 425 in Extension/src/LanguageServer/settings.ts

View workflow job for this annotation

GitHub Actions / job / build

All defaultCompilerPath signatures should be adjacent
const defaultCompilerPathStr: string = "default.compilerPath";
const compilerPathInfo: any = this.Section.inspect(defaultCompilerPathStr);
let target: vscode.ConfigurationTarget = vscode.ConfigurationTarget.Global;
Expand Down Expand Up @@ -638,7 +656,7 @@
}

if (isArrayOfString(value)) {
if (setting.items.enum && !allowUndefinedEnums) {
if (setting.items?.enum !== undefined && !allowUndefinedEnums) {
if (!value.every(x => this.isValidEnum(setting.items.enum, x))) {
return setting.default;
}
Expand Down
Loading