mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-26 01:21:57 +00:00
Manage Expected in formatting APIs
This commit is contained in:
parent
05e9bf3966
commit
4fdc81ae6d
@ -1,5 +1,7 @@
|
|||||||
#include "clang_format.h"
|
#include "clang_format.h"
|
||||||
|
|
||||||
|
#include <loguru.hpp>
|
||||||
|
|
||||||
using namespace clang::format;
|
using namespace clang::format;
|
||||||
using namespace clang::tooling;
|
using namespace clang::tooling;
|
||||||
|
|
||||||
@ -27,12 +29,18 @@ std::vector<Replacement> ClangFormat::FormatWholeDocument() {
|
|||||||
const auto language_kind = getLanguageKindFromFilename(document_filename_);
|
const auto language_kind = getLanguageKindFromFilename(document_filename_);
|
||||||
FormatStyle predefined_style;
|
FormatStyle predefined_style;
|
||||||
getPredefinedStyle("chromium", language_kind, &predefined_style);
|
getPredefinedStyle("chromium", language_kind, &predefined_style);
|
||||||
auto style = getStyle("file", document_filename_, "chromium");
|
llvm::Expected<FormatStyle> style =
|
||||||
if (style == predefined_style) {
|
getStyle("file", document_filename_, "chromium");
|
||||||
style.UseTab = insert_spaces_ ? FormatStyle::UseTabStyle::UT_Never
|
if (!style) {
|
||||||
: FormatStyle::UseTabStyle::UT_Always;
|
LOG_S(ERROR) << llvm::toString(style.takeError());
|
||||||
style.IndentWidth = tab_size_;
|
return {};
|
||||||
}
|
}
|
||||||
auto format_result = reformat(style, document_, ranges_, document_filename_);
|
|
||||||
|
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());
|
return std::vector<Replacement>(format_result.begin(), format_result.end());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user