Index: clangd/index/Index.h =================================================================== --- clangd/index/Index.h +++ clangd/index/Index.h @@ -10,12 +10,14 @@ #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_INDEX_H #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_INDEX_H +#include "ExpectedTypes.h" #include "clang/Index/IndexSymbol.h" #include "clang/Lex/Lexer.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/Hashing.h" #include "llvm/ADT/Optional.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" @@ -278,6 +280,9 @@ ImplementationDetail = 1 << 2, }; + /// Type of the symbol, used for scoring purposes. + llvm::StringRef Type; + SymbolFlag Flags = SymbolFlag::None; /// FIXME: also add deprecation message and fixit? }; @@ -311,6 +316,7 @@ for (auto &Include : S.IncludeHeaders) CB(Include.IncludeHeader); + CB(S.Type); } // Computes query-independent quality score for a Symbol. Index: clangd/index/Serialization.cpp =================================================================== --- clangd/index/Serialization.cpp +++ clangd/index/Serialization.cpp @@ -272,6 +272,7 @@ writeVar(Sym.IncludeHeaders.size(), OS); for (const auto &Include : Sym.IncludeHeaders) WriteInclude(Include); + writeVar(Strings.index(Sym.Type), OS); } Symbol readSymbol(Reader &Data, ArrayRef Strings) { @@ -295,6 +296,7 @@ I.IncludeHeader = Data.consumeString(Strings); I.References = Data.consumeVar(); } + Sym.Type = Data.consumeString(Strings); return Sym; } Index: clangd/index/SymbolCollector.cpp =================================================================== --- clangd/index/SymbolCollector.cpp +++ clangd/index/SymbolCollector.cpp @@ -587,6 +587,11 @@ if (!Include.empty()) S.IncludeHeaders.emplace_back(Include, 1); + llvm::Optional Type; + if (S.Flags & Symbol::IndexedForCodeCompletion) + Type = OpaqueType::fromCompletionResult(*ASTCtx, SymbolCompletion); + S.Type = Type ? Type->raw() : ""; + S.Origin = Opts.Origin; if (ND.getAvailability() == AR_Deprecated) S.Flags |= Symbol::Deprecated; Index: clangd/index/YAMLSerialization.cpp =================================================================== --- clangd/index/YAMLSerialization.cpp +++ clangd/index/YAMLSerialization.cpp @@ -198,6 +198,7 @@ IO.mapOptional("Documentation", Sym.Documentation); IO.mapOptional("ReturnType", Sym.ReturnType); IO.mapOptional("IncludeHeaders", Sym.IncludeHeaders); + IO.mapOptional("Type", Sym.Type); } }; Index: clangd/indexer/IndexerMain.cpp =================================================================== --- clangd/indexer/IndexerMain.cpp +++ clangd/indexer/IndexerMain.cpp @@ -42,9 +42,8 @@ IndexActionFactory(IndexFileIn &Result) : Result(Result) {} clang::FrontendAction *create() override { - SymbolCollector::Options Opts; return createStaticIndexingAction( - Opts, + SymbolCollector::Options(), [&](SymbolSlab S) { // Merge as we go. std::lock_guard Lock(SymbolsMu);