Skip to content

Commit 2a0423c

Browse files
committed
PR feedback
1 parent b88228f commit 2a0423c

File tree

1 file changed

+36
-21
lines changed

1 file changed

+36
-21
lines changed

Extension/src/LanguageServer/configurations.ts

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ export class CppProperties {
286286

287287
vscode.workspace.onDidOpenTextDocument(document => {
288288
if (document.uri.fsPath === settingsPath) {
289-
this.handleSquiggles(document);
289+
this.handleSquiggles();
290290
}
291291
});
292292

@@ -1731,13 +1731,8 @@ export class CppProperties {
17311731
* @returns The result of the operation and the time it took to complete in seconds.
17321732
*/
17331733
private async timeOperation<T>(operation: () => Promise<T | undefined>): Promise<{ result: T | undefined; duration: number }> {
1734-
let result: T | undefined;
17351734
const start = process.hrtime();
1736-
try {
1737-
result = await operation();
1738-
} catch {
1739-
// Suppress errors
1740-
}
1735+
const result = await operation();
17411736
const diff = process.hrtime(start);
17421737
const duration = diff[0] + diff[1] / 1e9; // diff[0] is in seconds, diff[1] is in nanoseconds
17431738
return { result, duration };
@@ -1762,8 +1757,12 @@ export class CppProperties {
17621757
errors.compilerPath = compilerPathAndArgs.error;
17631758

17641759
// Validate paths (directories)
1765-
const { result, duration } = await this.timeOperation(() => this.validatePath(config.includePath, { globPaths: true }));
1766-
errors.includePath = result ?? duration >= 10 ? localize('resolve.includePath.took.too.long', "The include path validation took {0}s to evaluate", duration) : undefined;
1760+
try {
1761+
const { result, duration } = await this.timeOperation(() => this.validatePath(config.includePath, { globPaths: true }));
1762+
errors.includePath = result ?? duration >= 10 ? localize('resolve.includePath.took.too.long', "The include path validation took {0}s to evaluate", duration) : undefined;
1763+
} catch (e) {
1764+
errors.includePath = localize('resolve.includePath.failed', "Failed to resolve include path. Error: {0}", (e as Error).message);
1765+
}
17671766
errors.macFrameworkPath = await this.validatePath(config.macFrameworkPath);
17681767
errors.browsePath = await this.validatePath(config.browse ? config.browse.path : undefined);
17691768

@@ -1870,9 +1869,11 @@ export class CppProperties {
18701869
private handleSquigglesDeferral: Deferral | undefined;
18711870

18721871
private handleSquiggles(doc?: vscode.TextDocument): void {
1873-
// When the active config changes, we don't pass the doc in since the version would not have changed.
1872+
// When we open the doc or the active config changes, we don't pass the doc in since we always want to process squiggles.
18741873
if (doc?.version !== this.lastConfigurationVersion) {
18751874
this.lastConfigurationVersion = doc?.version ?? 0;
1875+
1876+
// Debounce the squiggles requests.
18761877
this.handleSquigglesDeferral?.cancel();
18771878
this.handleSquigglesDeferral = new Deferral(() => void this.handleSquigglesImpl().catch(logAndReturn.undefined), 1000);
18781879
}
@@ -2132,18 +2133,32 @@ export class CppProperties {
21322133
// and extend that pattern to the next quote before and next quote after it.
21332134
const pattern: RegExp = new RegExp(`"[^"]*?(?<="|;)${escapedPath}(?="|;).*?"`, "g");
21342135
const configMatches: string[] | null = curText.match(pattern);
2136+
let expandedPaths: string[];
21352137

2136-
const { result, duration } = await this.timeOperation(() => this.resolveAndSplit([curPath], undefined, this.ExtendedEnvironment, true, true));
2137-
const expandedPaths: string[] = result ?? [];
2138-
if (duration > 10 && configMatches) {
2139-
newSquiggleMetrics.SlowPathResolution++;
2140-
const curOffset = curText.indexOf(configMatches[0]);
2141-
const endOffset = curOffset + curPath.length;
2142-
const diagnostic: vscode.Diagnostic = new vscode.Diagnostic(
2143-
new vscode.Range(document.positionAt(curTextStartOffset + curOffset), document.positionAt(curTextStartOffset + endOffset)),
2144-
localize('resolve.path.took.too.long', "Path took {0}s to evaluate", duration),
2145-
vscode.DiagnosticSeverity.Warning);
2146-
diagnostics.push(diagnostic);
2138+
try {
2139+
const { result, duration } = await this.timeOperation(() => this.resolveAndSplit([curPath], undefined, this.ExtendedEnvironment, true, true));
2140+
expandedPaths = result ?? [];
2141+
if (duration > 10 && configMatches) {
2142+
newSquiggleMetrics.SlowPathResolution++;
2143+
const curOffset = curText.indexOf(configMatches[0]);
2144+
const endOffset = curOffset + curPath.length;
2145+
const diagnostic: vscode.Diagnostic = new vscode.Diagnostic(
2146+
new vscode.Range(document.positionAt(curTextStartOffset + curOffset), document.positionAt(curTextStartOffset + endOffset)),
2147+
localize('resolve.path.took.too.long', "Path took {0}s to evaluate", duration),
2148+
vscode.DiagnosticSeverity.Warning);
2149+
diagnostics.push(diagnostic);
2150+
}
2151+
} catch (e) {
2152+
expandedPaths = [];
2153+
if (configMatches) {
2154+
const curOffset = curText.indexOf(configMatches[0]);
2155+
const endOffset = curOffset + curPath.length;
2156+
const diagnostic: vscode.Diagnostic = new vscode.Diagnostic(
2157+
new vscode.Range(document.positionAt(curTextStartOffset + curOffset), document.positionAt(curTextStartOffset + endOffset)),
2158+
localize('resolve.path.failed', "Failed to resolve path {0}. Error: {1}", curPath, (e as Error).message),
2159+
vscode.DiagnosticSeverity.Warning);
2160+
diagnostics.push(diagnostic);
2161+
}
21472162
}
21482163
const incorrectExpandedPaths: string[] = [];
21492164

0 commit comments

Comments
 (0)