[clangd] More precise representation of symbol names/labels in the index.
Summary:
Previously, the strings matched LSP completion pretty closely.
The completion label was a single string, for instance. This made
implementing completion itself easy but makes it hard to use the names
in other way, e.g. pretty-printed name in synthesized
documentation/hover.
It also limits our introspection into completion items, which can only
be as precise as the indexed symbols. This change is a prerequisite to
improvements to overload bundling which need to inspect e.g. signature
structure.
Reviewers: ioeric
Subscribers: ilya-biryukov, MaskRay, jkorous, cfe-commits
Differential Revision: https://reviews.llvm.org/D48475
llvm-svn: 335360
diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp
index 647e02d..d2e71b6 100644
--- a/clang-tools-extra/clangd/CodeComplete.cpp
+++ b/clang-tools-extra/clangd/CodeComplete.cpp
@@ -249,17 +249,21 @@
CompletionItem I;
bool InsertingInclude = false; // Whether a new #include will be added.
if (SemaResult) {
- I.kind = toCompletionItemKind(SemaResult->Kind, SemaResult->Declaration);
- getLabelAndInsertText(*SemaCCS, &I.label, &I.insertText,
- Opts.EnableSnippets);
- if (const char* Text = SemaCCS->getTypedText())
- I.filterText = Text;
+ llvm::StringRef Name(SemaCCS->getTypedText());
+ std::string Signature, SnippetSuffix, Qualifiers;
+ getSignature(*SemaCCS, &Signature, &SnippetSuffix, &Qualifiers);
+ I.label = (Qualifiers + Name + Signature).str();
+ I.filterText = Name;
+ I.insertText = (Qualifiers + Name).str();
+ if (Opts.EnableSnippets)
+ I.insertText += SnippetSuffix;
I.documentation = formatDocumentation(*SemaCCS, SemaDocComment);
- I.detail = getDetail(*SemaCCS);
+ I.detail = getReturnType(*SemaCCS);
if (SemaResult->Kind == CodeCompletionResult::RK_Declaration)
if (const auto *D = SemaResult->getDeclaration())
if (const auto *ND = llvm::dyn_cast<NamedDecl>(D))
I.SymbolScope = splitQualifiedName(printQualifiedName(*ND)).first;
+ I.kind = toCompletionItemKind(SemaResult->Kind, SemaResult->Declaration);
}
if (IndexResult) {
if (I.SymbolScope.empty())
@@ -268,21 +272,22 @@
I.kind = toCompletionItemKind(IndexResult->SymInfo.Kind);
// FIXME: reintroduce a way to show the index source for debugging.
if (I.label.empty())
- I.label = IndexResult->CompletionLabel;
+ I.label = (IndexResult->Name + IndexResult->Signature).str();
if (I.filterText.empty())
I.filterText = IndexResult->Name;
// FIXME(ioeric): support inserting/replacing scope qualifiers.
- if (I.insertText.empty())
- I.insertText = Opts.EnableSnippets
- ? IndexResult->CompletionSnippetInsertText
- : IndexResult->CompletionPlainInsertText;
+ if (I.insertText.empty()) {
+ I.insertText = IndexResult->Name;
+ if (Opts.EnableSnippets)
+ I.insertText += IndexResult->CompletionSnippetSuffix;
+ }
if (auto *D = IndexResult->Detail) {
if (I.documentation.empty())
I.documentation = D->Documentation;
if (I.detail.empty())
- I.detail = D->CompletionDetail;
+ I.detail = D->ReturnType;
if (auto Inserted = headerToInsertIfNotPresent()) {
auto IncludePath = [&]() -> Expected<std::string> {
auto ResolvedDeclaring = toHeaderFile(