[clang-tools-extra] 671eab2 - [clangd] Support IncludeFixer or base specifiers

Sam McCall via cfe-commits cfe-commits at lists.llvm.org
Sat Feb 26 06:46:35 PST 2022


Author: Sam McCall
Date: 2022-02-26T15:45:59+01:00
New Revision: 671eab254a7fc912857b697d5b6e414b71b75a60

URL: https://github.com/llvm/llvm-project/commit/671eab254a7fc912857b697d5b6e414b71b75a60
DIFF: https://github.com/llvm/llvm-project/commit/671eab254a7fc912857b697d5b6e414b71b75a60.diff

LOG: [clangd] Support IncludeFixer or base specifiers

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/IncludeFixer.cpp b/clang-tools-extra/clangd/IncludeFixer.cpp
index 7994e5f49920..66e955270914 100644
--- a/clang-tools-extra/clangd/IncludeFixer.cpp
+++ b/clang-tools-extra/clangd/IncludeFixer.cpp
@@ -20,6 +20,7 @@
 #include "clang/AST/NestedNameSpecifier.h"
 #include "clang/AST/Type.h"
 #include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/DiagnosticParse.h"
 #include "clang/Basic/DiagnosticSema.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SourceLocation.h"
@@ -182,6 +183,8 @@ std::vector<Fix> IncludeFixer::fix(DiagnosticsEngine::Level DiagLevel,
 
   case diag::err_unknown_typename:
   case diag::err_unknown_typename_suggest:
+  case diag::err_unknown_type_or_class_name_suggest:
+  case diag::err_expected_class_name:
   case diag::err_typename_nested_not_found:
   case diag::err_no_template:
   case diag::err_no_template_suggest:

diff  --git a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
index 7de3746d2251..7fd7babe68a7 100644
--- a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -1044,6 +1044,7 @@ void foo() {
   // considered the unresolved type.
   $unqualified2[[X]]::Nested n;
 }
+struct S : $base[[X]] {};
 }
 void bar() {
   ns::$qualified1[[X]] x; // ns:: is valid.
@@ -1087,7 +1088,11 @@ using Type = ns::$template[[Foo]]<int>;
                      "no template named 'Foo' in namespace 'ns'"),
                 diagName("no_member_template"),
                 withFix(Fix(Test.range("insert"), "#include \"foo.h\"\n",
-                            "Include \"foo.h\" for symbol ns::Foo")))));
+                            "Include \"foo.h\" for symbol ns::Foo"))),
+          AllOf(Diag(Test.range("base"), "expected class name"),
+                diagName("expected_class_name"),
+                withFix(Fix(Test.range("insert"), "#include \"x.h\"\n",
+                            "Include \"x.h\" for symbol ns::X")))));
 }
 
 TEST(IncludeFixerTest, MultipleMatchedSymbols) {


        


More information about the cfe-commits mailing list