[PATCH] D113555: [clangd] Mark macros from preamble for code completion
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 10 03:12:23 PST 2021
kadircet created this revision.
kadircet added reviewers: usaxena95, nridge.
Herald added a subscriber: arphaman.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.
If the main file is a header, mark the marcos defined in its preamble
section as code-completion ready.
Fixes https://github.com/clangd/clangd/issues/921.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D113555
Files:
clang-tools-extra/clangd/index/SymbolCollector.cpp
clang-tools-extra/clangd/unittests/FileIndexTests.cpp
Index: clang-tools-extra/clangd/unittests/FileIndexTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/FileIndexTests.cpp
+++ clang-tools-extra/clangd/unittests/FileIndexTests.cpp
@@ -727,6 +727,19 @@
EXPECT_THAT(MT.child("f3").children(), ElementsAre(Pair("relations", _)));
EXPECT_THAT(MT.child("f3").total(), Gt(0U));
}
+
+TEST(FileIndexTest, MacrosFromMainFile) {
+ FileIndex Idx;
+ TestTU TU;
+ TU.Code = "#pragma once\n#define FOO";
+ TU.Filename = "foo.h";
+ auto AST = TU.build();
+ Idx.updateMain(testPath(TU.Filename), AST);
+
+ auto &FooSymbol = findSymbol(runFuzzyFind(Idx, ""), "FOO");
+ EXPECT_TRUE(FooSymbol.Flags & Symbol::IndexedForCodeCompletion);
+}
+
} // namespace
} // namespace clangd
} // namespace clang
Index: clang-tools-extra/clangd/index/SymbolCollector.cpp
===================================================================
--- clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -564,6 +564,10 @@
S.SymInfo.Lang = index::SymbolLanguage::C;
S.Origin = Opts.Origin;
S.CanonicalDeclaration = R.Location;
+ if (!HeaderFileURIs->getIncludeHeader(SM.getMainFileID()).empty()) {
+ S.Flags |= Symbol::IndexedForCodeCompletion;
+ S.Flags |= Symbol::VisibleOutsideFile;
+ }
Symbols.insert(S);
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113555.386107.patch
Type: text/x-patch
Size: 1439 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211110/d474043b/attachment.bin>
More information about the cfe-commits
mailing list