[PATCH] D58135: [clangd] Handle a few more diag kinds in include fixer.

Eric Liu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 13 00:58:57 PST 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL353926: [clangd] Handle a few more diag kinds in include fixer. (authored by ioeric, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58135/new/

https://reviews.llvm.org/D58135

Files:
  clang-tools-extra/trunk/clangd/IncludeFixer.cpp
  clang-tools-extra/trunk/unittests/clangd/DiagnosticsTests.cpp


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",


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58135.186598.patch
Type: text/x-patch
Size: 2798 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190213/8335bd4e/attachment.bin>


More information about the llvm-commits mailing list