[PATCH] D94753: [clangd] exclude symbols from document outline which do not originate from the main file
Ilya Golovenko via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 14 23:47:44 PST 2021
ilya-golovenko created this revision.
Herald added subscribers: usaxena95, kadircet, arphaman.
ilya-golovenko requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D94753
Files:
clang-tools-extra/clangd/FindSymbols.cpp
clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
Index: clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
+++ clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
@@ -489,6 +489,19 @@
ElementsAre(WithName("foo"), WithName("Foo")));
}
+TEST(DocumentSymbols, InMainFile) {
+ TestTU TU;
+ TU.AdditionalFiles["bar.h"] = "void bar();";
+ TU.Code = R"cpp(
+ namespace ns {
+ #include "bar.h"
+ void foo();
+ })cpp";
+
+ EXPECT_THAT(getSymbols(TU.build()),
+ ElementsAre(AllOf(WithName("ns"), Children(WithName("foo")))));
+}
+
TEST(DocumentSymbols, NoLocals) {
TestTU TU;
TU.Code = R"cpp(
Index: clang-tools-extra/clangd/FindSymbols.cpp
===================================================================
--- clang-tools-extra/clangd/FindSymbols.cpp
+++ clang-tools-extra/clangd/FindSymbols.cpp
@@ -247,6 +247,10 @@
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())
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94753.316855.patch
Type: text/x-patch
Size: 1417 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210115/af97fd30/attachment-0001.bin>
More information about the cfe-commits
mailing list