forked from OSchip/llvm-project
[clangd] Disable suffix matching fallback for C during include insertion
Clangd currently doesn't respect language and breaks the builds with include insertion for C. This patch aims to stop the bleeding by not mapping back to CPP standard library headers. Improves https://github.com/clangd/clangd/issues/376. Differential Revision: https://reviews.llvm.org/D88144
This commit is contained in:
parent
27da287507
commit
64168c6d99
|
@ -772,7 +772,10 @@ void CanonicalIncludes::addSystemHeadersMapping(const LangOptions &Language) {
|
||||||
MaxSuffixComponents;
|
MaxSuffixComponents;
|
||||||
}) != SystemHeaderMap->keys().end());
|
}) != SystemHeaderMap->keys().end());
|
||||||
|
|
||||||
StdSuffixHeaderMapping = SystemHeaderMap;
|
// FIXME: Suffix mapping contains invalid entries for C, so only enable it for
|
||||||
|
// CPP.
|
||||||
|
if (Language.CPlusPlus)
|
||||||
|
StdSuffixHeaderMapping = SystemHeaderMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace clangd
|
} // namespace clangd
|
||||||
|
|
|
@ -21,6 +21,10 @@ TEST(CanonicalIncludesTest, CStandardLibrary) {
|
||||||
CI.addSystemHeadersMapping(Language);
|
CI.addSystemHeadersMapping(Language);
|
||||||
// Usual standard library symbols are mapped correctly.
|
// Usual standard library symbols are mapped correctly.
|
||||||
EXPECT_EQ("<stdio.h>", CI.mapHeader("path/stdio.h", "printf"));
|
EXPECT_EQ("<stdio.h>", CI.mapHeader("path/stdio.h", "printf"));
|
||||||
|
// Suffix mapping isn't available for C, instead of mapping to `<cstdio> we
|
||||||
|
// just leave the header as-is.
|
||||||
|
EXPECT_EQ("include/stdio.h",
|
||||||
|
CI.mapHeader("include/stdio.h", "unknown_symbol"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(CanonicalIncludesTest, CXXStandardLibrary) {
|
TEST(CanonicalIncludesTest, CXXStandardLibrary) {
|
||||||
|
|
Loading…
Reference in New Issue