Use pseudoparser-based folding ranges in ClangdServer.
authorUtkarsh Saxena <usx@google.com>
Mon, 18 Jul 2022 14:23:28 +0000 (16:23 +0200)
committerUtkarsh Saxena <usx@google.com>
Thu, 28 Jul 2022 03:43:17 +0000 (05:43 +0200)
Differential Revision: https://reviews.llvm.org/D130011

clang-tools-extra/clangd/ClangdServer.cpp

index c3e7242..5ab6cb7 100644 (file)
@@ -834,14 +834,17 @@ void ClangdServer::documentSymbols(llvm::StringRef File,
 
 void ClangdServer::foldingRanges(llvm::StringRef File,
                                  Callback<std::vector<FoldingRange>> CB) {
-  auto Action =
-      [CB = std::move(CB)](llvm::Expected<InputsAndAST> InpAST) mutable {
-        if (!InpAST)
-          return CB(InpAST.takeError());
-        CB(clangd::getFoldingRanges(InpAST->AST));
-      };
-  WorkScheduler->runWithAST("FoldingRanges", File, std::move(Action),
-                            Transient);
+  auto Code = getDraft(File);
+  if (!Code)
+    return CB(llvm::make_error<LSPError>(
+        "trying to compute folding ranges for non-added document",
+        ErrorCode::InvalidParams));
+  auto Action = [CB = std::move(CB), Code = std::move(*Code)]() mutable {
+    CB(clangd::getFoldingRanges(Code));
+  };
+  // We want to make sure folding ranges are always available for all the open
+  // files, hence prefer runQuick to not wait for operations on other files.
+  WorkScheduler->runQuick("FoldingRanges", File, std::move(Action));
 }
 
 void ClangdServer::findType(llvm::StringRef File, Position Pos,