indexer: index TemplateTypeParmDecl and ParmVarDecl in declarations for clang >= 9

Index ParmVarDecl in declarations if index.parametersInDeclarations is true

And support some unhandled Decl::Kind
This commit is contained in:
Fangrui Song 2019-02-22 10:59:05 +08:00
parent c63121d7c6
commit ea852374a2
3 changed files with 33 additions and 8 deletions

View File

@ -266,6 +266,9 @@ struct Config {
// May be too slow for big projects, so it is off by default. // May be too slow for big projects, so it is off by default.
bool onChange = false; bool onChange = false;
// If true, index parameters in declarations.
bool parametersInDeclarations = true;
// Number of indexer threads. If 0, 80% of cores are used. // Number of indexer threads. If 0, 80% of cores are used.
int threads = 0; int threads = 0;
@ -326,8 +329,8 @@ REFLECT_STRUCT(Config::Diagnostics, blacklist, onChange, onOpen, onSave,
REFLECT_STRUCT(Config::Highlight, largeFileSize, lsRanges, blacklist, whitelist) REFLECT_STRUCT(Config::Highlight, largeFileSize, lsRanges, blacklist, whitelist)
REFLECT_STRUCT(Config::Index, blacklist, comments, initialBlacklist, REFLECT_STRUCT(Config::Index, blacklist, comments, initialBlacklist,
initialWhitelist, maxInitializerLines, multiVersion, initialWhitelist, maxInitializerLines, multiVersion,
multiVersionBlacklist, multiVersionWhitelist, onChange, threads, multiVersionBlacklist, multiVersionWhitelist, onChange,
trackDependency, whitelist); parametersInDeclarations, threads, trackDependency, whitelist);
REFLECT_STRUCT(Config::Request, timeout); REFLECT_STRUCT(Config::Request, timeout);
REFLECT_STRUCT(Config::Session, maxNum); REFLECT_STRUCT(Config::Session, maxNum);
REFLECT_STRUCT(Config::WorkspaceSymbol, caseSensitivity, maxNum, sort); REFLECT_STRUCT(Config::WorkspaceSymbol, caseSensitivity, maxNum, sort);

View File

@ -159,6 +159,9 @@ Kind GetKind(const Decl *D, SymbolKind &kind) {
case Decl::UnresolvedUsingTypename: case Decl::UnresolvedUsingTypename:
kind = SymbolKind::TypeAlias; kind = SymbolKind::TypeAlias;
return Kind::Type; return Kind::Type;
case Decl::Using:
kind = SymbolKind::Null; // ignored
return Kind::Invalid;
case Decl::Binding: case Decl::Binding:
kind = SymbolKind::Variable; kind = SymbolKind::Variable;
return Kind::Var; return Kind::Var;
@ -181,6 +184,10 @@ Kind GetKind(const Decl *D, SymbolKind &kind) {
case Decl::CXXDestructor: case Decl::CXXDestructor:
kind = SymbolKind::Method; kind = SymbolKind::Method;
return Kind::Func; return Kind::Func;
case Decl::NonTypeTemplateParm:
// ccls extension
kind = SymbolKind::Parameter;
return Kind::Var;
case Decl::Var: case Decl::Var:
case Decl::Decomposition: case Decl::Decomposition:
kind = SymbolKind::Variable; kind = SymbolKind::Variable;
@ -204,7 +211,6 @@ Kind GetKind(const Decl *D, SymbolKind &kind) {
return Kind::Invalid; return Kind::Invalid;
default: default:
LOG_S(INFO) << "unhandled " << int(D->getKind());
return Kind::Invalid; return Kind::Invalid;
} }
} }
@ -722,7 +728,7 @@ public:
IndexFunc *func = nullptr; IndexFunc *func = nullptr;
IndexType *type = nullptr; IndexType *type = nullptr;
IndexVar *var = nullptr; IndexVar *var = nullptr;
SymbolKind ls_kind; SymbolKind ls_kind = SymbolKind::Unknown;
Kind kind = GetKind(D, ls_kind); Kind kind = GetKind(D, ls_kind);
if (is_def) if (is_def)
@ -772,8 +778,10 @@ public:
}; };
switch (kind) { switch (kind) {
case Kind::Invalid: case Kind::Invalid:
LOG_S(INFO) << "Unhandled " << int(D->getKind()) << " " << info->qualified if (ls_kind == SymbolKind::Unknown)
<< " in " << db->path << ":" << loc.start.line + 1; LOG_S(INFO) << "Unhandled " << int(D->getKind()) << " "
<< info->qualified << " in " << db->path << ":"
<< (loc.start.line + 1) << ":" << (loc.start.column + 1);
return true; return true;
case Kind::File: case Kind::File:
return true; return true;
@ -807,8 +815,12 @@ public:
do_def_decl(type); do_def_decl(type);
if (Spell != Loc) if (Spell != Loc)
AddMacroUse(db, SM, usr, Kind::Type, Spell); AddMacroUse(db, SM, usr, Kind::Type, Spell);
if (type->def.detailed_name[0] == '\0' && info->short_name.size()) if (type->def.detailed_name[0] == '\0' && info->short_name.size()) {
SetName(D, info->short_name, info->qualified, type->def); if (D->getKind() == Decl::TemplateTypeParm)
type->def.detailed_name = Intern(info->short_name);
else
SetName(OrigD, info->short_name, info->qualified, type->def);
}
if (is_def || is_decl) { if (is_def || is_decl) {
const Decl *DC = cast<Decl>(SemDC); const Decl *DC = cast<Decl>(SemDC);
if (GetKind(DC, ls_kind) == Kind::Type) if (GetKind(DC, ls_kind) == Kind::Type)
@ -840,6 +852,7 @@ public:
if (!isa<EnumConstantDecl>(D)) if (!isa<EnumConstantDecl>(D))
db->ToType(usr1).instances.push_back(usr); db->ToType(usr1).instances.push_back(usr);
} else if (const Decl *D1 = GetAdjustedDecl(GetTypeDecl(T))) { } else if (const Decl *D1 = GetAdjustedDecl(GetTypeDecl(T))) {
#if LLVM_VERSION_MAJOR < 9
if (isa<TemplateTypeParmDecl>(D1)) { if (isa<TemplateTypeParmDecl>(D1)) {
// e.g. TemplateTypeParmDecl is not handled by // e.g. TemplateTypeParmDecl is not handled by
// handleDeclOccurence. // handleDeclOccurence.
@ -862,6 +875,7 @@ public:
break; break;
} }
} }
#endif
IndexParam::DeclInfo *info1; IndexParam::DeclInfo *info1;
Usr usr1 = GetUsr(D1, &info1); Usr usr1 = GetUsr(D1, &info1);
@ -1227,6 +1241,11 @@ Index(SemaManager *manager, WorkingFiles *wfiles, VFS *vfs,
index::IndexingOptions::SystemSymbolFilterKind::All; index::IndexingOptions::SystemSymbolFilterKind::All;
IndexOpts.IndexFunctionLocals = true; IndexOpts.IndexFunctionLocals = true;
IndexOpts.IndexImplicitInstantiation = true; IndexOpts.IndexImplicitInstantiation = true;
#if LLVM_VERSION_MAJOR >= 9
IndexOpts.IndexParametersInDeclarations =
g_config->index.parametersInDeclarations;
IndexOpts.IndexTemplateParameters = true;
#endif
std::unique_ptr<FrontendAction> Action = createIndexingAction( std::unique_ptr<FrontendAction> Action = createIndexingAction(
DataConsumer, IndexOpts, std::make_unique<IndexFrontendAction>(param)); DataConsumer, IndexOpts, std::make_unique<IndexFrontendAction>(param));

View File

@ -260,6 +260,9 @@ CompletionItemKind GetCompletionKind(CodeCompletionContext::Kind K,
case Decl::TypeAlias: case Decl::TypeAlias:
case Decl::Typedef: case Decl::Typedef:
return CompletionItemKind::TypeParameter; return CompletionItemKind::TypeParameter;
case Decl::Using:
case Decl::ConstructorUsingShadow:
return CompletionItemKind::Keyword;
case Decl::Binding: case Decl::Binding:
return CompletionItemKind::Variable; return CompletionItemKind::Variable;
case Decl::Field: case Decl::Field: