mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-22 23:55:08 +00:00
Compute CompletionItemKind from Declaration instead of CursorKind
This commit is contained in:
parent
2db67f6edb
commit
03f91f0681
@ -107,12 +107,11 @@ Kind GetKind(const Decl *D, SymbolKind &kind) {
|
|||||||
case Decl::LinkageSpec:
|
case Decl::LinkageSpec:
|
||||||
return Kind::Invalid;
|
return Kind::Invalid;
|
||||||
case Decl::Namespace:
|
case Decl::Namespace:
|
||||||
|
case Decl::NamespaceAlias:
|
||||||
kind = SymbolKind::Namespace;
|
kind = SymbolKind::Namespace;
|
||||||
return Kind::Type;
|
return Kind::Type;
|
||||||
case Decl::NamespaceAlias:
|
|
||||||
kind = SymbolKind::TypeAlias;
|
|
||||||
return Kind::Type;
|
|
||||||
case Decl::ObjCCategory:
|
case Decl::ObjCCategory:
|
||||||
|
case Decl::ObjCCategoryImpl:
|
||||||
case Decl::ObjCImplementation:
|
case Decl::ObjCImplementation:
|
||||||
case Decl::ObjCInterface:
|
case Decl::ObjCInterface:
|
||||||
case Decl::ObjCProtocol:
|
case Decl::ObjCProtocol:
|
||||||
@ -154,6 +153,9 @@ Kind GetKind(const Decl *D, SymbolKind &kind) {
|
|||||||
case Decl::ClassTemplatePartialSpecialization:
|
case Decl::ClassTemplatePartialSpecialization:
|
||||||
kind = SymbolKind::Class;
|
kind = SymbolKind::Class;
|
||||||
return Kind::Type;
|
return Kind::Type;
|
||||||
|
case Decl::TemplateTypeParm:
|
||||||
|
kind = SymbolKind::TypeParameter;
|
||||||
|
return Kind::Type;
|
||||||
case Decl::TypeAlias:
|
case Decl::TypeAlias:
|
||||||
case Decl::Typedef:
|
case Decl::Typedef:
|
||||||
case Decl::UnresolvedUsingTypename:
|
case Decl::UnresolvedUsingTypename:
|
||||||
|
@ -215,88 +215,95 @@ void FilterCandidates(CompletionList &result, const std::string &complete_text,
|
|||||||
finalize();
|
finalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
CompletionItemKind GetCompletionKind(CXCursorKind cursor_kind) {
|
CompletionItemKind GetCompletionKind(CodeCompletionContext::Kind K,
|
||||||
switch (cursor_kind) {
|
const CodeCompletionResult &R) {
|
||||||
case CXCursor_UnexposedDecl:
|
switch (R.Kind) {
|
||||||
return CompletionItemKind::Text;
|
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 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;
|
||||||
|
|
||||||
case CXCursor_StructDecl:
|
default:
|
||||||
case CXCursor_UnionDecl:
|
LOG_S(WARNING) << "Unhandled " << int(D->getKind());
|
||||||
return CompletionItemKind::Struct;
|
return CompletionItemKind::Text;
|
||||||
case CXCursor_ClassDecl:
|
}
|
||||||
return CompletionItemKind::Class;
|
break;
|
||||||
case CXCursor_EnumDecl:
|
}
|
||||||
return CompletionItemKind::Enum;
|
case CodeCompletionResult::RK_Keyword:
|
||||||
case CXCursor_FieldDecl:
|
return CompletionItemKind::Keyword;
|
||||||
return CompletionItemKind::Field;
|
case CodeCompletionResult::RK_Macro:
|
||||||
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:
|
|
||||||
return CompletionItemKind::Module;
|
|
||||||
|
|
||||||
case CXCursor_MemberRef:
|
|
||||||
case CXCursor_TypeRef:
|
|
||||||
case CXCursor_ObjCSuperClassRef:
|
|
||||||
case CXCursor_ObjCProtocolRef:
|
|
||||||
case CXCursor_ObjCClassRef:
|
|
||||||
return CompletionItemKind::Reference;
|
return CompletionItemKind::Reference;
|
||||||
|
case CodeCompletionResult::RK_Pattern:
|
||||||
case CXCursor_NotImplemented:
|
#if LLVM_VERSION_MAJOR >= 8
|
||||||
case CXCursor_OverloadCandidate:
|
if (K == CodeCompletionContext::CCC_IncludedFile)
|
||||||
return CompletionItemKind::Text;
|
return CompletionItemKind::File;
|
||||||
|
#endif
|
||||||
case CXCursor_TemplateTypeParameter:
|
return CompletionItemKind::Snippet;
|
||||||
case CXCursor_TemplateTemplateParameter:
|
|
||||||
return CompletionItemKind::TypeParameter;
|
|
||||||
|
|
||||||
default:
|
|
||||||
LOG_S(WARNING) << "Unhandled completion kind " << cursor_kind;
|
|
||||||
return CompletionItemKind::Text;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -417,15 +424,12 @@ public:
|
|||||||
NK == DeclarationName::CXXLiteralOperatorName)
|
NK == DeclarationName::CXXLiteralOperatorName)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeCompletionString *CCS = R.CreateCodeCompletionString(
|
CodeCompletionString *CCS = R.CreateCodeCompletionString(
|
||||||
S, Context, getAllocator(), getCodeCompletionTUInfo(),
|
S, Context, getAllocator(), getCodeCompletionTUInfo(),
|
||||||
includeBriefComments());
|
includeBriefComments());
|
||||||
CompletionItem ls_item;
|
CompletionItem ls_item;
|
||||||
ls_item.kind = GetCompletionKind(R.CursorKind);
|
ls_item.kind = GetCompletionKind(Context.getKind(), R);
|
||||||
#if LLVM_VERSION_MAJOR >= 8
|
|
||||||
if (Context.getKind() == CodeCompletionContext::CCC_IncludedFile)
|
|
||||||
ls_item.kind = CompletionItemKind::File;
|
|
||||||
#endif
|
|
||||||
if (const char *brief = CCS->getBriefComment())
|
if (const char *brief = CCS->getBriefComment())
|
||||||
ls_item.documentation = brief;
|
ls_item.documentation = brief;
|
||||||
ls_item.detail = CCS->getParentContextName().str();
|
ls_item.detail = CCS->getParentContextName().str();
|
||||||
|
Loading…
Reference in New Issue
Block a user