[clang-tools-extra] 3fcca80 - [clangd] Refine recoveryAST flags in clangd
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 14 04:42:27 PDT 2020
Author: Haojian Wu
Date: 2020-10-14T13:42:11+02:00
New Revision: 3fcca804b2916b68d34523e9f88c77272a256d77
URL: https://github.com/llvm/llvm-project/commit/3fcca804b2916b68d34523e9f88c77272a256d77
DIFF: https://github.com/llvm/llvm-project/commit/3fcca804b2916b68d34523e9f88c77272a256d77.diff
LOG: [clangd] Refine recoveryAST flags in clangd
so that we could start experiment for C.
Previously, these flags in clangd were only meaningful for C++. We need
to flip them for C, this patch repurpose these flags.
- if true, just set it.
- if false, just respect the value in clang.
this would allow us to keep flags on for C++, and optionally flip them on for C.
Differential Revision: https://reviews.llvm.org/D89233
Added:
Modified:
clang-tools-extra/clangd/ClangdServer.h
clang-tools-extra/clangd/Compiler.cpp
clang-tools-extra/clangd/tool/ClangdMain.cpp
clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
clang-tools-extra/clangd/unittests/FindTargetTests.cpp
clang-tools-extra/clangd/unittests/TestTU.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/ClangdServer.h b/clang-tools-extra/clangd/ClangdServer.h
index 555f387ff329..612524aae98d 100644
--- a/clang-tools-extra/clangd/ClangdServer.h
+++ b/clang-tools-extra/clangd/ClangdServer.h
@@ -128,11 +128,13 @@ class ClangdServer {
/// enabled.
ClangTidyOptionsBuilder GetClangTidyOptions;
- /// If true, turn on the `-frecovery-ast` clang flag.
- bool BuildRecoveryAST = true;
+ /// If true, force -frecovery-ast flag.
+ /// If false, respect the value in clang.
+ bool BuildRecoveryAST = false;
- /// If true, turn on the `-frecovery-ast-type` clang flag.
- bool PreserveRecoveryASTType = true;
+ /// If true, force -frecovery-ast-type flag.
+ /// If false, respect the value in clang.
+ bool PreserveRecoveryASTType = false;
/// Clangd's workspace root. Relevant for "workspace" operations not bound
/// to a particular file.
diff --git a/clang-tools-extra/clangd/Compiler.cpp b/clang-tools-extra/clangd/Compiler.cpp
index f5875e2a7971..c22585fc53f9 100644
--- a/clang-tools-extra/clangd/Compiler.cpp
+++ b/clang-tools-extra/clangd/Compiler.cpp
@@ -81,11 +81,11 @@ buildCompilerInvocation(const ParseInputs &Inputs, clang::DiagnosticConsumer &D,
// Don't crash on `#pragma clang __debug parser_crash`
CI->getPreprocessorOpts().DisablePragmaDebugCrash = true;
- // Recovery expression currently only works for C++.
- if (CI->getLangOpts()->CPlusPlus) {
- CI->getLangOpts()->RecoveryAST = Inputs.Opts.BuildRecoveryAST;
- CI->getLangOpts()->RecoveryASTType = Inputs.Opts.PreserveRecoveryASTType;
- }
+ if (Inputs.Opts.BuildRecoveryAST)
+ CI->getLangOpts()->RecoveryAST = true;
+ if (Inputs.Opts.PreserveRecoveryASTType)
+ CI->getLangOpts()->RecoveryASTType = true;
+
return CI;
}
diff --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp b/clang-tools-extra/clangd/tool/ClangdMain.cpp
index 78d8355a2c5d..faa8c7508a93 100644
--- a/clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -310,7 +310,7 @@ opt<bool> CrossFileRename{
opt<bool> RecoveryAST{
"recovery-ast",
cat(Features),
- desc("Preserve expressions in AST for broken code (C++ only)."),
+ desc("Preserve expressions in AST for broken code."),
init(ClangdServer::Options().BuildRecoveryAST),
};
diff --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
index de73bc66a178..510f358920c1 100644
--- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -111,8 +111,6 @@ CodeCompleteResult completions(const TestTU &TU, Position Point,
MockFS FS;
auto Inputs = TU.inputs(FS);
- Inputs.Opts.BuildRecoveryAST = true;
- Inputs.Opts.PreserveRecoveryASTType = true;
IgnoreDiagnostics Diags;
auto CI = buildCompilerInvocation(Inputs, Diags);
if (!CI) {
@@ -1100,8 +1098,6 @@ SignatureHelp signatures(llvm::StringRef Text, Position Point,
MockFS FS;
auto Inputs = TU.inputs(FS);
Inputs.Index = Index.get();
- Inputs.Opts.BuildRecoveryAST = true;
- Inputs.Opts.PreserveRecoveryASTType = true;
IgnoreDiagnostics Diags;
auto CI = buildCompilerInvocation(Inputs, Diags);
if (!CI) {
diff --git a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
index 1ea2aa34f289..a68ea1d6a3dc 100644
--- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -148,6 +148,17 @@ TEST_F(TargetDeclTest, Exprs) {
EXPECT_DECLS("LabelStmt", "label:");
}
+TEST_F(TargetDeclTest, RecoveryForC) {
+ Flags = {"-xc", "-Xclang", "-frecovery-ast"};
+ Code = R"cpp(
+ // error-ok: testing behavior on broken code
+ // int f();
+ int f(int);
+ int x = [[f]]();
+ )cpp";
+ EXPECT_DECLS("DeclRefExpr", "int f(int)");
+}
+
TEST_F(TargetDeclTest, Recovery) {
Code = R"cpp(
// error-ok: testing behavior on broken code
diff --git a/clang-tools-extra/clangd/unittests/TestTU.cpp b/clang-tools-extra/clangd/unittests/TestTU.cpp
index 03254f876721..81b6b43da94b 100644
--- a/clang-tools-extra/clangd/unittests/TestTU.cpp
+++ b/clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -59,8 +59,6 @@ ParseInputs TestTU::inputs(MockFS &FS) const {
FS.OverlayRealFileSystemForModules = true;
Inputs.TFS = &FS;
Inputs.Opts = ParseOptions();
- Inputs.Opts.BuildRecoveryAST = true;
- Inputs.Opts.PreserveRecoveryASTType = true;
Inputs.Opts.ClangTidyOpts.Checks = ClangTidyChecks;
Inputs.Opts.ClangTidyOpts.WarningsAsErrors = ClangTidyWarningsAsErrors;
Inputs.Index = ExternalIndex;
More information about the cfe-commits
mailing list