MCPcopy Create free account
hub / github.com/clice-io/clice / completion_kind

Function completion_kind

src/feature/code_completion.cpp:51–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49 llvm::StringRef spelling;
50
51 static auto from(llvm::StringRef content, std::uint32_t offset) -> CompletionPrefix {
52 assert(offset <= content.size());
53
54 auto start = offset;
55 while(start > 0 && is_identifier_char(content[start - 1])) {
56 start -= 1;
57 }
58
59 auto end = offset;
60 while(end < content.size() && is_identifier_char(content[end])) {
61 end += 1;
62 }
63
64 return CompletionPrefix{
65 .typed = LocalSourceRange(start, offset),
66 .whole = LocalSourceRange(start, end),
67 .spelling = content.substr(start, offset - start),
68 };
69 }
70};
71
72auto completion_kind(const clang::NamedDecl* decl) -> protocol::CompletionItemKind {
73 if(auto* function = llvm::dyn_cast<clang::FunctionTemplateDecl>(decl)) {
74 decl = function->getTemplatedDecl();
75 }
76
77 if(llvm::isa<clang::NamespaceDecl, clang::NamespaceAliasDecl>(decl)) {
78 return protocol::CompletionItemKind::Module;
79 }
80
81 if(llvm::isa<clang::CXXConstructorDecl>(decl)) {
82 return protocol::CompletionItemKind::Constructor;
83 }
84
85 if(llvm::isa<clang::CXXMethodDecl, clang::CXXConversionDecl, clang::CXXDestructorDecl>(decl)) {
86 return protocol::CompletionItemKind::Method;
87 }
88
89 if(llvm::isa<clang::FunctionDecl>(decl)) {
90 return protocol::CompletionItemKind::Function;
91 }
92
93 if(llvm::isa<clang::FieldDecl, clang::IndirectFieldDecl>(decl)) {
94 return protocol::CompletionItemKind::Field;
95 }
96
97 if(llvm::isa<clang::VarDecl,
98 clang::ParmVarDecl,
99 clang::ImplicitParamDecl,
100 clang::BindingDecl,
101 clang::NonTypeTemplateParmDecl>(decl)) {
102 return protocol::CompletionItemKind::Variable;
103 }
104
105 if(llvm::isa<clang::LabelDecl>(decl)) {
106 return protocol::CompletionItemKind::Variable;
107 }
108

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected