mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-24 08:35:08 +00:00
Compute CompletionItemKind from Declaration instead of CursorKind
This commit is contained in:
parent
233ed4f741
commit
8724985388
@ -119,12 +119,11 @@ Kind GetKind(const Decl *D, SymbolKind &kind) {
|
||||
case Decl::LinkageSpec:
|
||||
return Kind::Invalid;
|
||||
case Decl::Namespace:
|
||||
case Decl::NamespaceAlias:
|
||||
kind = SymbolKind::Namespace;
|
||||
return Kind::Type;
|
||||
case Decl::NamespaceAlias:
|
||||
kind = SymbolKind::TypeAlias;
|
||||
return Kind::Type;
|
||||
case Decl::ObjCCategory:
|
||||
case Decl::ObjCCategoryImpl:
|
||||
case Decl::ObjCImplementation:
|
||||
case Decl::ObjCInterface:
|
||||
case Decl::ObjCProtocol:
|
||||
@ -166,6 +165,9 @@ Kind GetKind(const Decl *D, SymbolKind &kind) {
|
||||
case Decl::ClassTemplatePartialSpecialization:
|
||||
kind = SymbolKind::Class;
|
||||
return Kind::Type;
|
||||
case Decl::TemplateTypeParm:
|
||||
kind = SymbolKind::TypeParameter;
|
||||
return Kind::Type;
|
||||
case Decl::TypeAlias:
|
||||
case Decl::Typedef:
|
||||
case Decl::UnresolvedUsingTypename:
|
||||
|
@ -227,89 +227,96 @@ void FilterCandidates(CompletionList &result, const std::string &complete_text,
|
||||
finalize();
|
||||
}
|
||||
|
||||
CompletionItemKind GetCompletionKind(CXCursorKind cursor_kind) {
|
||||
switch (cursor_kind) {
|
||||
case CXCursor_UnexposedDecl:
|
||||
return CompletionItemKind::Text;
|
||||
|
||||
case CXCursor_StructDecl:
|
||||
case CXCursor_UnionDecl:
|
||||
return CompletionItemKind::Struct;
|
||||
case CXCursor_ClassDecl:
|
||||
return CompletionItemKind::Class;
|
||||
case CXCursor_EnumDecl:
|
||||
return CompletionItemKind::Enum;
|
||||
case CXCursor_FieldDecl:
|
||||
return CompletionItemKind::Field;
|
||||
case CXCursor_EnumConstantDecl:
|
||||
return CompletionItemKind::EnumMember;
|
||||
case CXCursor_FunctionDecl:
|
||||
return CompletionItemKind::Function;
|
||||
case CXCursor_VarDecl:
|
||||
case CXCursor_ParmDecl:
|
||||
return CompletionItemKind::Variable;
|
||||
case CXCursor_ObjCInterfaceDecl:
|
||||
return CompletionItemKind::Interface;
|
||||
|
||||
case CXCursor_ObjCInstanceMethodDecl:
|
||||
case CXCursor_CXXMethod:
|
||||
case CXCursor_ObjCClassMethodDecl:
|
||||
return CompletionItemKind::Method;
|
||||
|
||||
case CXCursor_FunctionTemplate:
|
||||
return CompletionItemKind::Function;
|
||||
|
||||
case CXCursor_Constructor:
|
||||
case CXCursor_Destructor:
|
||||
case CXCursor_ConversionFunction:
|
||||
return CompletionItemKind::Constructor;
|
||||
|
||||
case CXCursor_ObjCIvarDecl:
|
||||
return CompletionItemKind::Variable;
|
||||
|
||||
case CXCursor_ClassTemplate:
|
||||
case CXCursor_ClassTemplatePartialSpecialization:
|
||||
case CXCursor_UsingDeclaration:
|
||||
case CXCursor_TypedefDecl:
|
||||
case CXCursor_TypeAliasDecl:
|
||||
case CXCursor_TypeAliasTemplateDecl:
|
||||
case CXCursor_ObjCCategoryDecl:
|
||||
case CXCursor_ObjCProtocolDecl:
|
||||
case CXCursor_ObjCImplementationDecl:
|
||||
case CXCursor_ObjCCategoryImplDecl:
|
||||
return CompletionItemKind::Class;
|
||||
|
||||
case CXCursor_ObjCPropertyDecl:
|
||||
return CompletionItemKind::Property;
|
||||
|
||||
case CXCursor_MacroInstantiation:
|
||||
case CXCursor_MacroDefinition:
|
||||
return CompletionItemKind::Text;
|
||||
|
||||
case CXCursor_Namespace:
|
||||
case CXCursor_NamespaceAlias:
|
||||
case CXCursor_NamespaceRef:
|
||||
CompletionItemKind GetCompletionKind(CodeCompletionContext::Kind K,
|
||||
const CodeCompletionResult &R) {
|
||||
switch (R.Kind) {
|
||||
case CodeCompletionResult::RK_Declaration: {
|
||||
const Decl *D = R.Declaration;
|
||||
switch (D->getKind()) {
|
||||
case Decl::LinkageSpec:
|
||||
return CompletionItemKind::Keyword;
|
||||
case Decl::Namespace:
|
||||
case Decl::NamespaceAlias:
|
||||
return CompletionItemKind::Module;
|
||||
|
||||
case CXCursor_MemberRef:
|
||||
case CXCursor_TypeRef:
|
||||
case CXCursor_ObjCSuperClassRef:
|
||||
case CXCursor_ObjCProtocolRef:
|
||||
case CXCursor_ObjCClassRef:
|
||||
return CompletionItemKind::Reference;
|
||||
|
||||
case CXCursor_NotImplemented:
|
||||
case CXCursor_OverloadCandidate:
|
||||
return CompletionItemKind::Text;
|
||||
|
||||
case CXCursor_TemplateTypeParameter:
|
||||
case CXCursor_TemplateTemplateParameter:
|
||||
case Decl::ObjCCategory:
|
||||
case Decl::ObjCCategoryImpl:
|
||||
case Decl::ObjCImplementation:
|
||||
case Decl::ObjCInterface:
|
||||
case Decl::ObjCProtocol:
|
||||
return CompletionItemKind::Interface;
|
||||
case Decl::ObjCMethod:
|
||||
return CompletionItemKind::Method;
|
||||
case Decl::ObjCProperty:
|
||||
return CompletionItemKind::Property;
|
||||
case Decl::ClassTemplate:
|
||||
return CompletionItemKind::Class;
|
||||
case Decl::FunctionTemplate:
|
||||
return CompletionItemKind::Function;
|
||||
case Decl::TypeAliasTemplate:
|
||||
return CompletionItemKind::Class;
|
||||
case Decl::VarTemplate:
|
||||
if (cast<VarTemplateDecl>(D)->getTemplatedDecl()->isConstexpr())
|
||||
return CompletionItemKind::Constant;
|
||||
return CompletionItemKind::Variable;
|
||||
case Decl::TemplateTemplateParm:
|
||||
return CompletionItemKind::TypeParameter;
|
||||
case Decl::Enum:
|
||||
return CompletionItemKind::Enum;
|
||||
case Decl::CXXRecord:
|
||||
case Decl::Record:
|
||||
if (auto *RD = dyn_cast<RecordDecl>(D))
|
||||
if (RD->getTagKind() == TTK_Struct)
|
||||
return CompletionItemKind::Struct;
|
||||
return CompletionItemKind::Class;
|
||||
case Decl::TemplateTypeParm:
|
||||
case Decl::TypeAlias:
|
||||
case Decl::Typedef:
|
||||
return CompletionItemKind::TypeParameter;
|
||||
case Decl::Binding:
|
||||
return CompletionItemKind::Variable;
|
||||
case Decl::Field:
|
||||
case Decl::ObjCIvar:
|
||||
return CompletionItemKind::Field;
|
||||
case Decl::Function:
|
||||
return CompletionItemKind::Function;
|
||||
case Decl::CXXMethod:
|
||||
return CompletionItemKind::Method;
|
||||
case Decl::CXXConstructor:
|
||||
return CompletionItemKind::Constructor;
|
||||
case Decl::CXXConversion:
|
||||
case Decl::CXXDestructor:
|
||||
return CompletionItemKind::Method;
|
||||
case Decl::Var:
|
||||
case Decl::Decomposition:
|
||||
case Decl::ImplicitParam:
|
||||
case Decl::ParmVar:
|
||||
case Decl::VarTemplateSpecialization:
|
||||
case Decl::VarTemplatePartialSpecialization:
|
||||
if (cast<VarDecl>(D)->isConstexpr())
|
||||
return CompletionItemKind::Constant;
|
||||
return CompletionItemKind::Variable;
|
||||
case Decl::EnumConstant:
|
||||
return CompletionItemKind::EnumMember;
|
||||
case Decl::IndirectField:
|
||||
return CompletionItemKind::Field;
|
||||
|
||||
default:
|
||||
LOG_S(WARNING) << "Unhandled completion kind " << cursor_kind;
|
||||
LOG_S(WARNING) << "Unhandled " << int(D->getKind());
|
||||
return CompletionItemKind::Text;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CodeCompletionResult::RK_Keyword:
|
||||
return CompletionItemKind::Keyword;
|
||||
case CodeCompletionResult::RK_Macro:
|
||||
return CompletionItemKind::Reference;
|
||||
case CodeCompletionResult::RK_Pattern:
|
||||
#if LLVM_VERSION_MAJOR >= 8
|
||||
if (K == CodeCompletionContext::CCC_IncludedFile)
|
||||
return CompletionItemKind::File;
|
||||
#endif
|
||||
return CompletionItemKind::Snippet;
|
||||
}
|
||||
}
|
||||
|
||||
void BuildItem(const CodeCompletionResult &R, const CodeCompletionString &CCS,
|
||||
@ -429,15 +436,12 @@ public:
|
||||
NK == DeclarationName::CXXLiteralOperatorName)
|
||||
continue;
|
||||
}
|
||||
|
||||
CodeCompletionString *CCS = R.CreateCodeCompletionString(
|
||||
S, Context, getAllocator(), getCodeCompletionTUInfo(),
|
||||
includeBriefComments());
|
||||
CompletionItem ls_item;
|
||||
ls_item.kind = GetCompletionKind(R.CursorKind);
|
||||
#if LLVM_VERSION_MAJOR >= 8
|
||||
if (Context.getKind() == CodeCompletionContext::CCC_IncludedFile)
|
||||
ls_item.kind = CompletionItemKind::File;
|
||||
#endif
|
||||
ls_item.kind = GetCompletionKind(Context.getKind(), R);
|
||||
if (const char *brief = CCS->getBriefComment())
|
||||
ls_item.documentation = brief;
|
||||
ls_item.detail = CCS->getParentContextName().str();
|
||||
|
Loading…
Reference in New Issue
Block a user