Skip to content

Commit a0c7cb3

Browse files
committed
optimize 'canProvideConfiguration'
1 parent ec4b039 commit a0c7cb3

1 file changed

Lines changed: 28 additions & 8 deletions

File tree

src/EIDEProject.ts

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2396,6 +2396,12 @@ class EIDEProject extends AbstractProject {
23962396
return this.srcRefMap.get(file.path) || [];
23972397
}
23982398

2399+
public getSourceRefsAll(): string[] {
2400+
const allHeaders: string[] = [];
2401+
this.srcRefMap.forEach(v => v.forEach(f => allHeaders.push(f.path)));
2402+
return ArrayDelRepetition(allHeaders);
2403+
}
2404+
23992405
private whitespaceMatcher = /(?<![\\:]) /;
24002406

24012407
private gnu_parseRefLines(lines: string[]): string[] {
@@ -3123,16 +3129,30 @@ class EIDEProject extends AbstractProject {
31233129
}
31243130

31253131
canProvideConfiguration(uri: vscode.Uri, token?: vscode.CancellationToken | undefined): Thenable<boolean> {
3132+
31263133
return new Promise((resolve) => {
3127-
const filePath = platform.realpathSync(uri.fsPath);
3134+
3135+
const realPath = platform.realpathSync(uri.fsPath);
3136+
const lowcasePath = uri.fsPath.toLowerCase();
31283137
const prjRoot = platform.realpathSync(this.GetRootDir().path);
3129-
const allIncPaths = this.cppToolsConfig.includePath;
3130-
resolve(
3131-
filePath.startsWith(prjRoot) || // All source files in current workspace
3132-
allIncPaths.some(p => filePath.startsWith(p)) || // All .h files in IncludePaths
3133-
this.vSourceList.has(filePath) || // All virtual source files
3134-
this.sourceRoots.isIncludes(filePath) // All source files in linked source folders
3135-
);
3138+
const allIncPaths = this.cppToolsConfig.includePath.map(p => File.ToLocalPath(p.toLowerCase()));
3139+
3140+
// filter source files that can provide
3141+
let result: boolean =
3142+
realPath.startsWith(prjRoot) || // All source files in current workspace
3143+
allIncPaths.some(p => lowcasePath.startsWith(p)) || // All files in IncludePaths
3144+
this.vSourceList.has(realPath) || // All virtual source files
3145+
this.sourceRoots.isIncludes(realPath); // All source files in linked source folders
3146+
3147+
// other .h files
3148+
if (!result && AbstractProject.headerFilter.test(lowcasePath)) {
3149+
const allHeaders = this.getSourceRefsAll().map(p => File.ToLocalPath(p.toLowerCase()));
3150+
result = result ||
3151+
allHeaders.some(p => p == lowcasePath) || // All .h files for this project
3152+
lowcasePath.startsWith(this.getToolchain().getToolchainDir().path.toLowerCase()); // All .h files in toolchain dir
3153+
}
3154+
3155+
resolve(result);
31363156
});
31373157
}
31383158

0 commit comments

Comments
 (0)