mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-22 23:55:08 +00:00
Implement .clang-format style management
If we can't find a .clang-format file for the given file, default to Chromium style with the tab/spaces configuration that was provided by the client.
This commit is contained in:
parent
19341c18cd
commit
aa4e5e7e5b
@ -15,12 +15,24 @@ ClangFormat::ClangFormat(llvm::StringRef document_filename,
|
||||
insert_spaces_(insert_spaces) {}
|
||||
ClangFormat::~ClangFormat(){};
|
||||
|
||||
static FormatStyle::LanguageKind getLanguageKindFromFilename(
|
||||
llvm::StringRef filename) {
|
||||
if (filename.endswith(".m") || filename.endswith(".mm")) {
|
||||
return FormatStyle::LK_ObjC;
|
||||
}
|
||||
return FormatStyle::LK_Cpp;
|
||||
}
|
||||
|
||||
std::vector<Replacement> ClangFormat::FormatWholeDocument() {
|
||||
// TODO: Construct a valid style.
|
||||
FormatStyle style = getChromiumStyle(FormatStyle::LK_Cpp);
|
||||
const auto language_kind = getLanguageKindFromFilename(document_filename_);
|
||||
FormatStyle predefined_style;
|
||||
getPredefinedStyle("chromium", language_kind, &predefined_style);
|
||||
auto style = getStyle("file", document_filename_, "chromium");
|
||||
if (style == predefined_style) {
|
||||
style.UseTab = insert_spaces_ ? FormatStyle::UseTabStyle::UT_Never
|
||||
: FormatStyle::UseTabStyle::UT_Always;
|
||||
style.IndentWidth = tab_size_;
|
||||
}
|
||||
auto format_result = reformat(style, document_, ranges_, document_filename_);
|
||||
return std::vector<Replacement>(format_result.begin(), format_result.end());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user