Skip to content

Commit af6491c

Browse files
chouzzDimitri Ratz
authored andcommitted
Support Declaration and Definition tags
1 parent 18c71ac commit af6491c

File tree

4 files changed

+42
-40
lines changed

4 files changed

+42
-40
lines changed

clang-tools-extra/clangd/AST.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,23 @@ bool isVirtual(const Decl *D) {
257257
return false;
258258
}
259259

260+
bool isUniqueDefinition(const NamedDecl *Decl) {
261+
if (auto *Func = dyn_cast<FunctionDecl>(Decl))
262+
return Func->isThisDeclarationADefinition();
263+
if (auto *Klass = dyn_cast<CXXRecordDecl>(Decl))
264+
return Klass->isThisDeclarationADefinition();
265+
if (auto *Iface = dyn_cast<ObjCInterfaceDecl>(Decl))
266+
return Iface->isThisDeclarationADefinition();
267+
if (auto *Proto = dyn_cast<ObjCProtocolDecl>(Decl))
268+
return Proto->isThisDeclarationADefinition();
269+
if (auto *Var = dyn_cast<VarDecl>(Decl))
270+
return Var->isThisDeclarationADefinition();
271+
return isa<TemplateTypeParmDecl>(Decl) ||
272+
isa<NonTypeTemplateParmDecl>(Decl) ||
273+
isa<TemplateTemplateParmDecl>(Decl) || isa<ObjCCategoryDecl>(Decl) ||
274+
isa<ObjCImplDecl>(Decl);
275+
}
276+
260277
SourceLocation nameLocation(const clang::Decl &D, const SourceManager &SM) {
261278
auto L = D.getLocation();
262279
// For `- (void)foo` we want `foo` not the `-`.

clang-tools-extra/clangd/AST.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ bool isConst(const Decl *D);
184184
bool isStatic(const Decl *D);
185185
bool isAbstract(const Decl *D);
186186
bool isVirtual(const Decl *D);
187-
187+
bool isUniqueDefinition(const NamedDecl *Decl);
188188
/// Returns a nested name specifier loc of \p ND if it was present in the
189189
/// source, e.g.
190190
/// void ns::something::foo() -> returns 'ns::something'

clang-tools-extra/clangd/FindSymbols.cpp

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -188,34 +188,36 @@ std::string getSymbolName(ASTContext &Ctx, const NamedDecl &ND) {
188188
return printName(Ctx, ND);
189189
}
190190

191-
std::vector<SymbolTag> getSymbolTags(const NamedDecl &ND)
192-
{
191+
std::vector<SymbolTag> getSymbolTags(const NamedDecl &ND) {
193192
std::vector<SymbolTag> Tags;
194-
if (ND.isDeprecated())
193+
if (ND.isDeprecated())
195194
Tags.push_back(SymbolTag::Deprecated);
196-
if (isConst(&ND))
197-
Tags.push_back(SymbolTag::Constant);
198-
if (isStatic(&ND))
199-
Tags.push_back(SymbolTag::Static);
195+
if (isConst(&ND))
196+
Tags.push_back(SymbolTag::Constant);
197+
if (isStatic(&ND))
198+
Tags.push_back(SymbolTag::Static);
200199
if (isVirtual(&ND))
201-
Tags.push_back(SymbolTag::Virtual);
202-
200+
Tags.push_back(SymbolTag::Virtual);
201+
if (!isa<UnresolvedUsingValueDecl>(ND))
202+
Tags.push_back(SymbolTag::Declaration);
203+
if (isUniqueDefinition(&ND))
204+
Tags.push_back(SymbolTag::Definition);
203205
if (const FieldDecl *FD = dyn_cast<FieldDecl>(&ND)) {
204206
switch (FD->getAccess()) {
205-
case AS_public:
206-
Tags.push_back(SymbolTag::Public);
207-
break;
208-
case AS_protected:
209-
Tags.push_back(SymbolTag::Protected);
210-
break;
211-
case AS_private:
212-
Tags.push_back(SymbolTag::Private);
213-
break;
214-
default:
215-
break;
207+
case AS_public:
208+
Tags.push_back(SymbolTag::Public);
209+
break;
210+
case AS_protected:
211+
Tags.push_back(SymbolTag::Protected);
212+
break;
213+
case AS_private:
214+
Tags.push_back(SymbolTag::Private);
215+
break;
216+
default:
217+
break;
216218
}
217-
}
218-
219+
}
220+
219221
return Tags;
220222
}
221223

clang-tools-extra/clangd/SemanticHighlighting.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -78,23 +78,6 @@ bool canHighlightName(DeclarationName Name) {
7878
llvm_unreachable("invalid name kind");
7979
}
8080

81-
bool isUniqueDefinition(const NamedDecl *Decl) {
82-
if (auto *Func = dyn_cast<FunctionDecl>(Decl))
83-
return Func->isThisDeclarationADefinition();
84-
if (auto *Klass = dyn_cast<CXXRecordDecl>(Decl))
85-
return Klass->isThisDeclarationADefinition();
86-
if (auto *Iface = dyn_cast<ObjCInterfaceDecl>(Decl))
87-
return Iface->isThisDeclarationADefinition();
88-
if (auto *Proto = dyn_cast<ObjCProtocolDecl>(Decl))
89-
return Proto->isThisDeclarationADefinition();
90-
if (auto *Var = dyn_cast<VarDecl>(Decl))
91-
return Var->isThisDeclarationADefinition();
92-
return isa<TemplateTypeParmDecl>(Decl) ||
93-
isa<NonTypeTemplateParmDecl>(Decl) ||
94-
isa<TemplateTemplateParmDecl>(Decl) || isa<ObjCCategoryDecl>(Decl) ||
95-
isa<ObjCImplDecl>(Decl);
96-
}
97-
9881
std::optional<HighlightingKind> kindForType(const Type *TP,
9982
const HeuristicResolver *Resolver);
10083
std::optional<HighlightingKind> kindForDecl(const NamedDecl *D,

0 commit comments

Comments
 (0)