Skip to content
Merged
Changes from all commits
Commits
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
24 changes: 9 additions & 15 deletions Extension/src/LanguageServer/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ export class CppSettings extends Settings {
if (cachedClangPath !== undefined) {
return cachedClangPath;
}
const clangStr: string = isFormat ? this.clangFormatStr : this.clangTidyStr;
const clangName: string = isFormat ? this.clangFormatName : this.clangTidyName;
const setCachedClangPath: (path: string) => void = isFormat ? setCachedClangFormatPath : setCachedClangTidyPath;
const whichPath: string | null = which.sync(clangName, { nothrow: true });
Expand All @@ -290,29 +289,24 @@ export class CppSettings extends Settings {
return undefined;
} else {
// Attempt to invoke both our own version of clang-* to see if we can successfully execute it, and to get its version.
let clangVersion: string;
let bundledVersion: string;
try {
const exePath: string = getExtensionFilePath(`./LLVM/bin/${clangName}`);
const output: string[] = execSync(quote([exePath, '--version'])).toString().split(" ");
if (output.length < 3 || output[0] !== clangStr || output[1] !== "version" || !semver.valid(output[2])) {
if (output.length === 3) {
return path;
}
const versionIndex: number = output.findIndex((value: string) => value === "version");
if (versionIndex < 0 || versionIndex + 1 >= output.length || !semver.valid(output[versionIndex + 1].trim())) {
return path;
}
const bundledPath: string = getExtensionFilePath(`./LLVM/bin/${clangName}`);
const output: string = execSync(quote([bundledPath, '--version'])).toString();
bundledVersion = output.match(/(\d+\.\d+\.\d+)/)?.[1] ?? "";
if (!semver.valid(bundledVersion)) {
return path;
}
clangVersion = output[2];
} catch (e) {
// Unable to invoke our own clang-*. Use the system installed clang-*.
return path;
}

// Invoke the version on the system to compare versions. Use ours if it's more recent.
try {
const output: string[] = execSync(`"${path}" --version`).toString().split(" ");
if (output.length < 3 || output[0] !== clangStr || output[1] !== "version" || semver.ltr(output[2], clangVersion)) {
const output: string = execSync(`"${path}" --version`).toString();
const userVersion = output.match(/(\d+\.\d+\.\d+)/)?.[1] ?? "";
if (semver.ltr(userVersion, bundledVersion)) {
path = "";
setCachedClangPath(path);
}
Expand Down
Loading