[clangd] Add include-fixer fixit for no_member_template diagnostic.

Differential Revision: https://reviews.llvm.org/D95365
This commit is contained in:
Haojian Wu 2021-01-25 16:26:17 +01:00
parent e98d5c3192
commit 68dbd1aefe
2 changed files with 11 additions and 2 deletions

View File

@ -100,6 +100,8 @@ std::vector<Fix> IncludeFixer::fix(DiagnosticsEngine::Level DiagLevel,
case diag::err_undeclared_var_use_suggest:
case diag::err_no_member: // Could be no member in namespace.
case diag::err_no_member_suggest:
case diag::err_no_member_template:
case diag::err_no_member_template_suggest:
if (LastUnresolvedName) {
// Try to fix unresolved name caused by missing declaration.
// E.g.

View File

@ -879,11 +879,13 @@ void bar() {
::$global[[Global]] glob;
}
using Type = ns::$template[[Foo]]<int>;
)cpp");
auto TU = TestTU::withCode(Test.code());
auto Index = buildIndexWithSymbol(
{SymbolWithHeader{"ns::X", "unittest:///x.h", "\"x.h\""},
SymbolWithHeader{"Global", "unittest:///global.h", "\"global.h\""}});
SymbolWithHeader{"Global", "unittest:///global.h", "\"global.h\""},
SymbolWithHeader{"ns::Foo", "unittest:///foo.h", "\"foo.h\""}});
TU.ExternalIndex = Index.get();
EXPECT_THAT(
@ -908,7 +910,12 @@ void bar() {
"no type named 'Global' in the global namespace"),
DiagName("typename_nested_not_found"),
WithFix(Fix(Test.range("insert"), "#include \"global.h\"\n",
"Add include \"global.h\" for symbol Global")))));
"Add include \"global.h\" for symbol Global"))),
AllOf(Diag(Test.range("template"),
"no template named 'Foo' in namespace 'ns'"),
DiagName("no_member_template"),
WithFix(Fix(Test.range("insert"), "#include \"foo.h\"\n",
"Add include \"foo.h\" for symbol ns::Foo")))));
}
TEST(IncludeFixerTest, MultipleMatchedSymbols) {