1 //===--- SyncAPI.h - Sync version of ClangdServer's API ----------*- C++-*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains synchronous versions of ClangdServer's async API. We
10 // deliberately don't expose the sync API outside tests to encourage using the
11 // async versions in clangd code.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_SYNCAPI_H
16 #define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_SYNCAPI_H
17 
18 #include "ClangdServer.h"
19 #include "index/Index.h"
20 
21 namespace clang {
22 namespace clangd {
23 
24 // Calls addDocument and then blockUntilIdleForTest.
25 void runAddDocument(ClangdServer &Server, PathRef File, StringRef Contents,
26                     StringRef Version = "null",
27                     WantDiagnostics WantDiags = WantDiagnostics::Auto,
28                     bool ForceRebuild = false);
29 
30 llvm::Expected<CodeCompleteResult>
31 runCodeComplete(ClangdServer &Server, PathRef File, Position Pos,
32                 clangd::CodeCompleteOptions Opts);
33 
34 llvm::Expected<SignatureHelp> runSignatureHelp(ClangdServer &Server,
35                                                PathRef File, Position Pos);
36 
37 llvm::Expected<std::vector<LocatedSymbol>>
38 runLocateSymbolAt(ClangdServer &Server, PathRef File, Position Pos);
39 
40 llvm::Expected<std::vector<DocumentHighlight>>
41 runFindDocumentHighlights(ClangdServer &Server, PathRef File, Position Pos);
42 
43 llvm::Expected<RenameResult> runRename(ClangdServer &Server, PathRef File,
44                                        Position Pos, StringRef NewName,
45                                        const clangd::RenameOptions &RenameOpts);
46 
47 llvm::Expected<RenameResult>
48 runPrepareRename(ClangdServer &Server, PathRef File, Position Pos,
49                  llvm::Optional<std::string> NewName,
50                  const clangd::RenameOptions &RenameOpts);
51 
52 llvm::Expected<tooling::Replacements>
53 runFormatFile(ClangdServer &Server, PathRef File, llvm::Optional<Range>);
54 
55 SymbolSlab runFuzzyFind(const SymbolIndex &Index, StringRef Query);
56 SymbolSlab runFuzzyFind(const SymbolIndex &Index, const FuzzyFindRequest &Req);
57 RefSlab getRefs(const SymbolIndex &Index, SymbolID ID);
58 
59 llvm::Expected<std::vector<SelectionRange>>
60 runSemanticRanges(ClangdServer &Server, PathRef File,
61                   const std::vector<Position> &Pos);
62 
63 llvm::Expected<llvm::Optional<clangd::Path>>
64 runSwitchHeaderSource(ClangdServer &Server, PathRef File);
65 
66 llvm::Error runCustomAction(ClangdServer &Server, PathRef File,
67                             llvm::function_ref<void(InputsAndAST)>);
68 
69 } // namespace clangd
70 } // namespace clang
71 
72 #endif // LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_SYNCAPI_H
73