Skip to content

Commit fe8245f

Browse files
authored
Look for clang-format installed on system before defaulting to bundled version (#4855)
1 parent 419d5c1 commit fe8245f

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

Extension/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1768,6 +1768,7 @@
17681768
"vscode-extension-telemetry": "^0.1.2",
17691769
"vscode-languageclient": "^5.2.1",
17701770
"vscode-nls": "^4.1.1",
1771+
"which": "^2.0.2",
17711772
"yauzl": "^2.10.0"
17721773
},
17731774
"resolutions": {
@@ -1938,4 +1939,4 @@
19381939
"binaries": []
19391940
}
19401941
]
1941-
}
1942+
}

Extension/package.nls.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"c_cpp.command.rescanWorkspace.title": "Rescan Workspace",
1818
"c_cpp.command.vcpkgClipboardInstallSuggested.title": "Copy vcpkg install command to clipboard",
1919
"c_cpp.command.vcpkgOnlineHelpSuggested.title": "Visit the vcpkg help page",
20-
"c_cpp.configuration.clang_format_path.description": "The full path of the clang-format executable.",
20+
"c_cpp.configuration.clang_format_path.description": "The full path of the clang-format executable. If not specified, and clang-format is available in the environment path, that is used. If not found in the environment path, a copy of clang-format bundled with the extension will be used.",
2121
"c_cpp.configuration.clang_format_style.description": "Coding style, currently supports: Visual Studio, LLVM, Google, Chromium, Mozilla, WebKit. Use \"file\" to load the style from a .clang-format file in the current or parent directory. Use {key: value, ...} to set specific parameters. For example, the \"Visual Studio\" style is similar to: { BasedOnStyle: LLVM, UseTab: Never, IndentWidth: 4, TabWidth: 4, BreakBeforeBraces: Allman, AllowShortIfStatementsOnASingleLine: false, IndentCaseLabels: false, ColumnLimit: 0, AccessModifierOffset: -4 }",
2222
"c_cpp.configuration.clang_format_fallbackStyle.description": "Name of the predefined style used as a fallback in case clang-format is invoked with style \"file\" but the .clang-format file is not found. Possible values are Visual Studio, LLVM, Google, Chromium, Mozilla, WebKit, none, or use {key: value, ...} to set specific parameters. For example, the \"Visual Studio\" style is similar to: { BasedOnStyle: LLVM, UseTab: Never, IndentWidth: 4, TabWidth: 4, BreakBeforeBraces: Allman, AllowShortIfStatementsOnASingleLine: false, IndentCaseLabels: false, ColumnLimit: 0, AccessModifierOffset: -4 }",
2323
"c_cpp.configuration.clang_format_sortIncludes.description": "If set, overrides the include sorting behavior determined by the SortIncludes parameter.",

Extension/src/LanguageServer/settings.ts

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

77
import * as vscode from 'vscode';
88
import { CommentPattern } from './languageConfig';
9+
import * as which from 'which';
910

1011
function getTarget(): vscode.ConfigurationTarget {
1112
return (vscode.workspace.workspaceFolders) ? vscode.ConfigurationTarget.WorkspaceFolder : vscode.ConfigurationTarget.Global;
@@ -30,7 +31,14 @@ export class CppSettings extends Settings {
3031
super("C_Cpp", resource);
3132
}
3233

33-
public get clangFormatPath(): string { return super.Section.get<string>("clang_format_path"); }
34+
public get clangFormatPath(): string {
35+
let path: string = super.Section.get<string>("clang_format_path");
36+
if (!path) {
37+
path = which.sync('clang-format', {nothrow: true});
38+
}
39+
return path;
40+
}
41+
3442
public get clangFormatStyle(): string { return super.Section.get<string>("clang_format_style"); }
3543
public get clangFormatFallbackStyle(): string { return super.Section.get<string>("clang_format_fallbackStyle"); }
3644
public get clangFormatSortIncludes(): string { return super.Section.get<string>("clang_format_sortIncludes"); }

Extension/yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5335,7 +5335,7 @@ [email protected], which@^1.2.14, which@^1.2.9, which@^1.3.1:
53355335
dependencies:
53365336
isexe "^2.0.0"
53375337

5338-
which@^2.0.1:
5338+
which@^2.0.1, which@^2.0.2:
53395339
version "2.0.2"
53405340
resolved "https://registry.yarnpkg.com/which/-/which-2.0.2.tgz#7c6a8dd0a636a0327e10b59c9286eee93f3f51b1"
53415341
integrity sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==

0 commit comments

Comments
 (0)