Skip to content

Commit 211948b

Browse files
committed
[clangd] Make inline friend functions appear in document symbols
Otherwise, that definition would not show up in the document outline.
1 parent 6adbbcc commit 211948b

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

clang-tools-extra/clangd/FindSymbols.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "SourceCode.h"
1515
#include "index/Index.h"
1616
#include "support/Logger.h"
17+
#include "clang/AST/DeclFriend.h"
1718
#include "clang/AST/DeclTemplate.h"
1819
#include "clang/Index/IndexSymbol.h"
1920
#include "llvm/ADT/ArrayRef.h"
@@ -391,6 +392,16 @@ class DocumentOutline {
391392
D = TD;
392393
}
393394

395+
// Friend declarations should be traversed if and only if
396+
// they are also defined here.
397+
if (auto *Friend = llvm::dyn_cast<FriendDecl>(D)) {
398+
if (auto *Func =
399+
llvm::dyn_cast_or_null<FunctionDecl>(Friend->getFriendDecl())) {
400+
if (Func->isThisDeclarationADefinition())
401+
D = Func;
402+
}
403+
}
404+
394405
VisitKind Visit = shouldVisit(D);
395406
if (Visit == VisitKind::No)
396407
return;

clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ TEST(DocumentSymbols, BasicSymbols) {
335335
Foo(int a) {}
336336
void $decl[[f]]();
337337
friend void f1();
338+
friend void f2() {}
338339
friend class Friend;
339340
Foo& operator=(const Foo&);
340341
~Foo();
@@ -346,7 +347,7 @@ TEST(DocumentSymbols, BasicSymbols) {
346347
};
347348
348349
void f1();
349-
inline void f2() {}
350+
void f2();
350351
static const int KInt = 2;
351352
const char* kStr = "123";
352353
@@ -386,6 +387,8 @@ TEST(DocumentSymbols, BasicSymbols) {
386387
withDetail("(int)"), children()),
387388
AllOf(withName("f"), withKind(SymbolKind::Method),
388389
withDetail("void ()"), children()),
390+
AllOf(withName("f2"), withKind(SymbolKind::Function),
391+
withDetail("void ()"), children()),
389392
AllOf(withName("operator="), withKind(SymbolKind::Method),
390393
withDetail("Foo &(const Foo &)"), children()),
391394
AllOf(withName("~Foo"), withKind(SymbolKind::Constructor),

0 commit comments

Comments
 (0)