[PATCH] D113555: [clangd] Mark macros from preamble for code completion
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 12 05:07:09 PST 2021
This revision was automatically updated to reflect the committed changes.
kadircet marked an inline comment as done.
Closed by commit rG7d668ae38d2d: [clangd] Mark macros from preamble for code completion (authored by kadircet).
Changed prior to commit:
https://reviews.llvm.org/D113555?vs=386107&id=386807#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D113555/new/
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,12 @@
S.SymInfo.Lang = index::SymbolLanguage::C;
S.Origin = Opts.Origin;
S.CanonicalDeclaration = R.Location;
+ // Make the macro visible for code completion if main file is an
+ // include-able header.
+ 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.386807.patch
Type: text/x-patch
Size: 1546 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211112/7589698e/attachment-0001.bin>
More information about the cfe-commits
mailing list