diff options
Diffstat (limited to 'clang-tools-extra/clangd/CodeComplete.h')
| -rw-r--r-- | clang-tools-extra/clangd/CodeComplete.h | 80 |
1 files changed, 72 insertions, 8 deletions
diff --git a/clang-tools-extra/clangd/CodeComplete.h b/clang-tools-extra/clangd/CodeComplete.h index f89aad76cfe..78a78b82047 100644 --- a/clang-tools-extra/clangd/CodeComplete.h +++ b/clang-tools-extra/clangd/CodeComplete.h @@ -75,15 +75,79 @@ struct CodeCompleteOptions { const SymbolIndex *Index = nullptr; }; +// Semi-structured representation of a code-complete suggestion for our C++ API. +// We don't use the LSP structures here (unlike most features) as we want +// to expose more data to allow for more precise testing and evaluation. +struct CodeCompletion { + // The unqualified name of the symbol or other completion item. + std::string Name; + // The scope qualifier for the symbol name. e.g. "ns1::ns2::" + // Empty for non-symbol completions. Not inserted, but may be displayed. + std::string Scope; + // Text that must be inserted before the name, and displayed (e.g. base::). + std::string RequiredQualifier; + // Details to be displayed following the name. Not inserted. + std::string Signature; + // Text to be inserted following the name, in snippet format. + std::string SnippetSuffix; + // Type to be displayed for this completion. + std::string ReturnType; + std::string Documentation; + CompletionItemKind Kind = CompletionItemKind::Missing; + // This completion item may represent several symbols that can be inserted in + // the same way, such as function overloads. In this case BundleSize > 1, and + // the following fields are summaries: + // - Signature is e.g. "(...)" for functions. + // - SnippetSuffix is similarly e.g. "(${0})". + // - ReturnType may be empty + // - Documentation may be from one symbol, or a combination of several + // Other fields should apply equally to all bundled completions. + unsigned BundleSize; + // The header through which this symbol could be included. + // Quoted string as expected by an #include directive, e.g. "<memory>". + // Empty for non-symbol completions, or when not known. + std::string Header; + // Present if Header is set and should be inserted to use this item. + llvm::Optional<TextEdit> HeaderInsertion; + + // Scores are used to rank completion items. + struct Scores { + // The score that items are ranked by. + float Total = 0.f; + + // The finalScore with the fuzzy name match score excluded. + // When filtering client-side, editors should calculate the new fuzzy score, + // whose scale is 0-1 (with 1 = prefix match, special case 2 = exact match), + // and recompute finalScore = fuzzyScore * symbolScore. + float ExcludingName = 0.f; + + // Component scores that contributed to the final score: + + // Quality describes how important we think this candidate is, + // independent of the query. + // e.g. symbols with lots of incoming references have higher quality. + float Quality = 0.f; + // Relevance describes how well this candidate matched the query. + // e.g. symbols from nearby files have higher relevance. + float Relevance = 0.f; + }; + Scores Score; + + // Serialize this to an LSP completion item. This is a lossy operation. + CompletionItem render(const CodeCompleteOptions &) const; +}; +struct CodeCompleteResult { + std::vector<CodeCompletion> Completions; + bool HasMore = false; +}; + /// Get code completions at a specified \p Pos in \p FileName. -CompletionList codeComplete(PathRef FileName, - const tooling::CompileCommand &Command, - PrecompiledPreamble const *Preamble, - const std::vector<Inclusion> &PreambleInclusions, - StringRef Contents, Position Pos, - IntrusiveRefCntPtr<vfs::FileSystem> VFS, - std::shared_ptr<PCHContainerOperations> PCHs, - CodeCompleteOptions Opts); +CodeCompleteResult codeComplete( + PathRef FileName, const tooling::CompileCommand &Command, + PrecompiledPreamble const *Preamble, + const std::vector<Inclusion> &PreambleInclusions, StringRef Contents, + Position Pos, IntrusiveRefCntPtr<vfs::FileSystem> VFS, + std::shared_ptr<PCHContainerOperations> PCHs, CodeCompleteOptions Opts); /// Get signature help at a specified \p Pos in \p FileName. SignatureHelp signatureHelp(PathRef FileName, |

