Ilya Biryukov | 38d7977 | 2017-05-16 09:38:59 +0000 | [diff] [blame] | 1 | //===--- ClangdServer.cpp - Main clangd server code --------------*- C++-*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===-------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "ClangdServer.h" |
Sam McCall | a66d2cb | 2017-12-19 17:06:07 +0000 | [diff] [blame] | 11 | #include "CodeComplete.h" |
Eric Liu | c5105f9 | 2018-02-16 14:15:55 +0000 | [diff] [blame] | 12 | #include "Headers.h" |
Sam McCall | b536a2a | 2017-12-19 12:23:48 +0000 | [diff] [blame] | 13 | #include "SourceCode.h" |
Sam McCall | a66d2cb | 2017-12-19 17:06:07 +0000 | [diff] [blame] | 14 | #include "XRefs.h" |
Sam McCall | 0faecf0 | 2018-01-15 12:33:00 +0000 | [diff] [blame] | 15 | #include "index/Merge.h" |
Ilya Biryukov | afb5554 | 2017-05-16 14:40:30 +0000 | [diff] [blame] | 16 | #include "clang/Format/Format.h" |
Ilya Biryukov | 38d7977 | 2017-05-16 09:38:59 +0000 | [diff] [blame] | 17 | #include "clang/Frontend/CompilerInstance.h" |
| 18 | #include "clang/Frontend/CompilerInvocation.h" |
| 19 | #include "clang/Tooling/CompilationDatabase.h" |
Ilya Biryukov | 9e11c4c | 2017-11-15 18:04:56 +0000 | [diff] [blame] | 20 | #include "clang/Tooling/Refactoring/RefactoringResultConsumer.h" |
| 21 | #include "clang/Tooling/Refactoring/Rename/RenamingAction.h" |
Ilya Biryukov | afb5554 | 2017-05-16 14:40:30 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/ArrayRef.h" |
Sam McCall | b5f5eb6 | 2018-01-25 17:01:39 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/ScopeExit.h" |
Benjamin Kramer | ee19f16 | 2017-10-26 12:28:13 +0000 | [diff] [blame] | 24 | #include "llvm/Support/Errc.h" |
Ilya Biryukov | 38d7977 | 2017-05-16 09:38:59 +0000 | [diff] [blame] | 25 | #include "llvm/Support/FileSystem.h" |
Marc-Andre Laperle | 37de971 | 2017-09-27 15:31:17 +0000 | [diff] [blame] | 26 | #include "llvm/Support/Path.h" |
Ilya Biryukov | f01af68 | 2017-05-23 13:42:59 +0000 | [diff] [blame] | 27 | #include "llvm/Support/raw_ostream.h" |
| 28 | #include <future> |
Ilya Biryukov | 38d7977 | 2017-05-16 09:38:59 +0000 | [diff] [blame] | 29 | |
Ilya Biryukov | 2f31410 | 2017-05-16 10:06:20 +0000 | [diff] [blame] | 30 | using namespace clang; |
Ilya Biryukov | 38d7977 | 2017-05-16 09:38:59 +0000 | [diff] [blame] | 31 | using namespace clang::clangd; |
| 32 | |
Ilya Biryukov | afb5554 | 2017-05-16 14:40:30 +0000 | [diff] [blame] | 33 | namespace { |
| 34 | |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 35 | void ignoreError(llvm::Error Err) { |
| 36 | handleAllErrors(std::move(Err), [](const llvm::ErrorInfoBase &) {}); |
| 37 | } |
| 38 | |
Ilya Biryukov | a46f7a9 | 2017-06-28 10:34:50 +0000 | [diff] [blame] | 39 | std::string getStandardResourceDir() { |
| 40 | static int Dummy; // Just an address in this process. |
| 41 | return CompilerInvocation::GetResourcesPath("clangd", (void *)&Dummy); |
| 42 | } |
| 43 | |
Haojian Wu | 345099c | 2017-11-09 11:30:04 +0000 | [diff] [blame] | 44 | class RefactoringResultCollector final |
| 45 | : public tooling::RefactoringResultConsumer { |
| 46 | public: |
| 47 | void handleError(llvm::Error Err) override { |
| 48 | assert(!Result.hasValue()); |
| 49 | // FIXME: figure out a way to return better message for DiagnosticError. |
| 50 | // clangd uses llvm::toString to convert the Err to string, however, for |
| 51 | // DiagnosticError, only "clang diagnostic" will be generated. |
| 52 | Result = std::move(Err); |
| 53 | } |
| 54 | |
| 55 | // Using the handle(SymbolOccurrences) from parent class. |
| 56 | using tooling::RefactoringResultConsumer::handle; |
| 57 | |
| 58 | void handle(tooling::AtomicChanges SourceReplacements) override { |
| 59 | assert(!Result.hasValue()); |
| 60 | Result = std::move(SourceReplacements); |
| 61 | } |
| 62 | |
| 63 | Optional<Expected<tooling::AtomicChanges>> Result; |
| 64 | }; |
| 65 | |
Ilya Biryukov | afb5554 | 2017-05-16 14:40:30 +0000 | [diff] [blame] | 66 | } // namespace |
| 67 | |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 68 | IntrusiveRefCntPtr<vfs::FileSystem> RealFileSystemProvider::getFileSystem() { |
| 69 | return vfs::getRealFileSystem(); |
Ilya Biryukov | 0f62ed2 | 2017-05-26 12:26:51 +0000 | [diff] [blame] | 70 | } |
| 71 | |
Sam McCall | 7363a2f | 2018-03-05 17:28:54 +0000 | [diff] [blame] | 72 | ClangdServer::Options ClangdServer::optsForTest() { |
| 73 | ClangdServer::Options Opts; |
| 74 | Opts.UpdateDebounce = std::chrono::steady_clock::duration::zero(); // Faster! |
| 75 | Opts.StorePreamblesInMemory = true; |
| 76 | Opts.AsyncThreadsCount = 4; // Consistent! |
| 77 | return Opts; |
| 78 | } |
| 79 | |
Sam McCall | adccab6 | 2017-11-23 16:58:22 +0000 | [diff] [blame] | 80 | ClangdServer::ClangdServer(GlobalCompilationDatabase &CDB, |
Sam McCall | adccab6 | 2017-11-23 16:58:22 +0000 | [diff] [blame] | 81 | FileSystemProvider &FSProvider, |
Sam McCall | 7363a2f | 2018-03-05 17:28:54 +0000 | [diff] [blame] | 82 | DiagnosticsConsumer &DiagConsumer, |
| 83 | const Options &Opts) |
| 84 | : CompileArgs(CDB, Opts.ResourceDir ? Opts.ResourceDir->str() |
| 85 | : getStandardResourceDir()), |
Ilya Biryukov | 929697b | 2018-01-25 14:19:21 +0000 | [diff] [blame] | 86 | DiagConsumer(DiagConsumer), FSProvider(FSProvider), |
Sam McCall | 7363a2f | 2018-03-05 17:28:54 +0000 | [diff] [blame] | 87 | FileIdx(Opts.BuildDynamicSymbolIndex ? new FileIndex() : nullptr), |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 88 | PCHs(std::make_shared<PCHContainerOperations>()), |
| 89 | // Pass a callback into `WorkScheduler` to extract symbols from a newly |
| 90 | // parsed file and rebuild the file index synchronously each time an AST |
| 91 | // is parsed. |
Eric Liu | bfac8f7 | 2017-12-19 18:00:37 +0000 | [diff] [blame] | 92 | // FIXME(ioeric): this can be slow and we may be able to index on less |
| 93 | // critical paths. |
Sam McCall | 7363a2f | 2018-03-05 17:28:54 +0000 | [diff] [blame] | 94 | WorkScheduler(Opts.AsyncThreadsCount, Opts.StorePreamblesInMemory, |
Sam McCall | d1a7a37 | 2018-01-31 13:40:48 +0000 | [diff] [blame] | 95 | FileIdx |
| 96 | ? [this](PathRef Path, |
| 97 | ParsedAST *AST) { FileIdx->update(Path, AST); } |
Sam McCall | d1e0deb | 2018-03-02 08:56:37 +0000 | [diff] [blame] | 98 | : ASTParsedCallback(), |
Sam McCall | 7363a2f | 2018-03-05 17:28:54 +0000 | [diff] [blame] | 99 | Opts.UpdateDebounce) { |
| 100 | if (FileIdx && Opts.StaticIndex) { |
| 101 | MergedIndex = mergeIndex(FileIdx.get(), Opts.StaticIndex); |
Sam McCall | 0faecf0 | 2018-01-15 12:33:00 +0000 | [diff] [blame] | 102 | Index = MergedIndex.get(); |
| 103 | } else if (FileIdx) |
| 104 | Index = FileIdx.get(); |
Sam McCall | 7363a2f | 2018-03-05 17:28:54 +0000 | [diff] [blame] | 105 | else if (Opts.StaticIndex) |
| 106 | Index = Opts.StaticIndex; |
Sam McCall | 0faecf0 | 2018-01-15 12:33:00 +0000 | [diff] [blame] | 107 | else |
| 108 | Index = nullptr; |
| 109 | } |
Ilya Biryukov | 38d7977 | 2017-05-16 09:38:59 +0000 | [diff] [blame] | 110 | |
Marc-Andre Laperle | 37de971 | 2017-09-27 15:31:17 +0000 | [diff] [blame] | 111 | void ClangdServer::setRootPath(PathRef RootPath) { |
| 112 | std::string NewRootPath = llvm::sys::path::convert_to_slash( |
| 113 | RootPath, llvm::sys::path::Style::posix); |
| 114 | if (llvm::sys::fs::is_directory(NewRootPath)) |
| 115 | this->RootPath = NewRootPath; |
| 116 | } |
| 117 | |
Sam McCall | 568e17f | 2018-02-22 13:11:12 +0000 | [diff] [blame] | 118 | void ClangdServer::addDocument(PathRef File, StringRef Contents, |
Ilya Biryukov | bec5df2 | 2018-03-14 17:08:41 +0000 | [diff] [blame] | 119 | WantDiagnostics WantDiags, bool SkipCache) { |
| 120 | if (SkipCache) |
| 121 | CompileArgs.invalidate(File); |
| 122 | |
Ilya Biryukov | f01af68 | 2017-05-23 13:42:59 +0000 | [diff] [blame] | 123 | DocVersion Version = DraftMgr.updateDraft(File, Contents); |
Ilya Biryukov | bec5df2 | 2018-03-14 17:08:41 +0000 | [diff] [blame] | 124 | ParseInputs Inputs = {CompileArgs.getCompileCommand(File), |
| 125 | FSProvider.getFileSystem(), Contents.str()}; |
| 126 | |
| 127 | Path FileStr = File.str(); |
| 128 | WorkScheduler.update(File, std::move(Inputs), WantDiags, |
| 129 | [this, FileStr, Version](std::vector<Diag> Diags) { |
| 130 | consumeDiagnostics(FileStr, Version, std::move(Diags)); |
| 131 | }); |
Ilya Biryukov | 38d7977 | 2017-05-16 09:38:59 +0000 | [diff] [blame] | 132 | } |
| 133 | |
Ilya Biryukov | 7e5ee26 | 2018-02-08 07:37:35 +0000 | [diff] [blame] | 134 | void ClangdServer::removeDocument(PathRef File) { |
Ilya Biryukov | c5ad35f | 2017-08-14 08:17:24 +0000 | [diff] [blame] | 135 | DraftMgr.removeDraft(File); |
Ilya Biryukov | 929697b | 2018-01-25 14:19:21 +0000 | [diff] [blame] | 136 | CompileArgs.invalidate(File); |
Ilya Biryukov | 7e5ee26 | 2018-02-08 07:37:35 +0000 | [diff] [blame] | 137 | WorkScheduler.remove(File); |
Ilya Biryukov | 38d7977 | 2017-05-16 09:38:59 +0000 | [diff] [blame] | 138 | } |
| 139 | |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 140 | void ClangdServer::codeComplete(PathRef File, Position Pos, |
| 141 | const clangd::CodeCompleteOptions &Opts, |
| 142 | Callback<CompletionList> CB) { |
Ilya Biryukov | d3b04e3 | 2017-12-05 10:42:57 +0000 | [diff] [blame] | 143 | // Copy completion options for passing them to async task handler. |
| 144 | auto CodeCompleteOpts = Opts; |
Sam McCall | 0faecf0 | 2018-01-15 12:33:00 +0000 | [diff] [blame] | 145 | if (!CodeCompleteOpts.Index) // Respect overridden index. |
| 146 | CodeCompleteOpts.Index = Index; |
Ilya Biryukov | f6e2b4c | 2018-01-09 14:39:27 +0000 | [diff] [blame] | 147 | |
Sam McCall | db3ea4c | 2018-02-27 17:15:50 +0000 | [diff] [blame] | 148 | VersionedDraft Latest = DraftMgr.getDraft(File); |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 149 | if (!Latest.Draft) |
| 150 | return CB(llvm::make_error<llvm::StringError>( |
| 151 | "codeComplete called for non-added document", |
| 152 | llvm::errc::invalid_argument)); |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 153 | |
Ilya Biryukov | f6e2b4c | 2018-01-09 14:39:27 +0000 | [diff] [blame] | 154 | // Copy PCHs to avoid accessing this->PCHs concurrently |
| 155 | std::shared_ptr<PCHContainerOperations> PCHs = this->PCHs; |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 156 | auto FS = FSProvider.getFileSystem(); |
Simon Marchi | 5a48cf8 | 2018-03-14 18:31:48 +0000 | [diff] [blame^] | 157 | auto Task = [PCHs, Pos, FS, |
| 158 | CodeCompleteOpts](Path File, Callback<CompletionList> CB, |
| 159 | llvm::Expected<InputsAndPreamble> IP) { |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 160 | assert(IP && "error when trying to read preamble for codeComplete"); |
| 161 | auto PreambleData = IP->Preamble; |
Ilya Biryukov | dcd2169 | 2017-10-05 17:04:13 +0000 | [diff] [blame] | 162 | |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 163 | // FIXME(ibiryukov): even if Preamble is non-null, we may want to check |
| 164 | // both the old and the new version in case only one of them matches. |
| 165 | CompletionList Result = clangd::codeComplete( |
Ilya Biryukov | f1f3d57 | 2018-03-14 17:46:52 +0000 | [diff] [blame] | 166 | File, IP->Command, PreambleData ? &PreambleData->Preamble : nullptr, |
Simon Marchi | 5a48cf8 | 2018-03-14 18:31:48 +0000 | [diff] [blame^] | 167 | IP->Contents, Pos, FS, PCHs, CodeCompleteOpts); |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 168 | CB(std::move(Result)); |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 169 | }; |
| 170 | |
Simon Marchi | 5a48cf8 | 2018-03-14 18:31:48 +0000 | [diff] [blame^] | 171 | WorkScheduler.runWithPreamble("CodeComplete", File, |
| 172 | Bind(Task, File.str(), std::move(CB))); |
Ilya Biryukov | 38d7977 | 2017-05-16 09:38:59 +0000 | [diff] [blame] | 173 | } |
Ilya Biryukov | f01af68 | 2017-05-23 13:42:59 +0000 | [diff] [blame] | 174 | |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 175 | void ClangdServer::signatureHelp(PathRef File, Position Pos, |
| 176 | Callback<SignatureHelp> CB) { |
Sam McCall | db3ea4c | 2018-02-27 17:15:50 +0000 | [diff] [blame] | 177 | VersionedDraft Latest = DraftMgr.getDraft(File); |
| 178 | if (!Latest.Draft) |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 179 | return CB(llvm::make_error<llvm::StringError>( |
Sam McCall | db3ea4c | 2018-02-27 17:15:50 +0000 | [diff] [blame] | 180 | "signatureHelp is called for non-added document", |
| 181 | llvm::errc::invalid_argument)); |
Ilya Biryukov | d9bdfe0 | 2017-10-06 11:54:17 +0000 | [diff] [blame] | 182 | |
Ilya Biryukov | 2c5e8e8 | 2018-02-15 13:15:47 +0000 | [diff] [blame] | 183 | auto PCHs = this->PCHs; |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 184 | auto FS = FSProvider.getFileSystem(); |
Simon Marchi | 5a48cf8 | 2018-03-14 18:31:48 +0000 | [diff] [blame^] | 185 | auto Action = [Pos, FS, PCHs](Path File, Callback<SignatureHelp> CB, |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 186 | llvm::Expected<InputsAndPreamble> IP) { |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 187 | if (!IP) |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 188 | return CB(IP.takeError()); |
Ilya Biryukov | 2c5e8e8 | 2018-02-15 13:15:47 +0000 | [diff] [blame] | 189 | |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 190 | auto PreambleData = IP->Preamble; |
Ilya Biryukov | f1f3d57 | 2018-03-14 17:46:52 +0000 | [diff] [blame] | 191 | CB(clangd::signatureHelp(File, IP->Command, |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 192 | PreambleData ? &PreambleData->Preamble : nullptr, |
Simon Marchi | 5a48cf8 | 2018-03-14 18:31:48 +0000 | [diff] [blame^] | 193 | IP->Contents, Pos, FS, PCHs)); |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 194 | }; |
Ilya Biryukov | 2c5e8e8 | 2018-02-15 13:15:47 +0000 | [diff] [blame] | 195 | |
Simon Marchi | 5a48cf8 | 2018-03-14 18:31:48 +0000 | [diff] [blame^] | 196 | WorkScheduler.runWithPreamble("SignatureHelp", File, |
| 197 | Bind(Action, File.str(), std::move(CB))); |
Ilya Biryukov | d9bdfe0 | 2017-10-06 11:54:17 +0000 | [diff] [blame] | 198 | } |
| 199 | |
Raoul Wols | 212bcf8 | 2017-12-12 20:25:06 +0000 | [diff] [blame] | 200 | llvm::Expected<tooling::Replacements> |
| 201 | ClangdServer::formatRange(StringRef Code, PathRef File, Range Rng) { |
Ilya Biryukov | afb5554 | 2017-05-16 14:40:30 +0000 | [diff] [blame] | 202 | size_t Begin = positionToOffset(Code, Rng.start); |
| 203 | size_t Len = positionToOffset(Code, Rng.end) - Begin; |
| 204 | return formatCode(Code, File, {tooling::Range(Begin, Len)}); |
| 205 | } |
| 206 | |
Raoul Wols | 212bcf8 | 2017-12-12 20:25:06 +0000 | [diff] [blame] | 207 | llvm::Expected<tooling::Replacements> ClangdServer::formatFile(StringRef Code, |
| 208 | PathRef File) { |
Ilya Biryukov | afb5554 | 2017-05-16 14:40:30 +0000 | [diff] [blame] | 209 | // Format everything. |
Ilya Biryukov | afb5554 | 2017-05-16 14:40:30 +0000 | [diff] [blame] | 210 | return formatCode(Code, File, {tooling::Range(0, Code.size())}); |
| 211 | } |
| 212 | |
Raoul Wols | 212bcf8 | 2017-12-12 20:25:06 +0000 | [diff] [blame] | 213 | llvm::Expected<tooling::Replacements> |
| 214 | ClangdServer::formatOnType(StringRef Code, PathRef File, Position Pos) { |
Ilya Biryukov | afb5554 | 2017-05-16 14:40:30 +0000 | [diff] [blame] | 215 | // Look for the previous opening brace from the character position and |
| 216 | // format starting from there. |
Ilya Biryukov | afb5554 | 2017-05-16 14:40:30 +0000 | [diff] [blame] | 217 | size_t CursorPos = positionToOffset(Code, Pos); |
| 218 | size_t PreviousLBracePos = StringRef(Code).find_last_of('{', CursorPos); |
| 219 | if (PreviousLBracePos == StringRef::npos) |
| 220 | PreviousLBracePos = CursorPos; |
Sam McCall | b536a2a | 2017-12-19 12:23:48 +0000 | [diff] [blame] | 221 | size_t Len = CursorPos - PreviousLBracePos; |
Ilya Biryukov | afb5554 | 2017-05-16 14:40:30 +0000 | [diff] [blame] | 222 | |
| 223 | return formatCode(Code, File, {tooling::Range(PreviousLBracePos, Len)}); |
| 224 | } |
Ilya Biryukov | 38d7977 | 2017-05-16 09:38:59 +0000 | [diff] [blame] | 225 | |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 226 | void ClangdServer::rename(PathRef File, Position Pos, llvm::StringRef NewName, |
| 227 | Callback<std::vector<tooling::Replacement>> CB) { |
Ilya Biryukov | 2c5e8e8 | 2018-02-15 13:15:47 +0000 | [diff] [blame] | 228 | auto Action = [Pos](Path File, std::string NewName, |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 229 | Callback<std::vector<tooling::Replacement>> CB, |
Ilya Biryukov | 2c5e8e8 | 2018-02-15 13:15:47 +0000 | [diff] [blame] | 230 | Expected<InputsAndAST> InpAST) { |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 231 | if (!InpAST) |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 232 | return CB(InpAST.takeError()); |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 233 | auto &AST = InpAST->AST; |
| 234 | |
| 235 | RefactoringResultCollector ResultCollector; |
| 236 | const SourceManager &SourceMgr = AST.getASTContext().getSourceManager(); |
Haojian Wu | 345099c | 2017-11-09 11:30:04 +0000 | [diff] [blame] | 237 | const FileEntry *FE = |
| 238 | SourceMgr.getFileEntryForID(SourceMgr.getMainFileID()); |
| 239 | if (!FE) |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 240 | return CB(llvm::make_error<llvm::StringError>( |
Ilya Biryukov | 2c5e8e8 | 2018-02-15 13:15:47 +0000 | [diff] [blame] | 241 | "rename called for non-added document", |
| 242 | llvm::errc::invalid_argument)); |
Haojian Wu | 345099c | 2017-11-09 11:30:04 +0000 | [diff] [blame] | 243 | SourceLocation SourceLocationBeg = |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 244 | clangd::getBeginningOfIdentifier(AST, Pos, FE); |
Haojian Wu | 345099c | 2017-11-09 11:30:04 +0000 | [diff] [blame] | 245 | tooling::RefactoringRuleContext Context( |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 246 | AST.getASTContext().getSourceManager()); |
| 247 | Context.setASTContext(AST.getASTContext()); |
Haojian Wu | 345099c | 2017-11-09 11:30:04 +0000 | [diff] [blame] | 248 | auto Rename = clang::tooling::RenameOccurrences::initiate( |
Ilya Biryukov | 2c5e8e8 | 2018-02-15 13:15:47 +0000 | [diff] [blame] | 249 | Context, SourceRange(SourceLocationBeg), NewName); |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 250 | if (!Rename) |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 251 | return CB(Rename.takeError()); |
Haojian Wu | 345099c | 2017-11-09 11:30:04 +0000 | [diff] [blame] | 252 | |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 253 | Rename->invoke(ResultCollector, Context); |
| 254 | |
| 255 | assert(ResultCollector.Result.hasValue()); |
| 256 | if (!ResultCollector.Result.getValue()) |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 257 | return CB(ResultCollector.Result->takeError()); |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 258 | |
| 259 | std::vector<tooling::Replacement> Replacements; |
| 260 | for (const tooling::AtomicChange &Change : ResultCollector.Result->get()) { |
| 261 | tooling::Replacements ChangeReps = Change.getReplacements(); |
| 262 | for (const auto &Rep : ChangeReps) { |
| 263 | // FIXME: Right now we only support renaming the main file, so we |
| 264 | // drop replacements not for the main file. In the future, we might |
| 265 | // consider to support: |
| 266 | // * rename in any included header |
| 267 | // * rename only in the "main" header |
| 268 | // * provide an error if there are symbols we won't rename (e.g. |
| 269 | // std::vector) |
| 270 | // * rename globally in project |
| 271 | // * rename in open files |
| 272 | if (Rep.getFilePath() == File) |
| 273 | Replacements.push_back(Rep); |
| 274 | } |
Haojian Wu | 345099c | 2017-11-09 11:30:04 +0000 | [diff] [blame] | 275 | } |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 276 | return CB(std::move(Replacements)); |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 277 | }; |
Ilya Biryukov | 2c5e8e8 | 2018-02-15 13:15:47 +0000 | [diff] [blame] | 278 | |
| 279 | WorkScheduler.runWithAST( |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 280 | "Rename", File, Bind(Action, File.str(), NewName.str(), std::move(CB))); |
Haojian Wu | 345099c | 2017-11-09 11:30:04 +0000 | [diff] [blame] | 281 | } |
| 282 | |
Eric Liu | 6c8e858 | 2018-02-26 08:32:13 +0000 | [diff] [blame] | 283 | /// Creates a `HeaderFile` from \p Header which can be either a URI or a literal |
| 284 | /// include. |
| 285 | static llvm::Expected<HeaderFile> toHeaderFile(StringRef Header, |
| 286 | llvm::StringRef HintPath) { |
| 287 | if (isLiteralInclude(Header)) |
| 288 | return HeaderFile{Header.str(), /*Verbatim=*/true}; |
| 289 | auto U = URI::parse(Header); |
| 290 | if (!U) |
| 291 | return U.takeError(); |
| 292 | auto Resolved = URI::resolve(*U, HintPath); |
| 293 | if (!Resolved) |
| 294 | return Resolved.takeError(); |
| 295 | return HeaderFile{std::move(*Resolved), /*Verbatim=*/false}; |
Haojian Wu | 33caf89 | 2018-03-06 12:56:18 +0000 | [diff] [blame] | 296 | } |
Eric Liu | 6c8e858 | 2018-02-26 08:32:13 +0000 | [diff] [blame] | 297 | |
Eric Liu | c5105f9 | 2018-02-16 14:15:55 +0000 | [diff] [blame] | 298 | Expected<tooling::Replacements> |
| 299 | ClangdServer::insertInclude(PathRef File, StringRef Code, |
Eric Liu | 6c8e858 | 2018-02-26 08:32:13 +0000 | [diff] [blame] | 300 | StringRef DeclaringHeader, |
| 301 | StringRef InsertedHeader) { |
| 302 | assert(!DeclaringHeader.empty() && !InsertedHeader.empty()); |
Eric Liu | c5105f9 | 2018-02-16 14:15:55 +0000 | [diff] [blame] | 303 | std::string ToInclude; |
Eric Liu | 6c8e858 | 2018-02-26 08:32:13 +0000 | [diff] [blame] | 304 | auto ResolvedOrginal = toHeaderFile(DeclaringHeader, File); |
| 305 | if (!ResolvedOrginal) |
| 306 | return ResolvedOrginal.takeError(); |
| 307 | auto ResolvedPreferred = toHeaderFile(InsertedHeader, File); |
| 308 | if (!ResolvedPreferred) |
| 309 | return ResolvedPreferred.takeError(); |
| 310 | tooling::CompileCommand CompileCommand = CompileArgs.getCompileCommand(File); |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 311 | auto Include = |
| 312 | calculateIncludePath(File, Code, *ResolvedOrginal, *ResolvedPreferred, |
| 313 | CompileCommand, FSProvider.getFileSystem()); |
Eric Liu | 6c8e858 | 2018-02-26 08:32:13 +0000 | [diff] [blame] | 314 | if (!Include) |
| 315 | return Include.takeError(); |
| 316 | if (Include->empty()) |
| 317 | return tooling::Replacements(); |
| 318 | ToInclude = std::move(*Include); |
Eric Liu | c5105f9 | 2018-02-16 14:15:55 +0000 | [diff] [blame] | 319 | |
| 320 | auto Style = format::getStyle("file", File, "llvm"); |
| 321 | if (!Style) { |
| 322 | llvm::consumeError(Style.takeError()); |
| 323 | // FIXME(ioeric): needs more consistent style support in clangd server. |
| 324 | Style = format::getLLVMStyle(); |
| 325 | } |
| 326 | // Replacement with offset UINT_MAX and length 0 will be treated as include |
| 327 | // insertion. |
| 328 | tooling::Replacement R(File, /*Offset=*/UINT_MAX, 0, "#include " + ToInclude); |
Ilya Biryukov | bec5df2 | 2018-03-14 17:08:41 +0000 | [diff] [blame] | 329 | auto Replaces = |
| 330 | format::cleanupAroundReplacements(Code, tooling::Replacements(R), *Style); |
Eric Liu | e3395b9 | 2018-03-06 10:42:50 +0000 | [diff] [blame] | 331 | if (!Replaces) |
| 332 | return Replaces; |
| 333 | return formatReplacements(Code, *Replaces, *Style); |
Eric Liu | c5105f9 | 2018-02-16 14:15:55 +0000 | [diff] [blame] | 334 | } |
| 335 | |
Ilya Biryukov | 261c72e | 2018-01-17 12:30:24 +0000 | [diff] [blame] | 336 | llvm::Optional<std::string> ClangdServer::getDocument(PathRef File) { |
| 337 | auto Latest = DraftMgr.getDraft(File); |
| 338 | if (!Latest.Draft) |
| 339 | return llvm::None; |
| 340 | return std::move(*Latest.Draft); |
Ilya Biryukov | 38d7977 | 2017-05-16 09:38:59 +0000 | [diff] [blame] | 341 | } |
| 342 | |
Ilya Biryukov | 2c5e8e8 | 2018-02-15 13:15:47 +0000 | [diff] [blame] | 343 | void ClangdServer::dumpAST(PathRef File, |
| 344 | UniqueFunction<void(std::string)> Callback) { |
| 345 | auto Action = [](decltype(Callback) Callback, |
| 346 | llvm::Expected<InputsAndAST> InpAST) { |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 347 | if (!InpAST) { |
| 348 | ignoreError(InpAST.takeError()); |
Ilya Biryukov | 2c5e8e8 | 2018-02-15 13:15:47 +0000 | [diff] [blame] | 349 | return Callback("<no-ast>"); |
Ilya Biryukov | 02d5870 | 2017-08-01 15:51:38 +0000 | [diff] [blame] | 350 | } |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 351 | std::string Result; |
| 352 | |
| 353 | llvm::raw_string_ostream ResultOS(Result); |
| 354 | clangd::dumpAST(InpAST->AST, ResultOS); |
Ilya Biryukov | 02d5870 | 2017-08-01 15:51:38 +0000 | [diff] [blame] | 355 | ResultOS.flush(); |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 356 | |
Ilya Biryukov | 2c5e8e8 | 2018-02-15 13:15:47 +0000 | [diff] [blame] | 357 | Callback(Result); |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 358 | }; |
Ilya Biryukov | 2c5e8e8 | 2018-02-15 13:15:47 +0000 | [diff] [blame] | 359 | |
Sam McCall | 091557d | 2018-02-23 07:54:17 +0000 | [diff] [blame] | 360 | WorkScheduler.runWithAST("DumpAST", File, Bind(Action, std::move(Callback))); |
Ilya Biryukov | 38d7977 | 2017-05-16 09:38:59 +0000 | [diff] [blame] | 361 | } |
Marc-Andre Laperle | 2cbf037 | 2017-06-28 16:12:10 +0000 | [diff] [blame] | 362 | |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 363 | void ClangdServer::findDefinitions(PathRef File, Position Pos, |
| 364 | Callback<std::vector<Location>> CB) { |
| 365 | auto FS = FSProvider.getFileSystem(); |
| 366 | auto Action = [Pos, FS](Callback<std::vector<Location>> CB, |
| 367 | llvm::Expected<InputsAndAST> InpAST) { |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 368 | if (!InpAST) |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 369 | return CB(InpAST.takeError()); |
| 370 | CB(clangd::findDefinitions(InpAST->AST, Pos)); |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 371 | }; |
Ilya Biryukov | 2c5e8e8 | 2018-02-15 13:15:47 +0000 | [diff] [blame] | 372 | |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 373 | WorkScheduler.runWithAST("Definitions", File, Bind(Action, std::move(CB))); |
Marc-Andre Laperle | 2cbf037 | 2017-06-28 16:12:10 +0000 | [diff] [blame] | 374 | } |
Ilya Biryukov | c5ad35f | 2017-08-14 08:17:24 +0000 | [diff] [blame] | 375 | |
Marc-Andre Laperle | 6571b3e | 2017-09-28 03:14:40 +0000 | [diff] [blame] | 376 | llvm::Optional<Path> ClangdServer::switchSourceHeader(PathRef Path) { |
| 377 | |
| 378 | StringRef SourceExtensions[] = {".cpp", ".c", ".cc", ".cxx", |
| 379 | ".c++", ".m", ".mm"}; |
| 380 | StringRef HeaderExtensions[] = {".h", ".hh", ".hpp", ".hxx", ".inc"}; |
| 381 | |
| 382 | StringRef PathExt = llvm::sys::path::extension(Path); |
| 383 | |
| 384 | // Lookup in a list of known extensions. |
| 385 | auto SourceIter = |
| 386 | std::find_if(std::begin(SourceExtensions), std::end(SourceExtensions), |
| 387 | [&PathExt](PathRef SourceExt) { |
| 388 | return SourceExt.equals_lower(PathExt); |
| 389 | }); |
| 390 | bool IsSource = SourceIter != std::end(SourceExtensions); |
| 391 | |
| 392 | auto HeaderIter = |
| 393 | std::find_if(std::begin(HeaderExtensions), std::end(HeaderExtensions), |
| 394 | [&PathExt](PathRef HeaderExt) { |
| 395 | return HeaderExt.equals_lower(PathExt); |
| 396 | }); |
| 397 | |
| 398 | bool IsHeader = HeaderIter != std::end(HeaderExtensions); |
| 399 | |
| 400 | // We can only switch between extensions known extensions. |
| 401 | if (!IsSource && !IsHeader) |
| 402 | return llvm::None; |
| 403 | |
| 404 | // Array to lookup extensions for the switch. An opposite of where original |
| 405 | // extension was found. |
| 406 | ArrayRef<StringRef> NewExts; |
| 407 | if (IsSource) |
| 408 | NewExts = HeaderExtensions; |
| 409 | else |
| 410 | NewExts = SourceExtensions; |
| 411 | |
| 412 | // Storage for the new path. |
| 413 | SmallString<128> NewPath = StringRef(Path); |
| 414 | |
| 415 | // Instance of vfs::FileSystem, used for file existence checks. |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 416 | auto FS = FSProvider.getFileSystem(); |
Marc-Andre Laperle | 6571b3e | 2017-09-28 03:14:40 +0000 | [diff] [blame] | 417 | |
| 418 | // Loop through switched extension candidates. |
| 419 | for (StringRef NewExt : NewExts) { |
| 420 | llvm::sys::path::replace_extension(NewPath, NewExt); |
| 421 | if (FS->exists(NewPath)) |
| 422 | return NewPath.str().str(); // First str() to convert from SmallString to |
| 423 | // StringRef, second to convert from StringRef |
| 424 | // to std::string |
Ilya Biryukov | 3333494 | 2017-10-06 14:39:39 +0000 | [diff] [blame] | 425 | |
Marc-Andre Laperle | 6571b3e | 2017-09-28 03:14:40 +0000 | [diff] [blame] | 426 | // Also check NewExt in upper-case, just in case. |
| 427 | llvm::sys::path::replace_extension(NewPath, NewExt.upper()); |
| 428 | if (FS->exists(NewPath)) |
| 429 | return NewPath.str().str(); |
Marc-Andre Laperle | 6571b3e | 2017-09-28 03:14:40 +0000 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | return llvm::None; |
| 433 | } |
| 434 | |
Raoul Wols | 212bcf8 | 2017-12-12 20:25:06 +0000 | [diff] [blame] | 435 | llvm::Expected<tooling::Replacements> |
| 436 | ClangdServer::formatCode(llvm::StringRef Code, PathRef File, |
| 437 | ArrayRef<tooling::Range> Ranges) { |
| 438 | // Call clang-format. |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 439 | auto FS = FSProvider.getFileSystem(); |
| 440 | auto Style = format::getStyle("file", File, "LLVM", Code, FS.get()); |
Eric Liu | e3395b9 | 2018-03-06 10:42:50 +0000 | [diff] [blame] | 441 | if (!Style) |
| 442 | return Style.takeError(); |
| 443 | |
| 444 | tooling::Replacements IncludeReplaces = |
| 445 | format::sortIncludes(*Style, Code, Ranges, File); |
| 446 | auto Changed = tooling::applyAllReplacements(Code, IncludeReplaces); |
| 447 | if (!Changed) |
| 448 | return Changed.takeError(); |
| 449 | |
| 450 | return IncludeReplaces.merge(format::reformat( |
| 451 | Style.get(), *Changed, |
| 452 | tooling::calculateRangesAfterReplacements(IncludeReplaces, Ranges), |
| 453 | File)); |
Raoul Wols | 212bcf8 | 2017-12-12 20:25:06 +0000 | [diff] [blame] | 454 | } |
| 455 | |
Ilya Biryukov | 2c5e8e8 | 2018-02-15 13:15:47 +0000 | [diff] [blame] | 456 | void ClangdServer::findDocumentHighlights( |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 457 | PathRef File, Position Pos, Callback<std::vector<DocumentHighlight>> CB) { |
Ilya Biryukov | 0e6a51f | 2017-12-12 12:27:47 +0000 | [diff] [blame] | 458 | auto FileContents = DraftMgr.getDraft(File); |
| 459 | if (!FileContents.Draft) |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 460 | return CB(llvm::make_error<llvm::StringError>( |
Ilya Biryukov | 0e6a51f | 2017-12-12 12:27:47 +0000 | [diff] [blame] | 461 | "findDocumentHighlights called on non-added file", |
Ilya Biryukov | 2c5e8e8 | 2018-02-15 13:15:47 +0000 | [diff] [blame] | 462 | llvm::errc::invalid_argument)); |
Ilya Biryukov | 0e6a51f | 2017-12-12 12:27:47 +0000 | [diff] [blame] | 463 | |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 464 | auto FS = FSProvider.getFileSystem(); |
| 465 | auto Action = [FS, Pos](Callback<std::vector<DocumentHighlight>> CB, |
| 466 | llvm::Expected<InputsAndAST> InpAST) { |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 467 | if (!InpAST) |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 468 | return CB(InpAST.takeError()); |
| 469 | CB(clangd::findDocumentHighlights(InpAST->AST, Pos)); |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 470 | }; |
Ilya Biryukov | 2c5e8e8 | 2018-02-15 13:15:47 +0000 | [diff] [blame] | 471 | |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 472 | WorkScheduler.runWithAST("Highlights", File, Bind(Action, std::move(CB))); |
Ilya Biryukov | 0e6a51f | 2017-12-12 12:27:47 +0000 | [diff] [blame] | 473 | } |
| 474 | |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 475 | void ClangdServer::findHover(PathRef File, Position Pos, Callback<Hover> CB) { |
Marc-Andre Laperle | 3e618ed | 2018-02-16 21:38:15 +0000 | [diff] [blame] | 476 | Hover FinalHover; |
| 477 | auto FileContents = DraftMgr.getDraft(File); |
| 478 | if (!FileContents.Draft) |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 479 | return CB(llvm::make_error<llvm::StringError>( |
Marc-Andre Laperle | 3e618ed | 2018-02-16 21:38:15 +0000 | [diff] [blame] | 480 | "findHover called on non-added file", llvm::errc::invalid_argument)); |
| 481 | |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 482 | auto FS = FSProvider.getFileSystem(); |
| 483 | auto Action = [Pos, FS](Callback<Hover> CB, |
| 484 | llvm::Expected<InputsAndAST> InpAST) { |
Marc-Andre Laperle | 3e618ed | 2018-02-16 21:38:15 +0000 | [diff] [blame] | 485 | if (!InpAST) |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 486 | return CB(InpAST.takeError()); |
| 487 | CB(clangd::getHover(InpAST->AST, Pos)); |
Marc-Andre Laperle | 3e618ed | 2018-02-16 21:38:15 +0000 | [diff] [blame] | 488 | }; |
| 489 | |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 490 | WorkScheduler.runWithAST("Hover", File, Bind(Action, std::move(CB))); |
Marc-Andre Laperle | 3e618ed | 2018-02-16 21:38:15 +0000 | [diff] [blame] | 491 | } |
| 492 | |
Ilya Biryukov | bec5df2 | 2018-03-14 17:08:41 +0000 | [diff] [blame] | 493 | void ClangdServer::consumeDiagnostics(PathRef File, DocVersion Version, |
| 494 | std::vector<Diag> Diags) { |
| 495 | // We need to serialize access to resulting diagnostics to avoid calling |
| 496 | // `onDiagnosticsReady` in the wrong order. |
| 497 | std::lock_guard<std::mutex> DiagsLock(DiagnosticsMutex); |
| 498 | DocVersion &LastReportedDiagsVersion = ReportedDiagnosticVersions[File]; |
Ilya Biryukov | 929697b | 2018-01-25 14:19:21 +0000 | [diff] [blame] | 499 | |
Ilya Biryukov | bec5df2 | 2018-03-14 17:08:41 +0000 | [diff] [blame] | 500 | // FIXME(ibiryukov): get rid of '<' comparison here. In the current |
| 501 | // implementation diagnostics will not be reported after version counters' |
| 502 | // overflow. This should not happen in practice, since DocVersion is a |
| 503 | // 64-bit unsigned integer. |
| 504 | if (Version < LastReportedDiagsVersion) |
| 505 | return; |
| 506 | LastReportedDiagsVersion = Version; |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 507 | |
Ilya Biryukov | bec5df2 | 2018-03-14 17:08:41 +0000 | [diff] [blame] | 508 | DiagConsumer.onDiagnosticsReady(File, std::move(Diags)); |
Ilya Biryukov | c5ad35f | 2017-08-14 08:17:24 +0000 | [diff] [blame] | 509 | } |
Marc-Andre Laperle | bf11424 | 2017-10-02 18:00:37 +0000 | [diff] [blame] | 510 | |
Simon Marchi | 5178f92 | 2018-02-22 14:00:39 +0000 | [diff] [blame] | 511 | void ClangdServer::reparseOpenedFiles() { |
| 512 | for (const Path &FilePath : DraftMgr.getActiveFiles()) |
Ilya Biryukov | bec5df2 | 2018-03-14 17:08:41 +0000 | [diff] [blame] | 513 | addDocument(FilePath, *DraftMgr.getDraft(FilePath).Draft, |
| 514 | WantDiagnostics::Auto, /*SkipCache=*/true); |
Simon Marchi | 5178f92 | 2018-02-22 14:00:39 +0000 | [diff] [blame] | 515 | } |
| 516 | |
Marc-Andre Laperle | bf11424 | 2017-10-02 18:00:37 +0000 | [diff] [blame] | 517 | void ClangdServer::onFileEvent(const DidChangeWatchedFilesParams &Params) { |
| 518 | // FIXME: Do nothing for now. This will be used for indexing and potentially |
| 519 | // invalidating other caches. |
| 520 | } |
Ilya Biryukov | df84234 | 2018-01-25 14:32:21 +0000 | [diff] [blame] | 521 | |
| 522 | std::vector<std::pair<Path, std::size_t>> |
| 523 | ClangdServer::getUsedBytesPerFile() const { |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 524 | return WorkScheduler.getUsedBytesPerFile(); |
Ilya Biryukov | df84234 | 2018-01-25 14:32:21 +0000 | [diff] [blame] | 525 | } |
Sam McCall | 0bb24cd | 2018-02-13 08:59:23 +0000 | [diff] [blame] | 526 | |
| 527 | LLVM_NODISCARD bool |
| 528 | ClangdServer::blockUntilIdleForTest(llvm::Optional<double> TimeoutSeconds) { |
| 529 | return WorkScheduler.blockUntilIdle(timeoutSeconds(TimeoutSeconds)); |
| 530 | } |