annotate clang-tools-extra/clangd/CodeComplete.h @ 173:0572611fdcc8 llvm10 llvm12

reorgnization done
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 11:55:54 +0900
parents 1d019706d866
children 2e18cbf3894f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 //===--- CodeComplete.h ------------------------------------------*- C++-*-===//
anatofuz
parents:
diff changeset
2 //
anatofuz
parents:
diff changeset
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
anatofuz
parents:
diff changeset
4 // See https://llvm.org/LICENSE.txt for license information.
anatofuz
parents:
diff changeset
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
anatofuz
parents:
diff changeset
6 //
anatofuz
parents:
diff changeset
7 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
8 //
anatofuz
parents:
diff changeset
9 // Code completion provides suggestions for what the user might type next.
anatofuz
parents:
diff changeset
10 // After "std::string S; S." we might suggest members of std::string.
anatofuz
parents:
diff changeset
11 // Signature help describes the parameters of a function as you type them.
anatofuz
parents:
diff changeset
12 //
anatofuz
parents:
diff changeset
13 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
14
anatofuz
parents:
diff changeset
15 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_CODECOMPLETE_H
anatofuz
parents:
diff changeset
16 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_CODECOMPLETE_H
anatofuz
parents:
diff changeset
17
anatofuz
parents:
diff changeset
18 #include "Headers.h"
anatofuz
parents:
diff changeset
19 #include "Protocol.h"
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
20 #include "Quality.h"
150
anatofuz
parents:
diff changeset
21 #include "index/Index.h"
anatofuz
parents:
diff changeset
22 #include "index/Symbol.h"
anatofuz
parents:
diff changeset
23 #include "index/SymbolOrigin.h"
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
24 #include "support/Logger.h"
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
25 #include "support/Markup.h"
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
26 #include "support/Path.h"
150
anatofuz
parents:
diff changeset
27 #include "clang/Sema/CodeCompleteConsumer.h"
anatofuz
parents:
diff changeset
28 #include "clang/Sema/CodeCompleteOptions.h"
anatofuz
parents:
diff changeset
29 #include "clang/Tooling/CompilationDatabase.h"
anatofuz
parents:
diff changeset
30 #include "llvm/ADT/Optional.h"
anatofuz
parents:
diff changeset
31 #include "llvm/ADT/SmallVector.h"
anatofuz
parents:
diff changeset
32 #include "llvm/ADT/StringRef.h"
anatofuz
parents:
diff changeset
33 #include "llvm/Support/Error.h"
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
34 #include <functional>
150
anatofuz
parents:
diff changeset
35 #include <future>
anatofuz
parents:
diff changeset
36
anatofuz
parents:
diff changeset
37 namespace clang {
anatofuz
parents:
diff changeset
38 class NamedDecl;
anatofuz
parents:
diff changeset
39 namespace clangd {
anatofuz
parents:
diff changeset
40 struct PreambleData;
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
41 struct CodeCompletion;
150
anatofuz
parents:
diff changeset
42
anatofuz
parents:
diff changeset
43 struct CodeCompleteOptions {
anatofuz
parents:
diff changeset
44 /// Returns options that can be passed to clang's completion engine.
anatofuz
parents:
diff changeset
45 clang::CodeCompleteOptions getClangCompleteOpts() const;
anatofuz
parents:
diff changeset
46
anatofuz
parents:
diff changeset
47 /// When true, completion items will contain expandable code snippets in
anatofuz
parents:
diff changeset
48 /// completion (e.g. `return ${1:expression}` or `foo(${1:int a}, ${2:int
anatofuz
parents:
diff changeset
49 /// b})).
anatofuz
parents:
diff changeset
50 bool EnableSnippets = false;
anatofuz
parents:
diff changeset
51
anatofuz
parents:
diff changeset
52 /// Add code patterns to completion results.
anatofuz
parents:
diff changeset
53 /// If EnableSnippets is false, this options is ignored and code patterns will
anatofuz
parents:
diff changeset
54 /// always be omitted.
anatofuz
parents:
diff changeset
55 bool IncludeCodePatterns = true;
anatofuz
parents:
diff changeset
56
anatofuz
parents:
diff changeset
57 /// Add macros to code completion results.
anatofuz
parents:
diff changeset
58 bool IncludeMacros = true;
anatofuz
parents:
diff changeset
59
anatofuz
parents:
diff changeset
60 /// Add comments to code completion results, if available.
anatofuz
parents:
diff changeset
61 bool IncludeComments = true;
anatofuz
parents:
diff changeset
62
anatofuz
parents:
diff changeset
63 /// Include results that are not legal completions in the current context.
anatofuz
parents:
diff changeset
64 /// For example, private members are usually inaccessible.
anatofuz
parents:
diff changeset
65 bool IncludeIneligibleResults = false;
anatofuz
parents:
diff changeset
66
anatofuz
parents:
diff changeset
67 /// Combine overloads into a single completion item where possible.
anatofuz
parents:
diff changeset
68 /// If none, the implementation may choose an appropriate behavior.
anatofuz
parents:
diff changeset
69 /// (In practice, ClangdLSPServer enables bundling if the client claims
anatofuz
parents:
diff changeset
70 /// to supports signature help).
anatofuz
parents:
diff changeset
71 llvm::Optional<bool> BundleOverloads;
anatofuz
parents:
diff changeset
72
anatofuz
parents:
diff changeset
73 /// Limit the number of results returned (0 means no limit).
anatofuz
parents:
diff changeset
74 /// If more results are available, we set CompletionList.isIncomplete.
anatofuz
parents:
diff changeset
75 size_t Limit = 0;
anatofuz
parents:
diff changeset
76
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
77 /// Whether to present doc comments as plain-text or markdown.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
78 MarkupKind DocumentationFormat = MarkupKind::PlainText;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
79
150
anatofuz
parents:
diff changeset
80 enum IncludeInsertion {
anatofuz
parents:
diff changeset
81 IWYU,
anatofuz
parents:
diff changeset
82 NeverInsert,
anatofuz
parents:
diff changeset
83 } InsertIncludes = IncludeInsertion::IWYU;
anatofuz
parents:
diff changeset
84
anatofuz
parents:
diff changeset
85 /// A visual indicator to prepend to the completion label to indicate whether
anatofuz
parents:
diff changeset
86 /// completion result would trigger an #include insertion or not.
anatofuz
parents:
diff changeset
87 struct IncludeInsertionIndicator {
anatofuz
parents:
diff changeset
88 std::string Insert = "•";
anatofuz
parents:
diff changeset
89 std::string NoInsert = " ";
anatofuz
parents:
diff changeset
90 } IncludeIndicator;
anatofuz
parents:
diff changeset
91
anatofuz
parents:
diff changeset
92 /// Expose origins of completion items in the label (for debugging).
anatofuz
parents:
diff changeset
93 bool ShowOrigins = false;
anatofuz
parents:
diff changeset
94
anatofuz
parents:
diff changeset
95 /// If set to true, this will send an asynchronous speculative index request,
anatofuz
parents:
diff changeset
96 /// based on the index request for the last code completion on the same file
anatofuz
parents:
diff changeset
97 /// and the filter text typed before the cursor, before sema code completion
anatofuz
parents:
diff changeset
98 /// is invoked. This can reduce the code completion latency (by roughly
anatofuz
parents:
diff changeset
99 /// latency of sema code completion) if the speculative request is the same as
anatofuz
parents:
diff changeset
100 /// the one generated for the ongoing code completion from sema. As a sequence
anatofuz
parents:
diff changeset
101 /// of code completions often have the same scopes and proximity paths etc,
anatofuz
parents:
diff changeset
102 /// this should be effective for a number of code completions.
anatofuz
parents:
diff changeset
103 bool SpeculativeIndexRequest = false;
anatofuz
parents:
diff changeset
104
anatofuz
parents:
diff changeset
105 // Populated internally by clangd, do not set.
anatofuz
parents:
diff changeset
106 /// If `Index` is set, it is used to augment the code completion
anatofuz
parents:
diff changeset
107 /// results.
anatofuz
parents:
diff changeset
108 /// FIXME(ioeric): we might want a better way to pass the index around inside
anatofuz
parents:
diff changeset
109 /// clangd.
anatofuz
parents:
diff changeset
110 const SymbolIndex *Index = nullptr;
anatofuz
parents:
diff changeset
111
anatofuz
parents:
diff changeset
112 /// Include completions that require small corrections, e.g. change '.' to
anatofuz
parents:
diff changeset
113 /// '->' on member access etc.
anatofuz
parents:
diff changeset
114 bool IncludeFixIts = false;
anatofuz
parents:
diff changeset
115
anatofuz
parents:
diff changeset
116 /// Whether to generate snippets for function arguments on code-completion.
anatofuz
parents:
diff changeset
117 /// Needs snippets to be enabled as well.
anatofuz
parents:
diff changeset
118 bool EnableFunctionArgSnippets = true;
anatofuz
parents:
diff changeset
119
anatofuz
parents:
diff changeset
120 /// Whether to include index symbols that are not defined in the scopes
anatofuz
parents:
diff changeset
121 /// visible from the code completion point. This applies in contexts without
anatofuz
parents:
diff changeset
122 /// explicit scope qualifiers.
anatofuz
parents:
diff changeset
123 ///
anatofuz
parents:
diff changeset
124 /// Such completions can insert scope qualifiers.
anatofuz
parents:
diff changeset
125 bool AllScopes = false;
anatofuz
parents:
diff changeset
126
anatofuz
parents:
diff changeset
127 /// Whether to use the clang parser, or fallback to text-based completion
anatofuz
parents:
diff changeset
128 /// (using identifiers in the current file and symbol indexes).
anatofuz
parents:
diff changeset
129 enum CodeCompletionParse {
anatofuz
parents:
diff changeset
130 /// Block until we can run the parser (e.g. preamble is built).
anatofuz
parents:
diff changeset
131 /// Return an error if this fails.
anatofuz
parents:
diff changeset
132 AlwaysParse,
anatofuz
parents:
diff changeset
133 /// Run the parser if inputs (preamble) are ready.
anatofuz
parents:
diff changeset
134 /// Otherwise, use text-based completion.
anatofuz
parents:
diff changeset
135 ParseIfReady,
anatofuz
parents:
diff changeset
136 /// Always use text-based completion.
anatofuz
parents:
diff changeset
137 NeverParse,
anatofuz
parents:
diff changeset
138 } RunParser = ParseIfReady;
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
139
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
140 /// Callback invoked on all CompletionCandidate after they are scored and
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
141 /// before they are ranked (by -Score). Thus the results are yielded in
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
142 /// arbitrary order.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
143 ///
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
144 /// This callbacks allows capturing various internal structures used by clangd
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
145 /// during code completion. Eg: Symbol quality and relevance signals.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
146 std::function<void(const CodeCompletion &, const SymbolQualitySignals &,
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
147 const SymbolRelevanceSignals &, float Score)>
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
148 RecordCCResult;
150
anatofuz
parents:
diff changeset
149 };
anatofuz
parents:
diff changeset
150
anatofuz
parents:
diff changeset
151 // Semi-structured representation of a code-complete suggestion for our C++ API.
anatofuz
parents:
diff changeset
152 // We don't use the LSP structures here (unlike most features) as we want
anatofuz
parents:
diff changeset
153 // to expose more data to allow for more precise testing and evaluation.
anatofuz
parents:
diff changeset
154 struct CodeCompletion {
anatofuz
parents:
diff changeset
155 // The unqualified name of the symbol or other completion item.
anatofuz
parents:
diff changeset
156 std::string Name;
anatofuz
parents:
diff changeset
157 // The scope qualifier for the symbol name. e.g. "ns1::ns2::"
anatofuz
parents:
diff changeset
158 // Empty for non-symbol completions. Not inserted, but may be displayed.
anatofuz
parents:
diff changeset
159 std::string Scope;
anatofuz
parents:
diff changeset
160 // Text that must be inserted before the name, and displayed (e.g. base::).
anatofuz
parents:
diff changeset
161 std::string RequiredQualifier;
anatofuz
parents:
diff changeset
162 // Details to be displayed following the name. Not inserted.
anatofuz
parents:
diff changeset
163 std::string Signature;
anatofuz
parents:
diff changeset
164 // Text to be inserted following the name, in snippet format.
anatofuz
parents:
diff changeset
165 std::string SnippetSuffix;
anatofuz
parents:
diff changeset
166 // Type to be displayed for this completion.
anatofuz
parents:
diff changeset
167 std::string ReturnType;
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
168 // The parsed documentation comment.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
169 llvm::Optional<markup::Document> Documentation;
150
anatofuz
parents:
diff changeset
170 CompletionItemKind Kind = CompletionItemKind::Missing;
anatofuz
parents:
diff changeset
171 // This completion item may represent several symbols that can be inserted in
anatofuz
parents:
diff changeset
172 // the same way, such as function overloads. In this case BundleSize > 1, and
anatofuz
parents:
diff changeset
173 // the following fields are summaries:
anatofuz
parents:
diff changeset
174 // - Signature is e.g. "(...)" for functions.
anatofuz
parents:
diff changeset
175 // - SnippetSuffix is similarly e.g. "(${0})".
anatofuz
parents:
diff changeset
176 // - ReturnType may be empty
anatofuz
parents:
diff changeset
177 // - Documentation may be from one symbol, or a combination of several
anatofuz
parents:
diff changeset
178 // Other fields should apply equally to all bundled completions.
anatofuz
parents:
diff changeset
179 unsigned BundleSize = 1;
anatofuz
parents:
diff changeset
180 SymbolOrigin Origin = SymbolOrigin::Unknown;
anatofuz
parents:
diff changeset
181
anatofuz
parents:
diff changeset
182 struct IncludeCandidate {
anatofuz
parents:
diff changeset
183 // The header through which this symbol could be included.
anatofuz
parents:
diff changeset
184 // Quoted string as expected by an #include directive, e.g. "<memory>".
anatofuz
parents:
diff changeset
185 // Empty for non-symbol completions, or when not known.
anatofuz
parents:
diff changeset
186 std::string Header;
anatofuz
parents:
diff changeset
187 // Present if Header should be inserted to use this item.
anatofuz
parents:
diff changeset
188 llvm::Optional<TextEdit> Insertion;
anatofuz
parents:
diff changeset
189 };
anatofuz
parents:
diff changeset
190 // All possible include headers ranked by preference. By default, the first
anatofuz
parents:
diff changeset
191 // include is used.
anatofuz
parents:
diff changeset
192 // If we've bundled together overloads that have different sets of includes,
anatofuz
parents:
diff changeset
193 // thse includes may not be accurate for all of them.
anatofuz
parents:
diff changeset
194 llvm::SmallVector<IncludeCandidate, 1> Includes;
anatofuz
parents:
diff changeset
195
anatofuz
parents:
diff changeset
196 /// Holds information about small corrections that needs to be done. Like
anatofuz
parents:
diff changeset
197 /// converting '->' to '.' on member access.
anatofuz
parents:
diff changeset
198 std::vector<TextEdit> FixIts;
anatofuz
parents:
diff changeset
199
anatofuz
parents:
diff changeset
200 /// Holds the range of the token we are going to replace with this completion.
anatofuz
parents:
diff changeset
201 Range CompletionTokenRange;
anatofuz
parents:
diff changeset
202
anatofuz
parents:
diff changeset
203 // Scores are used to rank completion items.
anatofuz
parents:
diff changeset
204 struct Scores {
anatofuz
parents:
diff changeset
205 // The score that items are ranked by.
anatofuz
parents:
diff changeset
206 float Total = 0.f;
anatofuz
parents:
diff changeset
207
anatofuz
parents:
diff changeset
208 // The finalScore with the fuzzy name match score excluded.
anatofuz
parents:
diff changeset
209 // When filtering client-side, editors should calculate the new fuzzy score,
anatofuz
parents:
diff changeset
210 // whose scale is 0-1 (with 1 = prefix match, special case 2 = exact match),
anatofuz
parents:
diff changeset
211 // and recompute finalScore = fuzzyScore * symbolScore.
anatofuz
parents:
diff changeset
212 float ExcludingName = 0.f;
anatofuz
parents:
diff changeset
213
anatofuz
parents:
diff changeset
214 // Component scores that contributed to the final score:
anatofuz
parents:
diff changeset
215
anatofuz
parents:
diff changeset
216 // Quality describes how important we think this candidate is,
anatofuz
parents:
diff changeset
217 // independent of the query.
anatofuz
parents:
diff changeset
218 // e.g. symbols with lots of incoming references have higher quality.
anatofuz
parents:
diff changeset
219 float Quality = 0.f;
anatofuz
parents:
diff changeset
220 // Relevance describes how well this candidate matched the query.
anatofuz
parents:
diff changeset
221 // e.g. symbols from nearby files have higher relevance.
anatofuz
parents:
diff changeset
222 float Relevance = 0.f;
anatofuz
parents:
diff changeset
223 };
anatofuz
parents:
diff changeset
224 Scores Score;
anatofuz
parents:
diff changeset
225
anatofuz
parents:
diff changeset
226 /// Indicates if this item is deprecated.
anatofuz
parents:
diff changeset
227 bool Deprecated = false;
anatofuz
parents:
diff changeset
228
anatofuz
parents:
diff changeset
229 // Serialize this to an LSP completion item. This is a lossy operation.
anatofuz
parents:
diff changeset
230 CompletionItem render(const CodeCompleteOptions &) const;
anatofuz
parents:
diff changeset
231 };
anatofuz
parents:
diff changeset
232 raw_ostream &operator<<(raw_ostream &, const CodeCompletion &);
anatofuz
parents:
diff changeset
233 struct CodeCompleteResult {
anatofuz
parents:
diff changeset
234 std::vector<CodeCompletion> Completions;
anatofuz
parents:
diff changeset
235 bool HasMore = false;
anatofuz
parents:
diff changeset
236 CodeCompletionContext::Kind Context = CodeCompletionContext::CCC_Other;
anatofuz
parents:
diff changeset
237 // The text that is being directly completed.
anatofuz
parents:
diff changeset
238 // Example: foo.pb^ -> foo.push_back()
anatofuz
parents:
diff changeset
239 // ~~
anatofuz
parents:
diff changeset
240 // Typically matches the textEdit.range of Completions, but not guaranteed to.
anatofuz
parents:
diff changeset
241 llvm::Optional<Range> CompletionRange;
anatofuz
parents:
diff changeset
242 // Usually the source will be parsed with a real C++ parser.
anatofuz
parents:
diff changeset
243 // But heuristics may be used instead if e.g. the preamble is not ready.
anatofuz
parents:
diff changeset
244 bool RanParser = true;
anatofuz
parents:
diff changeset
245 };
anatofuz
parents:
diff changeset
246 raw_ostream &operator<<(raw_ostream &, const CodeCompleteResult &);
anatofuz
parents:
diff changeset
247
anatofuz
parents:
diff changeset
248 /// A speculative and asynchronous fuzzy find index request (based on cached
anatofuz
parents:
diff changeset
249 /// request) that can be sent before parsing sema. This would reduce completion
anatofuz
parents:
diff changeset
250 /// latency if the speculation succeeds.
anatofuz
parents:
diff changeset
251 struct SpeculativeFuzzyFind {
anatofuz
parents:
diff changeset
252 /// A cached request from past code completions.
anatofuz
parents:
diff changeset
253 /// Set by caller of `codeComplete()`.
anatofuz
parents:
diff changeset
254 llvm::Optional<FuzzyFindRequest> CachedReq;
anatofuz
parents:
diff changeset
255 /// The actual request used by `codeComplete()`.
anatofuz
parents:
diff changeset
256 /// Set by `codeComplete()`. This can be used by callers to update cache.
anatofuz
parents:
diff changeset
257 llvm::Optional<FuzzyFindRequest> NewReq;
anatofuz
parents:
diff changeset
258 /// The result is consumed by `codeComplete()` if speculation succeeded.
anatofuz
parents:
diff changeset
259 /// NOTE: the destructor will wait for the async call to finish.
anatofuz
parents:
diff changeset
260 std::future<SymbolSlab> Result;
anatofuz
parents:
diff changeset
261 };
anatofuz
parents:
diff changeset
262
anatofuz
parents:
diff changeset
263 /// Gets code completions at a specified \p Pos in \p FileName.
anatofuz
parents:
diff changeset
264 ///
anatofuz
parents:
diff changeset
265 /// If \p Preamble is nullptr, this runs code completion without compiling the
anatofuz
parents:
diff changeset
266 /// code.
anatofuz
parents:
diff changeset
267 ///
anatofuz
parents:
diff changeset
268 /// If \p SpecFuzzyFind is set, a speculative and asynchronous fuzzy find index
anatofuz
parents:
diff changeset
269 /// request (based on cached request) will be run before parsing sema. In case
anatofuz
parents:
diff changeset
270 /// the speculative result is used by code completion (e.g. speculation failed),
anatofuz
parents:
diff changeset
271 /// the speculative result is not consumed, and `SpecFuzzyFind` is only
anatofuz
parents:
diff changeset
272 /// destroyed when the async request finishes.
anatofuz
parents:
diff changeset
273 CodeCompleteResult codeComplete(PathRef FileName,
anatofuz
parents:
diff changeset
274 const tooling::CompileCommand &Command,
anatofuz
parents:
diff changeset
275 const PreambleData *Preamble,
anatofuz
parents:
diff changeset
276 StringRef Contents, Position Pos,
anatofuz
parents:
diff changeset
277 IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
anatofuz
parents:
diff changeset
278 CodeCompleteOptions Opts,
anatofuz
parents:
diff changeset
279 SpeculativeFuzzyFind *SpecFuzzyFind = nullptr);
anatofuz
parents:
diff changeset
280
anatofuz
parents:
diff changeset
281 /// Get signature help at a specified \p Pos in \p FileName.
anatofuz
parents:
diff changeset
282 SignatureHelp signatureHelp(PathRef FileName,
anatofuz
parents:
diff changeset
283 const tooling::CompileCommand &Command,
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
284 const PreambleData &Preamble, StringRef Contents,
150
anatofuz
parents:
diff changeset
285 Position Pos,
anatofuz
parents:
diff changeset
286 IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
anatofuz
parents:
diff changeset
287 const SymbolIndex *Index);
anatofuz
parents:
diff changeset
288
anatofuz
parents:
diff changeset
289 // For index-based completion, we only consider:
anatofuz
parents:
diff changeset
290 // * symbols in namespaces or translation unit scopes (e.g. no class
anatofuz
parents:
diff changeset
291 // members, no locals)
anatofuz
parents:
diff changeset
292 // * enum constants in unscoped enum decl (e.g. "red" in "enum {red};")
anatofuz
parents:
diff changeset
293 // * primary templates (no specializations)
anatofuz
parents:
diff changeset
294 // For the other cases, we let Clang do the completion because it does not
anatofuz
parents:
diff changeset
295 // need any non-local information and it will be much better at following
anatofuz
parents:
diff changeset
296 // lookup rules. Other symbols still appear in the index for other purposes,
anatofuz
parents:
diff changeset
297 // like workspace/symbols or textDocument/definition, but are not used for code
anatofuz
parents:
diff changeset
298 // completion.
anatofuz
parents:
diff changeset
299 bool isIndexedForCodeCompletion(const NamedDecl &ND, ASTContext &ASTCtx);
anatofuz
parents:
diff changeset
300
anatofuz
parents:
diff changeset
301 // Text immediately before the completion point that should be completed.
anatofuz
parents:
diff changeset
302 // This is heuristically derived from the source code, and is used when:
anatofuz
parents:
diff changeset
303 // - semantic analysis fails
anatofuz
parents:
diff changeset
304 // - semantic analysis may be slow, and we speculatively query the index
anatofuz
parents:
diff changeset
305 struct CompletionPrefix {
anatofuz
parents:
diff changeset
306 // The unqualified partial name.
anatofuz
parents:
diff changeset
307 // If there is none, begin() == end() == completion position.
anatofuz
parents:
diff changeset
308 llvm::StringRef Name;
anatofuz
parents:
diff changeset
309 // The spelled scope qualifier, such as Foo::.
anatofuz
parents:
diff changeset
310 // If there is none, begin() == end() == Name.begin().
anatofuz
parents:
diff changeset
311 llvm::StringRef Qualifier;
anatofuz
parents:
diff changeset
312 };
anatofuz
parents:
diff changeset
313 // Heuristically parses before Offset to determine what should be completed.
anatofuz
parents:
diff changeset
314 CompletionPrefix guessCompletionPrefix(llvm::StringRef Content,
anatofuz
parents:
diff changeset
315 unsigned Offset);
anatofuz
parents:
diff changeset
316
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
317 // Whether it makes sense to complete at the point based on typed characters.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
318 // For instance, we implicitly trigger at `a->^` but not at `a>^`.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
319 bool allowImplicitCompletion(llvm::StringRef Content, unsigned Offset);
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
320
150
anatofuz
parents:
diff changeset
321 } // namespace clangd
anatofuz
parents:
diff changeset
322 } // namespace clang
anatofuz
parents:
diff changeset
323
anatofuz
parents:
diff changeset
324 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_CODECOMPLETE_H