Skip to content

Commit 646b1bd

Browse files
feat: Support code nav for type aliases (#135)
1 parent 5528fa8 commit 646b1bd

File tree

8 files changed

+42
-0
lines changed

8 files changed

+42
-0
lines changed

indexer/Indexer.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,20 @@ void TuIndexer::saveTagTypeLoc(const clang::TagTypeLoc &tagTypeLoc) {
524524
}
525525
}
526526

527+
void TuIndexer::saveTypedefNameDecl(
528+
const clang::TypedefNameDecl &typedefNameDecl) {
529+
auto optSymbol = this->symbolFormatter.getNamedDeclSymbol(typedefNameDecl);
530+
if (!optSymbol.has_value()) {
531+
return;
532+
}
533+
scip::SymbolInformation symbolInfo{};
534+
for (auto &docComment : this->tryGetDocComment(typedefNameDecl)) {
535+
*symbolInfo.add_documentation() = std::move(docComment.Text);
536+
}
537+
this->saveDefinition(*optSymbol, typedefNameDecl.getLocation(),
538+
std::move(symbolInfo));
539+
}
540+
527541
void TuIndexer::saveVarDecl(const clang::VarDecl &varDecl) {
528542
if (llvm::isa<clang::DecompositionDecl>(&varDecl)) {
529543
// Individual bindings will be visited by VisitBindingDecl

indexer/SymbolFormatter.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,24 @@ SymbolFormatter::getLocalVarOrParmSymbol(const clang::VarDecl &varDecl) {
473473
return this->getNextLocalSymbol(varDecl);
474474
}
475475

476+
std::optional<std::string_view> SymbolFormatter::getTypedefNameSymbol(
477+
const clang::TypedefNameDecl &typedefNameDecl) {
478+
return this->getSymbolCached(
479+
typedefNameDecl, [&]() -> std::optional<std::string> {
480+
auto optContextSymbol =
481+
this->getContextSymbol(*typedefNameDecl.getDeclContext());
482+
if (!optContextSymbol.has_value()) {
483+
return {};
484+
}
485+
return SymbolBuilder::formatContextual(
486+
*optContextSymbol,
487+
DescriptorBuilder{
488+
.name = llvm_ext::toStringView(typedefNameDecl.getName()),
489+
.suffix = scip::Descriptor::Type,
490+
});
491+
});
492+
}
493+
476494
std::optional<std::string_view>
477495
SymbolFormatter::getVarSymbol(const clang::VarDecl &varDecl) {
478496
if (varDecl.isLocalVarDeclOrParm()) {

indexer/SymbolFormatter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
F(Function) \
2525
F(Namespace) \
2626
F(Record) \
27+
F(TypedefName) \
2728
F(Var)
2829

2930
namespace clang {

test/index/functions/ctors_dtors.snapshot.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
template<class T> struct remove_ref { typedef T type; };
44
// ^^^^^^^^^^ definition [..] remove_ref#
5+
// ^^^^ definition [..] remove_ref#type#
56
template<class T> struct remove_ref<T&> { typedef T type; };
67
// ^^^^^^^^^^ definition [..] remove_ref#
8+
// ^^^^ definition [..] remove_ref#type#
79
template<class T> struct remove_ref<T&&> { typedef T type; };
810
// ^^^^^^^^^^ definition [..] remove_ref#
11+
// ^^^^ definition [..] remove_ref#type#
912

1013
template <typename T>
1114
typename remove_ref<T>::type&& move(T&& arg) {

test/index/functions/functions.snapshot.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
// check that the same canonical type produces the same hash
3737
using IntAlias = int;
38+
// ^^^^^^^^ definition [..] IntAlias#
3839
void int_to_void_fn(int) {}
3940
// ^^^^^^^^^^^^^^ definition [..] int_to_void_fn(d4f767463ce0a6b3).
4041
void same_hash_as_previous(IntAlias) {}

test/index/functions/operators.snapshot.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
explicit operator const char*() const { return "aaa"; }
131131
// ^^^^^^^^ definition [..] IntConvertible#`operator const char *`(a9f41ea0e82d88cf).
132132
using arr_t = int[3];
133+
// ^^^^^ definition [..] IntConvertible#arr_t#
133134
operator arr_t*() const { return nullptr; }
134135
// ^^^^^^^^ definition [..] IntConvertible#`operator int (*)[3]`(a00bb5473f10e296).
135136
};
@@ -157,6 +158,7 @@
157158
using size_t = unsigned long long;
158159
#else
159160
using size_t = unsigned long;
161+
// ^^^^^^ definition [..] size_t#
160162
#endif
161163

162164
// Override global stuff

test/index/namespaces/namespaces.snapshot.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
}
4444

4545
using C = c::C;
46+
// ^ definition [..] C#
4647
// ^ reference [..] c/
4748
// ^ reference [..] c/C#
4849

test/index/types/bad_tagdecl.snapshot.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
template<class T>
1717
struct enable_if<true, T> { typedef T type; };
1818
// ^^^^^^^^^ definition [..] enable_if#
19+
// ^^^^ definition [..] enable_if#type#
1920

2021
template< bool B, class T = void >
2122
using enable_if_t = typename enable_if<B,T>::type;
23+
// ^^^^^^^^^^^ definition [..] enable_if_t#
2224

2325
template <typename T, typename Enable = void> struct MyTemplate { };
2426
// ^^^^^^^^^^ definition [..] MyTemplate#

0 commit comments

Comments
 (0)