[clang-tools-extra] df537be - Use pseudoparser-based folding ranges in ClangdServer.

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 27 20:44:56 PDT 2022


Author: Utkarsh Saxena
Date: 2022-07-28T05:43:17+02:00
New Revision: df537bef6393042d40275567679ed51c7731e859

URL: https://github.com/llvm/llvm-project/commit/df537bef6393042d40275567679ed51c7731e859
DIFF: https://github.com/llvm/llvm-project/commit/df537bef6393042d40275567679ed51c7731e859.diff

LOG: Use pseudoparser-based folding ranges in ClangdServer.

Differential Revision: https://reviews.llvm.org/D130011

Added: 
    

Modified: 
    clang-tools-extra/clangd/ClangdServer.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp
index c3e7242c19342..5ab6cb7ef6afd 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -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,


        


More information about the cfe-commits mailing list