forked from OSchip/llvm-project
[clangd] Handle a few more diag kinds in include fixer.
Reviewers: sammccall Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58135 llvm-svn: 353926
This commit is contained in:
parent
e47f89cb2c
commit
da2ed56fea
|
@ -79,6 +79,12 @@ std::vector<Fix> IncludeFixer::fix(DiagnosticsEngine::Level DiagLevel,
|
|||
case diag::err_typename_nested_not_found:
|
||||
case diag::err_no_template:
|
||||
case diag::err_no_template_suggest:
|
||||
case diag::err_undeclared_use:
|
||||
case diag::err_undeclared_use_suggest:
|
||||
case diag::err_undeclared_var_use:
|
||||
case diag::err_undeclared_var_use_suggest:
|
||||
case diag::err_no_member: // Could be no member in namespace.
|
||||
case diag::err_no_member_suggest:
|
||||
if (LastUnresolvedName) {
|
||||
// Try to fix unresolved name caused by missing declaraion.
|
||||
// E.g.
|
||||
|
|
|
@ -368,11 +368,14 @@ TEST(IncludeFixerTest, Typo) {
|
|||
Annotations Test(R"cpp(
|
||||
$insert[[]]namespace ns {
|
||||
void foo() {
|
||||
$unqualified[[X]] x;
|
||||
$unqualified1[[X]] x;
|
||||
$unqualified2[[X]]::Nested n;
|
||||
}
|
||||
}
|
||||
void bar() {
|
||||
ns::$qualified[[X]] x; // ns:: is valid.
|
||||
ns::$qualified1[[X]] x; // ns:: is valid.
|
||||
ns::$qualified2[[X]](); // Error: no member in namespace
|
||||
|
||||
::$global[[Global]] glob;
|
||||
}
|
||||
)cpp");
|
||||
|
@ -385,13 +388,21 @@ void bar() {
|
|||
EXPECT_THAT(
|
||||
TU.build().getDiagnostics(),
|
||||
UnorderedElementsAre(
|
||||
AllOf(Diag(Test.range("unqualified"), "unknown type name 'X'"),
|
||||
AllOf(Diag(Test.range("unqualified1"), "unknown type name 'X'"),
|
||||
WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
|
||||
"Add include \"x.h\" for symbol ns::X"))),
|
||||
AllOf(Diag(Test.range("qualified"),
|
||||
AllOf(Diag(Test.range("unqualified2"),
|
||||
"use of undeclared identifier 'X'"),
|
||||
WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
|
||||
"Add include \"x.h\" for symbol ns::X"))),
|
||||
AllOf(Diag(Test.range("qualified1"),
|
||||
"no type named 'X' in namespace 'ns'"),
|
||||
WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
|
||||
"Add include \"x.h\" for symbol ns::X"))),
|
||||
AllOf(Diag(Test.range("qualified2"),
|
||||
"no member named 'X' in namespace 'ns'"),
|
||||
WithFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
|
||||
"Add include \"x.h\" for symbol ns::X"))),
|
||||
AllOf(Diag(Test.range("global"),
|
||||
"no type named 'Global' in the global namespace"),
|
||||
WithFix(Fix(Test.range("insert"), "#include \"global.h\"\n",
|
||||
|
|
Loading…
Reference in New Issue