Index: clang-tools-extra/trunk/clangd/IncludeFixer.cpp =================================================================== --- clang-tools-extra/trunk/clangd/IncludeFixer.cpp +++ clang-tools-extra/trunk/clangd/IncludeFixer.cpp @@ -79,6 +79,12 @@ 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. Index: clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp =================================================================== --- clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp +++ clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp @@ -368,11 +368,14 @@ 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 @@ 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("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("qualified"), + 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",