[clangd] Expose qualified symbol names in CompletionItem (C++ structure only, no json).
Summary:
The qualified name can be used to match a completion item to its corresponding
symbol. This can be useful for tools that measure code completion quality.
Qualified names are not precise for identifying symbols; we need to figure out a
better way to identify completion items.
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: ilya-biryukov, MaskRay, jkorous, cfe-commits
Differential Revision: https://reviews.llvm.org/D48425
llvm-svn: 335334
diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp
index 3161939..647e02d 100644
--- a/clang-tools-extra/clangd/CodeComplete.cpp
+++ b/clang-tools-extra/clangd/CodeComplete.cpp
@@ -19,6 +19,7 @@
//===---------------------------------------------------------------------===//
#include "CodeComplete.h"
+#include "AST.h"
#include "CodeCompletionStrings.h"
#include "Compiler.h"
#include "FuzzyMatch.h"
@@ -243,6 +244,8 @@
const IncludeInserter &Includes,
llvm::StringRef SemaDocComment) const {
assert(bool(SemaResult) == bool(SemaCCS));
+ assert(SemaResult || IndexResult);
+
CompletionItem I;
bool InsertingInclude = false; // Whether a new #include will be added.
if (SemaResult) {
@@ -253,8 +256,14 @@
I.filterText = Text;
I.documentation = formatDocumentation(*SemaCCS, SemaDocComment);
I.detail = getDetail(*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;
}
if (IndexResult) {
+ if (I.SymbolScope.empty())
+ I.SymbolScope = IndexResult->Scope;
if (I.kind == CompletionItemKind::Missing)
I.kind = toCompletionItemKind(IndexResult->SymInfo.Kind);
// FIXME: reintroduce a way to show the index source for debugging.