diff options
| author | Haojian Wu <hokein@google.com> | 2019-02-11 15:18:11 +0000 |
|---|---|---|
| committer | Haojian Wu <hokein@google.com> | 2019-02-11 15:18:11 +0000 |
| commit | e64ee7c6458b5125ec898110dd67682770071ca9 (patch) | |
| tree | b7b662bae69063faf3cbc6e387c6cd41418d2621 /clang-tools-extra/clangd/ClangdServer.cpp | |
| parent | 9a857d207598ea7d4bf87a25e58129bb3d438b4e (diff) | |
| download | bcm5719-llvm-e64ee7c6458b5125ec898110dd67682770071ca9.tar.gz bcm5719-llvm-e64ee7c6458b5125ec898110dd67682770071ca9.zip | |
Revamp the "[clangd] Format tweak's replacements"
Summary:
This patch contains two parts:
1) reverts commit r353306.
2) move the format logic out from tweaks, keep tweaks API unchanged.
Reviewers: sammccall, ilya-biryukov
Reviewed By: ilya-biryukov
Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D58051
llvm-svn: 353712
Diffstat (limited to 'clang-tools-extra/clangd/ClangdServer.cpp')
| -rw-r--r-- | clang-tools-extra/clangd/ClangdServer.cpp | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp index 1aa87998181..11e3d2c002f 100644 --- a/clang-tools-extra/clangd/ClangdServer.cpp +++ b/clang-tools-extra/clangd/ClangdServer.cpp @@ -152,9 +152,6 @@ void ClangdServer::addDocument(PathRef File, llvm::StringRef Contents, Opts.ClangTidyOpts = tidy::ClangTidyOptions::getDefaults(); if (ClangTidyOptProvider) Opts.ClangTidyOpts = ClangTidyOptProvider->getOptions(File); - // FIXME: cache this. - Opts.Style = - getFormatStyleForFile(File, Contents, FSProvider.getFileSystem().get()); Opts.SuggestMissingIncludes = SuggestMissingIncludes; // FIXME: some build systems like Bazel will take time to preparing // environment to build the file, it would be nice if we could emit a @@ -365,8 +362,9 @@ void ClangdServer::enumerateTweaks(PathRef File, Range Sel, void ClangdServer::applyTweak(PathRef File, Range Sel, StringRef TweakID, Callback<tooling::Replacements> CB) { - auto Action = [Sel](decltype(CB) CB, std::string File, std::string TweakID, - Expected<InputsAndAST> InpAST) { + auto Action = [Sel, this](decltype(CB) CB, std::string File, + std::string TweakID, + Expected<InputsAndAST> InpAST) { if (!InpAST) return CB(InpAST.takeError()); auto Selection = tweakSelection(Sel, *InpAST); @@ -375,7 +373,15 @@ void ClangdServer::applyTweak(PathRef File, Range Sel, StringRef TweakID, auto A = prepareTweak(TweakID, *Selection); if (!A) return CB(A.takeError()); - return CB((*A)->apply(*Selection, InpAST->Inputs.Opts.Style)); + auto RawReplacements = (*A)->apply(*Selection); + if (!RawReplacements) + return CB(RawReplacements.takeError()); + // FIXME: this function has I/O operations (find .clang-format file), figure + // out a way to cache the format style. + auto Style = getFormatStyleForFile(File, InpAST->Inputs.Contents, + InpAST->Inputs.FS.get()); + return CB( + cleanupAndFormat(InpAST->Inputs.Contents, *RawReplacements, Style)); }; WorkScheduler.runWithAST( "ApplyTweak", File, |

