1 //===--- SyncAPI.h - Sync version of ClangdServer's API ----------*- C++-*-===//
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
7 //===----------------------------------------------------------------------===//
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.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_SYNCAPI_H
16 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_SYNCAPI_H
18 #include "ClangdServer.h"
20 #include "index/Index.h"
26 // Calls addDocument and then blockUntilIdleForTest.
27 void runAddDocument(ClangdServer
&Server
, PathRef File
, StringRef Contents
,
28 StringRef Version
= "null",
29 WantDiagnostics WantDiags
= WantDiagnostics::Auto
,
30 bool ForceRebuild
= false);
32 llvm::Expected
<CodeCompleteResult
>
33 runCodeComplete(ClangdServer
&Server
, PathRef File
, Position Pos
,
34 clangd::CodeCompleteOptions Opts
);
36 llvm::Expected
<SignatureHelp
> runSignatureHelp(ClangdServer
&Server
,
37 PathRef File
, Position Pos
,
38 MarkupKind DocumentationFormat
);
40 llvm::Expected
<std::vector
<LocatedSymbol
>>
41 runLocateSymbolAt(ClangdServer
&Server
, PathRef File
, Position Pos
);
43 llvm::Expected
<std::vector
<DocumentHighlight
>>
44 runFindDocumentHighlights(ClangdServer
&Server
, PathRef File
, Position Pos
);
46 llvm::Expected
<RenameResult
> runRename(ClangdServer
&Server
, PathRef File
,
47 Position Pos
, StringRef NewName
,
48 const clangd::RenameOptions
&RenameOpts
);
50 llvm::Expected
<RenameResult
>
51 runPrepareRename(ClangdServer
&Server
, PathRef File
, Position Pos
,
52 std::optional
<std::string
> NewName
,
53 const clangd::RenameOptions
&RenameOpts
);
55 llvm::Expected
<tooling::Replacements
>
56 runFormatFile(ClangdServer
&Server
, PathRef File
, std::optional
<Range
>);
58 SymbolSlab
runFuzzyFind(const SymbolIndex
&Index
, StringRef Query
);
59 SymbolSlab
runFuzzyFind(const SymbolIndex
&Index
, const FuzzyFindRequest
&Req
);
60 RefSlab
getRefs(const SymbolIndex
&Index
, SymbolID ID
);
62 llvm::Expected
<std::vector
<SelectionRange
>>
63 runSemanticRanges(ClangdServer
&Server
, PathRef File
,
64 const std::vector
<Position
> &Pos
);
66 llvm::Expected
<std::optional
<clangd::Path
>>
67 runSwitchHeaderSource(ClangdServer
&Server
, PathRef File
);
69 llvm::Error
runCustomAction(ClangdServer
&Server
, PathRef File
,
70 llvm::function_ref
<void(InputsAndAST
)>);
75 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_SYNCAPI_H