Skip to content

Commit 9cc221b

Browse files
[clangd] exclude symbols from document outline which do not originate from the main file
Differential Revision: https://reviews.llvm.org/D94753
1 parent 45ef053 commit 9cc221b

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

clang-tools-extra/clangd/FindSymbols.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,10 @@ class DocumentOutline {
247247
enum class VisitKind { No, OnlyDecl, OnlyChildren, DeclAndChildren };
248248

249249
void traverseDecl(Decl *D, std::vector<DocumentSymbol> &Results) {
250+
// Skip symbols which do not originate from the main file.
251+
if (!isInsideMainFile(D->getLocation(), AST.getSourceManager()))
252+
return;
253+
250254
if (auto *Templ = llvm::dyn_cast<TemplateDecl>(D)) {
251255
// TemplatedDecl might be null, e.g. concepts.
252256
if (auto *TD = Templ->getTemplatedDecl())

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,11 +523,13 @@ TEST(DocumentSymbols, InHeaderFile) {
523523
}
524524
)cpp";
525525
TU.Code = R"cpp(
526+
int i; // declaration to finish preamble
526527
#include "bar.h"
527528
int test() {
528529
}
529530
)cpp";
530-
EXPECT_THAT(getSymbols(TU.build()), ElementsAre(WithName("test")));
531+
EXPECT_THAT(getSymbols(TU.build()),
532+
ElementsAre(WithName("i"), WithName("test")));
531533
}
532534

533535
TEST(DocumentSymbols, Template) {

0 commit comments

Comments
 (0)