clang-tools  15.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_CLANGD_UNITTESTS_SYNCAPI_H
16 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_SYNCAPI_H
17 
18 #include "ClangdServer.h"
19 #include "Protocol.h"
20 #include "index/Index.h"
21 
22 namespace clang {
23 namespace clangd {
24 
25 // Calls addDocument and then blockUntilIdleForTest.
26 void runAddDocument(ClangdServer &Server, PathRef File, StringRef Contents,
27  StringRef Version = "null",
29  bool ForceRebuild = false);
30 
31 llvm::Expected<CodeCompleteResult>
32 runCodeComplete(ClangdServer &Server, PathRef File, Position Pos,
33  clangd::CodeCompleteOptions Opts);
34 
35 llvm::Expected<SignatureHelp> runSignatureHelp(ClangdServer &Server,
36  PathRef File, Position Pos,
37  MarkupKind DocumentationFormat);
38 
39 llvm::Expected<std::vector<LocatedSymbol>>
40 runLocateSymbolAt(ClangdServer &Server, PathRef File, Position Pos);
41 
42 llvm::Expected<std::vector<DocumentHighlight>>
43 runFindDocumentHighlights(ClangdServer &Server, PathRef File, Position Pos);
44 
45 llvm::Expected<RenameResult> runRename(ClangdServer &Server, PathRef File,
46  Position Pos, StringRef NewName,
47  const clangd::RenameOptions &RenameOpts);
48 
49 llvm::Expected<RenameResult>
50 runPrepareRename(ClangdServer &Server, PathRef File, Position Pos,
51  llvm::Optional<std::string> NewName,
52  const clangd::RenameOptions &RenameOpts);
53 
54 llvm::Expected<tooling::Replacements>
55 runFormatFile(ClangdServer &Server, PathRef File, llvm::Optional<Range>);
56 
57 SymbolSlab runFuzzyFind(const SymbolIndex &Index, StringRef Query);
58 SymbolSlab runFuzzyFind(const SymbolIndex &Index, const FuzzyFindRequest &Req);
59 RefSlab getRefs(const SymbolIndex &Index, SymbolID ID);
60 
61 llvm::Expected<std::vector<SelectionRange>>
62 runSemanticRanges(ClangdServer &Server, PathRef File,
63  const std::vector<Position> &Pos);
64 
65 llvm::Expected<llvm::Optional<clangd::Path>>
66 runSwitchHeaderSource(ClangdServer &Server, PathRef File);
67 
68 llvm::Error runCustomAction(ClangdServer &Server, PathRef File,
69  llvm::function_ref<void(InputsAndAST)>);
70 
71 } // namespace clangd
72 } // namespace clang
73 
74 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_SYNCAPI_H
WantDiags
WantDiagnostics WantDiags
Definition: TUScheduler.cpp:494
clang::clangd::runFuzzyFind
SymbolSlab runFuzzyFind(const SymbolIndex &Index, llvm::StringRef Query)
Definition: SyncAPI.cpp:126
clang::clangd::runCodeComplete
llvm::Expected< CodeCompleteResult > runCodeComplete(ClangdServer &Server, PathRef File, Position Pos, clangd::CodeCompleteOptions Opts)
Definition: SyncAPI.cpp:73
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:16
clang::clangd::runPrepareRename
llvm::Expected< RenameResult > runPrepareRename(ClangdServer &Server, PathRef File, Position Pos, llvm::Optional< std::string > NewName, const RenameOptions &RenameOpts)
Definition: SyncAPI.cpp:111
Pos
size_t Pos
Definition: NoLintDirectiveHandler.cpp:97
clang::clangd::WantDiagnostics
WantDiagnostics
Determines whether diagnostics should be generated for a file snapshot.
Definition: TUScheduler.h:52
clang::clangd::runSemanticRanges
llvm::Expected< std::vector< SelectionRange > > runSemanticRanges(ClangdServer &Server, PathRef File, const std::vector< Position > &Pos)
Definition: SyncAPI.cpp:148
Protocol.h
clang::clangd::getRefs
RefSlab getRefs(const SymbolIndex &Index, SymbolID ID)
Definition: SyncAPI.cpp:139
clang::clangd::runLocateSymbolAt
llvm::Expected< std::vector< LocatedSymbol > > runLocateSymbolAt(ClangdServer &Server, PathRef File, Position Pos)
Definition: SyncAPI.cpp:89
clang::clangd::runFormatFile
llvm::Expected< tooling::Replacements > runFormatFile(ClangdServer &Server, PathRef File, llvm::Optional< Range > Rng)
Definition: SyncAPI.cpp:120
clang::clangd::runSwitchHeaderSource
llvm::Expected< llvm::Optional< clangd::Path > > runSwitchHeaderSource(ClangdServer &Server, PathRef File)
Definition: SyncAPI.cpp:156
clang::clangd::runFindDocumentHighlights
llvm::Expected< std::vector< DocumentHighlight > > runFindDocumentHighlights(ClangdServer &Server, PathRef File, Position Pos)
Definition: SyncAPI.cpp:96
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:102
Index
const SymbolIndex * Index
Definition: Dexp.cpp:98
clang::clangd::MarkupKind
MarkupKind
Definition: Protocol.h:392
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::runSignatureHelp
llvm::Expected< SignatureHelp > runSignatureHelp(ClangdServer &Server, PathRef File, Position Pos, MarkupKind DocumentationFormat)
Definition: SyncAPI.cpp:80
clang::clangd::runCustomAction
llvm::Error runCustomAction(ClangdServer &Server, PathRef File, llvm::function_ref< void(InputsAndAST)> Action)
Definition: SyncAPI.cpp:162