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