Skip to content

Commit ab55557

Browse files
authored
Cache call to which.sync('clang-format') (#6645)
1 parent c70dc9e commit ab55557

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Extension/src/LanguageServer/settings.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import * as vscode from 'vscode';
88
import { CommentPattern } from './languageConfig';
9-
import { getExtensionFilePath } from '../common';
9+
import { getExtensionFilePath, getCachedClangFormatPath, setCachedClangFormatPath } from '../common';
1010
import * as os from 'os';
1111
import * as which from 'which';
1212
import { execSync } from 'child_process';
@@ -74,7 +74,15 @@ export class CppSettings extends Settings {
7474
public get clangFormatPath(): string | undefined {
7575
let path: string | undefined | null = super.Section.get<string>("clang_format_path");
7676
if (!path) {
77+
const cachedClangFormatPath: string | null | undefined = getCachedClangFormatPath();
78+
if (cachedClangFormatPath !== undefined) {
79+
if (cachedClangFormatPath === null) {
80+
return undefined;
81+
}
82+
return cachedClangFormatPath;
83+
}
7784
path = which.sync('clang-format', { nothrow: true });
85+
setCachedClangFormatPath(path);
7886
if (!path) {
7987
return undefined;
8088
} else {

Extension/src/common.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ export function setExtensionPath(path: string): void {
4545
extensionPath = path;
4646
}
4747

48+
let cachedClangFormatPath: string | null | undefined;
49+
export function getCachedClangFormatPath(): string | null | undefined {
50+
return cachedClangFormatPath;
51+
}
52+
export function setCachedClangFormatPath(path: string | null): void {
53+
cachedClangFormatPath = path;
54+
}
55+
4856
// Use this package.json to read values
4957
export const packageJson: any = vscode.extensions.getExtension("ms-vscode.cpptools")?.packageJSON;
5058

0 commit comments

Comments
 (0)