[clang-tools-extra] 9cc221b - [clangd] exclude symbols from document outline which do not originate from the main file
Ilya Golovenko via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 15 03:02:19 PST 2021
Author: Ilya Golovenko
Date: 2021-01-15T13:23:12+03:00
New Revision: 9cc221b99becf20397d935981eeb48cba5be7faf
URL: https://github.com/llvm/llvm-project/commit/9cc221b99becf20397d935981eeb48cba5be7faf
DIFF: https://github.com/llvm/llvm-project/commit/9cc221b99becf20397d935981eeb48cba5be7faf.diff
LOG: [clangd] exclude symbols from document outline which do not originate from the main file
Differential Revision: https://reviews.llvm.org/D94753
Added:
Modified:
clang-tools-extra/clangd/FindSymbols.cpp
clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/FindSymbols.cpp b/clang-tools-extra/clangd/FindSymbols.cpp
index d6908f7ab5fb..0a10e3efb05c 100644
--- a/clang-tools-extra/clangd/FindSymbols.cpp
+++ b/clang-tools-extra/clangd/FindSymbols.cpp
@@ -247,6 +247,10 @@ class DocumentOutline {
enum class VisitKind { No, OnlyDecl, OnlyChildren, DeclAndChildren };
void traverseDecl(Decl *D, std::vector<DocumentSymbol> &Results) {
+ // Skip symbols which do not originate from the main file.
+ if (!isInsideMainFile(D->getLocation(), AST.getSourceManager()))
+ return;
+
if (auto *Templ = llvm::dyn_cast<TemplateDecl>(D)) {
// TemplatedDecl might be null, e.g. concepts.
if (auto *TD = Templ->getTemplatedDecl())
diff --git a/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp b/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
index 43658284937e..e594ade4295e 100644
--- a/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
@@ -523,11 +523,13 @@ TEST(DocumentSymbols, InHeaderFile) {
}
)cpp";
TU.Code = R"cpp(
+ int i; // declaration to finish preamble
#include "bar.h"
int test() {
}
)cpp";
- EXPECT_THAT(getSymbols(TU.build()), ElementsAre(WithName("test")));
+ EXPECT_THAT(getSymbols(TU.build()),
+ ElementsAre(WithName("i"), WithName("test")));
}
TEST(DocumentSymbols, Template) {
More information about the cfe-commits
mailing list