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,