[PATCH] D58135: [clangd] Handle a few more diag kinds in include fixer.
Eric Liu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 12 09:25:39 PST 2019
ioeric created this revision.
ioeric added a reviewer: sammccall.
Herald added subscribers: cfe-commits, kadircet, arphaman, jkorous, MaskRay, ilya-biryukov.
Herald added a project: clang.
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D58135
Files:
clangd/IncludeFixer.cpp
unittests/clangd/DiagnosticsTests.cpp
Index: unittests/clangd/DiagnosticsTests.cpp
===================================================================
--- unittests/clangd/DiagnosticsTests.cpp
+++ 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",
Index: clangd/IncludeFixer.cpp
===================================================================
--- clangd/IncludeFixer.cpp
+++ 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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58135.186494.patch
Type: text/x-patch
Size: 2654 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190212/c45ac1bb/attachment.bin>
More information about the cfe-commits
mailing list