[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
Fri Jan 15 01:58:24 PST 2021
ilya-golovenko updated this revision to Diff 316877.
ilya-golovenko added a comment.
Update existing test and remove redundant one
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D94753/new/
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
@@ -523,11 +523,13 @@
}
)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) {
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.316877.patch
Type: text/x-patch
Size: 1327 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210115/2710cedd/attachment-0001.bin>
More information about the cfe-commits
mailing list