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(); |
| 157 | auto Task = [PCHs, Pos, FS, CodeCompleteOpts]( |
| 158 | std::string Contents, Path File, Callback<CompletionList> CB, |
Sam McCall | d1a7a37 | 2018-01-31 13:40:48 +0000 | [diff] [blame] | 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; |
| 162 | auto &Command = IP->Inputs.CompileCommand; |
Ilya Biryukov | dcd2169 | 2017-10-05 17:04:13 +0000 | [diff] [blame] | 163 | |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 164 | // FIXME(ibiryukov): even if Preamble is non-null, we may want to check |
| 165 | // both the old and the new version in case only one of them matches. |
| 166 | CompletionList Result = clangd::codeComplete( |
Sam McCall | d1a7a37 | 2018-01-31 13:40:48 +0000 | [diff] [blame] | 167 | File, Command, PreambleData ? &PreambleData->Preamble : nullptr, |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 168 | Contents, Pos, FS, PCHs, CodeCompleteOpts); |
| 169 | CB(std::move(Result)); |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 170 | }; |
| 171 | |
Sam McCall | 091557d | 2018-02-23 07:54:17 +0000 | [diff] [blame] | 172 | WorkScheduler.runWithPreamble( |
| 173 | "CodeComplete", File, |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 174 | Bind(Task, std::move(*Latest.Draft), File.str(), std::move(CB))); |
Ilya Biryukov | 38d7977 | 2017-05-16 09:38:59 +0000 | [diff] [blame] | 175 | } |
Ilya Biryukov | f01af68 | 2017-05-23 13:42:59 +0000 | [diff] [blame] | 176 | |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 177 | void ClangdServer::signatureHelp(PathRef File, Position Pos, |
| 178 | Callback<SignatureHelp> CB) { |
Sam McCall | db3ea4c | 2018-02-27 17:15:50 +0000 | [diff] [blame] | 179 | VersionedDraft Latest = DraftMgr.getDraft(File); |
| 180 | if (!Latest.Draft) |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 181 | return CB(llvm::make_error<llvm::StringError>( |
Sam McCall | db3ea4c | 2018-02-27 17:15:50 +0000 | [diff] [blame] | 182 | "signatureHelp is called for non-added document", |
| 183 | llvm::errc::invalid_argument)); |
Ilya Biryukov | d9bdfe0 | 2017-10-06 11:54:17 +0000 | [diff] [blame] | 184 | |
Ilya Biryukov | 2c5e8e8 | 2018-02-15 13:15:47 +0000 | [diff] [blame] | 185 | auto PCHs = this->PCHs; |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 186 | auto FS = FSProvider.getFileSystem(); |
| 187 | auto Action = [Pos, FS, PCHs](std::string Contents, Path File, |
| 188 | Callback<SignatureHelp> CB, |
| 189 | llvm::Expected<InputsAndPreamble> IP) { |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 190 | if (!IP) |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 191 | return CB(IP.takeError()); |
Ilya Biryukov | 2c5e8e8 | 2018-02-15 13:15:47 +0000 | [diff] [blame] | 192 | |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 193 | auto PreambleData = IP->Preamble; |
| 194 | auto &Command = IP->Inputs.CompileCommand; |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 195 | CB(clangd::signatureHelp(File, Command, |
| 196 | PreambleData ? &PreambleData->Preamble : nullptr, |
| 197 | Contents, Pos, FS, PCHs)); |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 198 | }; |
Ilya Biryukov | 2c5e8e8 | 2018-02-15 13:15:47 +0000 | [diff] [blame] | 199 | |
Sam McCall | db3ea4c | 2018-02-27 17:15:50 +0000 | [diff] [blame] | 200 | WorkScheduler.runWithPreamble( |
| 201 | "SignatureHelp", File, |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 202 | Bind(Action, std::move(*Latest.Draft), File.str(), std::move(CB))); |
Ilya Biryukov | d9bdfe0 | 2017-10-06 11:54:17 +0000 | [diff] [blame] | 203 | } |
| 204 | |
Raoul Wols | 212bcf8 | 2017-12-12 20:25:06 +0000 | [diff] [blame] | 205 | llvm::Expected<tooling::Replacements> |
| 206 | ClangdServer::formatRange(StringRef Code, PathRef File, Range Rng) { |
Ilya Biryukov | afb5554 | 2017-05-16 14:40:30 +0000 | [diff] [blame] | 207 | size_t Begin = positionToOffset(Code, Rng.start); |
| 208 | size_t Len = positionToOffset(Code, Rng.end) - Begin; |
| 209 | return formatCode(Code, File, {tooling::Range(Begin, Len)}); |
| 210 | } |
| 211 | |
Raoul Wols | 212bcf8 | 2017-12-12 20:25:06 +0000 | [diff] [blame] | 212 | llvm::Expected<tooling::Replacements> ClangdServer::formatFile(StringRef Code, |
| 213 | PathRef File) { |
Ilya Biryukov | afb5554 | 2017-05-16 14:40:30 +0000 | [diff] [blame] | 214 | // Format everything. |
Ilya Biryukov | afb5554 | 2017-05-16 14:40:30 +0000 | [diff] [blame] | 215 | return formatCode(Code, File, {tooling::Range(0, Code.size())}); |
| 216 | } |
| 217 | |
Raoul Wols | 212bcf8 | 2017-12-12 20:25:06 +0000 | [diff] [blame] | 218 | llvm::Expected<tooling::Replacements> |
| 219 | ClangdServer::formatOnType(StringRef Code, PathRef File, Position Pos) { |
Ilya Biryukov | afb5554 | 2017-05-16 14:40:30 +0000 | [diff] [blame] | 220 | // Look for the previous opening brace from the character position and |
| 221 | // format starting from there. |
Ilya Biryukov | afb5554 | 2017-05-16 14:40:30 +0000 | [diff] [blame] | 222 | size_t CursorPos = positionToOffset(Code, Pos); |
| 223 | size_t PreviousLBracePos = StringRef(Code).find_last_of('{', CursorPos); |
| 224 | if (PreviousLBracePos == StringRef::npos) |
| 225 | PreviousLBracePos = CursorPos; |
Sam McCall | b536a2a | 2017-12-19 12:23:48 +0000 | [diff] [blame] | 226 | size_t Len = CursorPos - PreviousLBracePos; |
Ilya Biryukov | afb5554 | 2017-05-16 14:40:30 +0000 | [diff] [blame] | 227 | |
| 228 | return formatCode(Code, File, {tooling::Range(PreviousLBracePos, Len)}); |
| 229 | } |
Ilya Biryukov | 38d7977 | 2017-05-16 09:38:59 +0000 | [diff] [blame] | 230 | |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 231 | void ClangdServer::rename(PathRef File, Position Pos, llvm::StringRef NewName, |
| 232 | Callback<std::vector<tooling::Replacement>> CB) { |
Ilya Biryukov | 2c5e8e8 | 2018-02-15 13:15:47 +0000 | [diff] [blame] | 233 | auto Action = [Pos](Path File, std::string NewName, |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 234 | Callback<std::vector<tooling::Replacement>> CB, |
Ilya Biryukov | 2c5e8e8 | 2018-02-15 13:15:47 +0000 | [diff] [blame] | 235 | Expected<InputsAndAST> InpAST) { |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 236 | if (!InpAST) |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 237 | return CB(InpAST.takeError()); |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 238 | auto &AST = InpAST->AST; |
| 239 | |
| 240 | RefactoringResultCollector ResultCollector; |
| 241 | const SourceManager &SourceMgr = AST.getASTContext().getSourceManager(); |
Haojian Wu | 345099c | 2017-11-09 11:30:04 +0000 | [diff] [blame] | 242 | const FileEntry *FE = |
| 243 | SourceMgr.getFileEntryForID(SourceMgr.getMainFileID()); |
| 244 | if (!FE) |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 245 | return CB(llvm::make_error<llvm::StringError>( |
Ilya Biryukov | 2c5e8e8 | 2018-02-15 13:15:47 +0000 | [diff] [blame] | 246 | "rename called for non-added document", |
| 247 | llvm::errc::invalid_argument)); |
Haojian Wu | 345099c | 2017-11-09 11:30:04 +0000 | [diff] [blame] | 248 | SourceLocation SourceLocationBeg = |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 249 | clangd::getBeginningOfIdentifier(AST, Pos, FE); |
Haojian Wu | 345099c | 2017-11-09 11:30:04 +0000 | [diff] [blame] | 250 | tooling::RefactoringRuleContext Context( |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 251 | AST.getASTContext().getSourceManager()); |
| 252 | Context.setASTContext(AST.getASTContext()); |
Haojian Wu | 345099c | 2017-11-09 11:30:04 +0000 | [diff] [blame] | 253 | auto Rename = clang::tooling::RenameOccurrences::initiate( |
Ilya Biryukov | 2c5e8e8 | 2018-02-15 13:15:47 +0000 | [diff] [blame] | 254 | Context, SourceRange(SourceLocationBeg), NewName); |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 255 | if (!Rename) |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 256 | return CB(Rename.takeError()); |
Haojian Wu | 345099c | 2017-11-09 11:30:04 +0000 | [diff] [blame] | 257 | |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 258 | Rename->invoke(ResultCollector, Context); |
| 259 | |
| 260 | assert(ResultCollector.Result.hasValue()); |
| 261 | if (!ResultCollector.Result.getValue()) |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 262 | return CB(ResultCollector.Result->takeError()); |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 263 | |
| 264 | std::vector<tooling::Replacement> Replacements; |
| 265 | for (const tooling::AtomicChange &Change : ResultCollector.Result->get()) { |
| 266 | tooling::Replacements ChangeReps = Change.getReplacements(); |
| 267 | for (const auto &Rep : ChangeReps) { |
| 268 | // FIXME: Right now we only support renaming the main file, so we |
| 269 | // drop replacements not for the main file. In the future, we might |
| 270 | // consider to support: |
| 271 | // * rename in any included header |
| 272 | // * rename only in the "main" header |
| 273 | // * provide an error if there are symbols we won't rename (e.g. |
| 274 | // std::vector) |
| 275 | // * rename globally in project |
| 276 | // * rename in open files |
| 277 | if (Rep.getFilePath() == File) |
| 278 | Replacements.push_back(Rep); |
| 279 | } |
Haojian Wu | 345099c | 2017-11-09 11:30:04 +0000 | [diff] [blame] | 280 | } |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 281 | return CB(std::move(Replacements)); |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 282 | }; |
Ilya Biryukov | 2c5e8e8 | 2018-02-15 13:15:47 +0000 | [diff] [blame] | 283 | |
| 284 | WorkScheduler.runWithAST( |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 285 | "Rename", File, Bind(Action, File.str(), NewName.str(), std::move(CB))); |
Haojian Wu | 345099c | 2017-11-09 11:30:04 +0000 | [diff] [blame] | 286 | } |
| 287 | |
Eric Liu | 6c8e858 | 2018-02-26 08:32:13 +0000 | [diff] [blame] | 288 | /// Creates a `HeaderFile` from \p Header which can be either a URI or a literal |
| 289 | /// include. |
| 290 | static llvm::Expected<HeaderFile> toHeaderFile(StringRef Header, |
| 291 | llvm::StringRef HintPath) { |
| 292 | if (isLiteralInclude(Header)) |
| 293 | return HeaderFile{Header.str(), /*Verbatim=*/true}; |
| 294 | auto U = URI::parse(Header); |
| 295 | if (!U) |
| 296 | return U.takeError(); |
| 297 | auto Resolved = URI::resolve(*U, HintPath); |
| 298 | if (!Resolved) |
| 299 | return Resolved.takeError(); |
| 300 | return HeaderFile{std::move(*Resolved), /*Verbatim=*/false}; |
Haojian Wu | 33caf89 | 2018-03-06 12:56:18 +0000 | [diff] [blame] | 301 | } |
Eric Liu | 6c8e858 | 2018-02-26 08:32:13 +0000 | [diff] [blame] | 302 | |
Eric Liu | c5105f9 | 2018-02-16 14:15:55 +0000 | [diff] [blame] | 303 | Expected<tooling::Replacements> |
| 304 | ClangdServer::insertInclude(PathRef File, StringRef Code, |
Eric Liu | 6c8e858 | 2018-02-26 08:32:13 +0000 | [diff] [blame] | 305 | StringRef DeclaringHeader, |
| 306 | StringRef InsertedHeader) { |
| 307 | assert(!DeclaringHeader.empty() && !InsertedHeader.empty()); |
Eric Liu | c5105f9 | 2018-02-16 14:15:55 +0000 | [diff] [blame] | 308 | std::string ToInclude; |
Eric Liu | 6c8e858 | 2018-02-26 08:32:13 +0000 | [diff] [blame] | 309 | auto ResolvedOrginal = toHeaderFile(DeclaringHeader, File); |
| 310 | if (!ResolvedOrginal) |
| 311 | return ResolvedOrginal.takeError(); |
| 312 | auto ResolvedPreferred = toHeaderFile(InsertedHeader, File); |
| 313 | if (!ResolvedPreferred) |
| 314 | return ResolvedPreferred.takeError(); |
| 315 | tooling::CompileCommand CompileCommand = CompileArgs.getCompileCommand(File); |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 316 | auto Include = |
| 317 | calculateIncludePath(File, Code, *ResolvedOrginal, *ResolvedPreferred, |
| 318 | CompileCommand, FSProvider.getFileSystem()); |
Eric Liu | 6c8e858 | 2018-02-26 08:32:13 +0000 | [diff] [blame] | 319 | if (!Include) |
| 320 | return Include.takeError(); |
| 321 | if (Include->empty()) |
| 322 | return tooling::Replacements(); |
| 323 | ToInclude = std::move(*Include); |
Eric Liu | c5105f9 | 2018-02-16 14:15:55 +0000 | [diff] [blame] | 324 | |
| 325 | auto Style = format::getStyle("file", File, "llvm"); |
| 326 | if (!Style) { |
| 327 | llvm::consumeError(Style.takeError()); |
| 328 | // FIXME(ioeric): needs more consistent style support in clangd server. |
| 329 | Style = format::getLLVMStyle(); |
| 330 | } |
| 331 | // Replacement with offset UINT_MAX and length 0 will be treated as include |
| 332 | // insertion. |
| 333 | tooling::Replacement R(File, /*Offset=*/UINT_MAX, 0, "#include " + ToInclude); |
Ilya Biryukov | bec5df2 | 2018-03-14 17:08:41 +0000 | [diff] [blame^] | 334 | auto Replaces = |
| 335 | format::cleanupAroundReplacements(Code, tooling::Replacements(R), *Style); |
Eric Liu | e3395b9 | 2018-03-06 10:42:50 +0000 | [diff] [blame] | 336 | if (!Replaces) |
| 337 | return Replaces; |
| 338 | return formatReplacements(Code, *Replaces, *Style); |
Eric Liu | c5105f9 | 2018-02-16 14:15:55 +0000 | [diff] [blame] | 339 | } |
| 340 | |
Ilya Biryukov | 261c72e | 2018-01-17 12:30:24 +0000 | [diff] [blame] | 341 | llvm::Optional<std::string> ClangdServer::getDocument(PathRef File) { |
| 342 | auto Latest = DraftMgr.getDraft(File); |
| 343 | if (!Latest.Draft) |
| 344 | return llvm::None; |
| 345 | return std::move(*Latest.Draft); |
Ilya Biryukov | 38d7977 | 2017-05-16 09:38:59 +0000 | [diff] [blame] | 346 | } |
| 347 | |
Ilya Biryukov | 2c5e8e8 | 2018-02-15 13:15:47 +0000 | [diff] [blame] | 348 | void ClangdServer::dumpAST(PathRef File, |
| 349 | UniqueFunction<void(std::string)> Callback) { |
| 350 | auto Action = [](decltype(Callback) Callback, |
| 351 | llvm::Expected<InputsAndAST> InpAST) { |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 352 | if (!InpAST) { |
| 353 | ignoreError(InpAST.takeError()); |
Ilya Biryukov | 2c5e8e8 | 2018-02-15 13:15:47 +0000 | [diff] [blame] | 354 | return Callback("<no-ast>"); |
Ilya Biryukov | 02d5870 | 2017-08-01 15:51:38 +0000 | [diff] [blame] | 355 | } |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 356 | std::string Result; |
| 357 | |
| 358 | llvm::raw_string_ostream ResultOS(Result); |
| 359 | clangd::dumpAST(InpAST->AST, ResultOS); |
Ilya Biryukov | 02d5870 | 2017-08-01 15:51:38 +0000 | [diff] [blame] | 360 | ResultOS.flush(); |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 361 | |
Ilya Biryukov | 2c5e8e8 | 2018-02-15 13:15:47 +0000 | [diff] [blame] | 362 | Callback(Result); |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 363 | }; |
Ilya Biryukov | 2c5e8e8 | 2018-02-15 13:15:47 +0000 | [diff] [blame] | 364 | |
Sam McCall | 091557d | 2018-02-23 07:54:17 +0000 | [diff] [blame] | 365 | WorkScheduler.runWithAST("DumpAST", File, Bind(Action, std::move(Callback))); |
Ilya Biryukov | 38d7977 | 2017-05-16 09:38:59 +0000 | [diff] [blame] | 366 | } |
Marc-Andre Laperle | 2cbf037 | 2017-06-28 16:12:10 +0000 | [diff] [blame] | 367 | |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 368 | void ClangdServer::findDefinitions(PathRef File, Position Pos, |
| 369 | Callback<std::vector<Location>> CB) { |
| 370 | auto FS = FSProvider.getFileSystem(); |
| 371 | auto Action = [Pos, FS](Callback<std::vector<Location>> CB, |
| 372 | llvm::Expected<InputsAndAST> InpAST) { |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 373 | if (!InpAST) |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 374 | return CB(InpAST.takeError()); |
| 375 | CB(clangd::findDefinitions(InpAST->AST, Pos)); |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 376 | }; |
Ilya Biryukov | 2c5e8e8 | 2018-02-15 13:15:47 +0000 | [diff] [blame] | 377 | |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 378 | WorkScheduler.runWithAST("Definitions", File, Bind(Action, std::move(CB))); |
Marc-Andre Laperle | 2cbf037 | 2017-06-28 16:12:10 +0000 | [diff] [blame] | 379 | } |
Ilya Biryukov | c5ad35f | 2017-08-14 08:17:24 +0000 | [diff] [blame] | 380 | |
Marc-Andre Laperle | 6571b3e | 2017-09-28 03:14:40 +0000 | [diff] [blame] | 381 | llvm::Optional<Path> ClangdServer::switchSourceHeader(PathRef Path) { |
| 382 | |
| 383 | StringRef SourceExtensions[] = {".cpp", ".c", ".cc", ".cxx", |
| 384 | ".c++", ".m", ".mm"}; |
| 385 | StringRef HeaderExtensions[] = {".h", ".hh", ".hpp", ".hxx", ".inc"}; |
| 386 | |
| 387 | StringRef PathExt = llvm::sys::path::extension(Path); |
| 388 | |
| 389 | // Lookup in a list of known extensions. |
| 390 | auto SourceIter = |
| 391 | std::find_if(std::begin(SourceExtensions), std::end(SourceExtensions), |
| 392 | [&PathExt](PathRef SourceExt) { |
| 393 | return SourceExt.equals_lower(PathExt); |
| 394 | }); |
| 395 | bool IsSource = SourceIter != std::end(SourceExtensions); |
| 396 | |
| 397 | auto HeaderIter = |
| 398 | std::find_if(std::begin(HeaderExtensions), std::end(HeaderExtensions), |
| 399 | [&PathExt](PathRef HeaderExt) { |
| 400 | return HeaderExt.equals_lower(PathExt); |
| 401 | }); |
| 402 | |
| 403 | bool IsHeader = HeaderIter != std::end(HeaderExtensions); |
| 404 | |
| 405 | // We can only switch between extensions known extensions. |
| 406 | if (!IsSource && !IsHeader) |
| 407 | return llvm::None; |
| 408 | |
| 409 | // Array to lookup extensions for the switch. An opposite of where original |
| 410 | // extension was found. |
| 411 | ArrayRef<StringRef> NewExts; |
| 412 | if (IsSource) |
| 413 | NewExts = HeaderExtensions; |
| 414 | else |
| 415 | NewExts = SourceExtensions; |
| 416 | |
| 417 | // Storage for the new path. |
| 418 | SmallString<128> NewPath = StringRef(Path); |
| 419 | |
| 420 | // Instance of vfs::FileSystem, used for file existence checks. |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 421 | auto FS = FSProvider.getFileSystem(); |
Marc-Andre Laperle | 6571b3e | 2017-09-28 03:14:40 +0000 | [diff] [blame] | 422 | |
| 423 | // Loop through switched extension candidates. |
| 424 | for (StringRef NewExt : NewExts) { |
| 425 | llvm::sys::path::replace_extension(NewPath, NewExt); |
| 426 | if (FS->exists(NewPath)) |
| 427 | return NewPath.str().str(); // First str() to convert from SmallString to |
| 428 | // StringRef, second to convert from StringRef |
| 429 | // to std::string |
Ilya Biryukov | 3333494 | 2017-10-06 14:39:39 +0000 | [diff] [blame] | 430 | |
Marc-Andre Laperle | 6571b3e | 2017-09-28 03:14:40 +0000 | [diff] [blame] | 431 | // Also check NewExt in upper-case, just in case. |
| 432 | llvm::sys::path::replace_extension(NewPath, NewExt.upper()); |
| 433 | if (FS->exists(NewPath)) |
| 434 | return NewPath.str().str(); |
Marc-Andre Laperle | 6571b3e | 2017-09-28 03:14:40 +0000 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | return llvm::None; |
| 438 | } |
| 439 | |
Raoul Wols | 212bcf8 | 2017-12-12 20:25:06 +0000 | [diff] [blame] | 440 | llvm::Expected<tooling::Replacements> |
| 441 | ClangdServer::formatCode(llvm::StringRef Code, PathRef File, |
| 442 | ArrayRef<tooling::Range> Ranges) { |
| 443 | // Call clang-format. |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 444 | auto FS = FSProvider.getFileSystem(); |
| 445 | auto Style = format::getStyle("file", File, "LLVM", Code, FS.get()); |
Eric Liu | e3395b9 | 2018-03-06 10:42:50 +0000 | [diff] [blame] | 446 | if (!Style) |
| 447 | return Style.takeError(); |
| 448 | |
| 449 | tooling::Replacements IncludeReplaces = |
| 450 | format::sortIncludes(*Style, Code, Ranges, File); |
| 451 | auto Changed = tooling::applyAllReplacements(Code, IncludeReplaces); |
| 452 | if (!Changed) |
| 453 | return Changed.takeError(); |
| 454 | |
| 455 | return IncludeReplaces.merge(format::reformat( |
| 456 | Style.get(), *Changed, |
| 457 | tooling::calculateRangesAfterReplacements(IncludeReplaces, Ranges), |
| 458 | File)); |
Raoul Wols | 212bcf8 | 2017-12-12 20:25:06 +0000 | [diff] [blame] | 459 | } |
| 460 | |
Ilya Biryukov | 2c5e8e8 | 2018-02-15 13:15:47 +0000 | [diff] [blame] | 461 | void ClangdServer::findDocumentHighlights( |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 462 | PathRef File, Position Pos, Callback<std::vector<DocumentHighlight>> CB) { |
Ilya Biryukov | 0e6a51f | 2017-12-12 12:27:47 +0000 | [diff] [blame] | 463 | auto FileContents = DraftMgr.getDraft(File); |
| 464 | if (!FileContents.Draft) |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 465 | return CB(llvm::make_error<llvm::StringError>( |
Ilya Biryukov | 0e6a51f | 2017-12-12 12:27:47 +0000 | [diff] [blame] | 466 | "findDocumentHighlights called on non-added file", |
Ilya Biryukov | 2c5e8e8 | 2018-02-15 13:15:47 +0000 | [diff] [blame] | 467 | llvm::errc::invalid_argument)); |
Ilya Biryukov | 0e6a51f | 2017-12-12 12:27:47 +0000 | [diff] [blame] | 468 | |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 469 | auto FS = FSProvider.getFileSystem(); |
| 470 | auto Action = [FS, Pos](Callback<std::vector<DocumentHighlight>> CB, |
| 471 | llvm::Expected<InputsAndAST> InpAST) { |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 472 | if (!InpAST) |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 473 | return CB(InpAST.takeError()); |
| 474 | CB(clangd::findDocumentHighlights(InpAST->AST, Pos)); |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 475 | }; |
Ilya Biryukov | 2c5e8e8 | 2018-02-15 13:15:47 +0000 | [diff] [blame] | 476 | |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 477 | WorkScheduler.runWithAST("Highlights", File, Bind(Action, std::move(CB))); |
Ilya Biryukov | 0e6a51f | 2017-12-12 12:27:47 +0000 | [diff] [blame] | 478 | } |
| 479 | |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 480 | void ClangdServer::findHover(PathRef File, Position Pos, Callback<Hover> CB) { |
Marc-Andre Laperle | 3e618ed | 2018-02-16 21:38:15 +0000 | [diff] [blame] | 481 | Hover FinalHover; |
| 482 | auto FileContents = DraftMgr.getDraft(File); |
| 483 | if (!FileContents.Draft) |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 484 | return CB(llvm::make_error<llvm::StringError>( |
Marc-Andre Laperle | 3e618ed | 2018-02-16 21:38:15 +0000 | [diff] [blame] | 485 | "findHover called on non-added file", llvm::errc::invalid_argument)); |
| 486 | |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 487 | auto FS = FSProvider.getFileSystem(); |
| 488 | auto Action = [Pos, FS](Callback<Hover> CB, |
| 489 | llvm::Expected<InputsAndAST> InpAST) { |
Marc-Andre Laperle | 3e618ed | 2018-02-16 21:38:15 +0000 | [diff] [blame] | 490 | if (!InpAST) |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 491 | return CB(InpAST.takeError()); |
| 492 | CB(clangd::getHover(InpAST->AST, Pos)); |
Marc-Andre Laperle | 3e618ed | 2018-02-16 21:38:15 +0000 | [diff] [blame] | 493 | }; |
| 494 | |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 495 | WorkScheduler.runWithAST("Hover", File, Bind(Action, std::move(CB))); |
Marc-Andre Laperle | 3e618ed | 2018-02-16 21:38:15 +0000 | [diff] [blame] | 496 | } |
| 497 | |
Ilya Biryukov | bec5df2 | 2018-03-14 17:08:41 +0000 | [diff] [blame^] | 498 | void ClangdServer::consumeDiagnostics(PathRef File, DocVersion Version, |
| 499 | std::vector<Diag> Diags) { |
| 500 | // We need to serialize access to resulting diagnostics to avoid calling |
| 501 | // `onDiagnosticsReady` in the wrong order. |
| 502 | std::lock_guard<std::mutex> DiagsLock(DiagnosticsMutex); |
| 503 | DocVersion &LastReportedDiagsVersion = ReportedDiagnosticVersions[File]; |
Ilya Biryukov | 929697b | 2018-01-25 14:19:21 +0000 | [diff] [blame] | 504 | |
Ilya Biryukov | bec5df2 | 2018-03-14 17:08:41 +0000 | [diff] [blame^] | 505 | // FIXME(ibiryukov): get rid of '<' comparison here. In the current |
| 506 | // implementation diagnostics will not be reported after version counters' |
| 507 | // overflow. This should not happen in practice, since DocVersion is a |
| 508 | // 64-bit unsigned integer. |
| 509 | if (Version < LastReportedDiagsVersion) |
| 510 | return; |
| 511 | LastReportedDiagsVersion = Version; |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 512 | |
Ilya Biryukov | bec5df2 | 2018-03-14 17:08:41 +0000 | [diff] [blame^] | 513 | DiagConsumer.onDiagnosticsReady(File, std::move(Diags)); |
Ilya Biryukov | c5ad35f | 2017-08-14 08:17:24 +0000 | [diff] [blame] | 514 | } |
Marc-Andre Laperle | bf11424 | 2017-10-02 18:00:37 +0000 | [diff] [blame] | 515 | |
Simon Marchi | 5178f92 | 2018-02-22 14:00:39 +0000 | [diff] [blame] | 516 | void ClangdServer::reparseOpenedFiles() { |
| 517 | for (const Path &FilePath : DraftMgr.getActiveFiles()) |
Ilya Biryukov | bec5df2 | 2018-03-14 17:08:41 +0000 | [diff] [blame^] | 518 | addDocument(FilePath, *DraftMgr.getDraft(FilePath).Draft, |
| 519 | WantDiagnostics::Auto, /*SkipCache=*/true); |
Simon Marchi | 5178f92 | 2018-02-22 14:00:39 +0000 | [diff] [blame] | 520 | } |
| 521 | |
Marc-Andre Laperle | bf11424 | 2017-10-02 18:00:37 +0000 | [diff] [blame] | 522 | void ClangdServer::onFileEvent(const DidChangeWatchedFilesParams &Params) { |
| 523 | // FIXME: Do nothing for now. This will be used for indexing and potentially |
| 524 | // invalidating other caches. |
| 525 | } |
Ilya Biryukov | df84234 | 2018-01-25 14:32:21 +0000 | [diff] [blame] | 526 | |
| 527 | std::vector<std::pair<Path, std::size_t>> |
| 528 | ClangdServer::getUsedBytesPerFile() const { |
Ilya Biryukov | 75f1dd9 | 2018-01-31 08:51:16 +0000 | [diff] [blame] | 529 | return WorkScheduler.getUsedBytesPerFile(); |
Ilya Biryukov | df84234 | 2018-01-25 14:32:21 +0000 | [diff] [blame] | 530 | } |
Sam McCall | 0bb24cd | 2018-02-13 08:59:23 +0000 | [diff] [blame] | 531 | |
| 532 | LLVM_NODISCARD bool |
| 533 | ClangdServer::blockUntilIdleForTest(llvm::Optional<double> TimeoutSeconds) { |
| 534 | return WorkScheduler.blockUntilIdle(timeoutSeconds(TimeoutSeconds)); |
| 535 | } |