From 7ad1696900e6189f89688a346f6d954372748a33 Mon Sep 17 00:00:00 2001 From: Eric Liu Date: Fri, 22 Jun 2018 10:46:59 +0000 Subject: [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 --- clang-tools-extra/clangd/CodeComplete.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'clang-tools-extra/clangd/CodeComplete.cpp') diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp index 31619398d17..647e02da728 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 @@ struct CompletionCandidate { 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 @@ struct CompletionCandidate { 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(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. -- cgit v1.2.3