clang-tools  14.0.0git
SyncAPI.h
Go to the documentation of this file.
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",
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
WantDiags
WantDiagnostics WantDiags
Definition: TUScheduler.cpp:459
clang::clangd::runFuzzyFind
SymbolSlab runFuzzyFind(const SymbolIndex &Index, llvm::StringRef Query)
Definition: SyncAPI.cpp:124
clang::clangd::runCodeComplete
llvm::Expected< CodeCompleteResult > runCodeComplete(ClangdServer &Server, PathRef File, Position Pos, clangd::CodeCompleteOptions Opts)
Definition: SyncAPI.cpp:72
clang::clangd::WantDiagnostics::Auto
@ Auto
Diagnostics must not be generated for this snapshot.
Index.h
clang::clangd::runAddDocument
void runAddDocument(ClangdServer &Server, PathRef File, llvm::StringRef Contents, llvm::StringRef Version, WantDiagnostics WantDiags, bool ForceRebuild)
Definition: SyncAPI.cpp:15
clang::clangd::runPrepareRename
llvm::Expected< RenameResult > runPrepareRename(ClangdServer &Server, PathRef File, Position Pos, llvm::Optional< std::string > NewName, const RenameOptions &RenameOpts)
Definition: SyncAPI.cpp:109
clang::clangd::WantDiagnostics
WantDiagnostics
Determines whether diagnostics should be generated for a file snapshot.
Definition: TUScheduler.h:53
clang::clangd::runSemanticRanges
llvm::Expected< std::vector< SelectionRange > > runSemanticRanges(ClangdServer &Server, PathRef File, const std::vector< Position > &Pos)
Definition: SyncAPI.cpp:146
clang::clangd::getRefs
RefSlab getRefs(const SymbolIndex &Index, SymbolID ID)
Definition: SyncAPI.cpp:137
clang::clangd::runLocateSymbolAt
llvm::Expected< std::vector< LocatedSymbol > > runLocateSymbolAt(ClangdServer &Server, PathRef File, Position Pos)
Definition: SyncAPI.cpp:87
clang::clangd::runFormatFile
llvm::Expected< tooling::Replacements > runFormatFile(ClangdServer &Server, PathRef File, llvm::Optional< Range > Rng)
Definition: SyncAPI.cpp:118
clang::clangd::runSwitchHeaderSource
llvm::Expected< llvm::Optional< clangd::Path > > runSwitchHeaderSource(ClangdServer &Server, PathRef File)
Definition: SyncAPI.cpp:154
clang::clangd::runFindDocumentHighlights
llvm::Expected< std::vector< DocumentHighlight > > runFindDocumentHighlights(ClangdServer &Server, PathRef File, Position Pos)
Definition: SyncAPI.cpp:94
clang::doc::SymbolID
std::array< uint8_t, 20 > SymbolID
Definition: Representation.h:30
clang::clangd::runRename
llvm::Expected< RenameResult > runRename(ClangdServer &Server, PathRef File, Position Pos, llvm::StringRef NewName, const RenameOptions &RenameOpts)
Definition: SyncAPI.cpp:100
Index
const SymbolIndex * Index
Definition: Dexp.cpp:99
ID
static char ID
Definition: Logger.cpp:74
clang::clangd::PathRef
llvm::StringRef PathRef
A typedef to represent a ref to file path.
Definition: Path.h:29
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
ClangdServer.h
clang::clangd::runCustomAction
llvm::Error runCustomAction(ClangdServer &Server, PathRef File, llvm::function_ref< void(InputsAndAST)> Action)
Definition: SyncAPI.cpp:160
clang::clangd::runSignatureHelp
llvm::Expected< SignatureHelp > runSignatureHelp(ClangdServer &Server, PathRef File, Position Pos)
Definition: SyncAPI.cpp:79
Pos
Position Pos
Definition: SourceCode.cpp:657