Skip to content

Commit 3fcca80

Browse files
committed
[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
1 parent 01549dd commit 3fcca80

File tree

6 files changed

+23
-16
lines changed

6 files changed

+23
-16
lines changed

clang-tools-extra/clangd/ClangdServer.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,13 @@ class ClangdServer {
128128
/// enabled.
129129
ClangTidyOptionsBuilder GetClangTidyOptions;
130130

131-
/// If true, turn on the `-frecovery-ast` clang flag.
132-
bool BuildRecoveryAST = true;
131+
/// If true, force -frecovery-ast flag.
132+
/// If false, respect the value in clang.
133+
bool BuildRecoveryAST = false;
133134

134-
/// If true, turn on the `-frecovery-ast-type` clang flag.
135-
bool PreserveRecoveryASTType = true;
135+
/// If true, force -frecovery-ast-type flag.
136+
/// If false, respect the value in clang.
137+
bool PreserveRecoveryASTType = false;
136138

137139
/// Clangd's workspace root. Relevant for "workspace" operations not bound
138140
/// to a particular file.

clang-tools-extra/clangd/Compiler.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ buildCompilerInvocation(const ParseInputs &Inputs, clang::DiagnosticConsumer &D,
8181
// Don't crash on `#pragma clang __debug parser_crash`
8282
CI->getPreprocessorOpts().DisablePragmaDebugCrash = true;
8383

84-
// Recovery expression currently only works for C++.
85-
if (CI->getLangOpts()->CPlusPlus) {
86-
CI->getLangOpts()->RecoveryAST = Inputs.Opts.BuildRecoveryAST;
87-
CI->getLangOpts()->RecoveryASTType = Inputs.Opts.PreserveRecoveryASTType;
88-
}
84+
if (Inputs.Opts.BuildRecoveryAST)
85+
CI->getLangOpts()->RecoveryAST = true;
86+
if (Inputs.Opts.PreserveRecoveryASTType)
87+
CI->getLangOpts()->RecoveryASTType = true;
88+
8989
return CI;
9090
}
9191

clang-tools-extra/clangd/tool/ClangdMain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ opt<bool> CrossFileRename{
310310
opt<bool> RecoveryAST{
311311
"recovery-ast",
312312
cat(Features),
313-
desc("Preserve expressions in AST for broken code (C++ only)."),
313+
desc("Preserve expressions in AST for broken code."),
314314
init(ClangdServer::Options().BuildRecoveryAST),
315315
};
316316

clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ CodeCompleteResult completions(const TestTU &TU, Position Point,
111111

112112
MockFS FS;
113113
auto Inputs = TU.inputs(FS);
114-
Inputs.Opts.BuildRecoveryAST = true;
115-
Inputs.Opts.PreserveRecoveryASTType = true;
116114
IgnoreDiagnostics Diags;
117115
auto CI = buildCompilerInvocation(Inputs, Diags);
118116
if (!CI) {
@@ -1100,8 +1098,6 @@ SignatureHelp signatures(llvm::StringRef Text, Position Point,
11001098
MockFS FS;
11011099
auto Inputs = TU.inputs(FS);
11021100
Inputs.Index = Index.get();
1103-
Inputs.Opts.BuildRecoveryAST = true;
1104-
Inputs.Opts.PreserveRecoveryASTType = true;
11051101
IgnoreDiagnostics Diags;
11061102
auto CI = buildCompilerInvocation(Inputs, Diags);
11071103
if (!CI) {

clang-tools-extra/clangd/unittests/FindTargetTests.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,17 @@ TEST_F(TargetDeclTest, Exprs) {
148148
EXPECT_DECLS("LabelStmt", "label:");
149149
}
150150

151+
TEST_F(TargetDeclTest, RecoveryForC) {
152+
Flags = {"-xc", "-Xclang", "-frecovery-ast"};
153+
Code = R"cpp(
154+
// error-ok: testing behavior on broken code
155+
// int f();
156+
int f(int);
157+
int x = [[f]]();
158+
)cpp";
159+
EXPECT_DECLS("DeclRefExpr", "int f(int)");
160+
}
161+
151162
TEST_F(TargetDeclTest, Recovery) {
152163
Code = R"cpp(
153164
// error-ok: testing behavior on broken code

clang-tools-extra/clangd/unittests/TestTU.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ ParseInputs TestTU::inputs(MockFS &FS) const {
5959
FS.OverlayRealFileSystemForModules = true;
6060
Inputs.TFS = &FS;
6161
Inputs.Opts = ParseOptions();
62-
Inputs.Opts.BuildRecoveryAST = true;
63-
Inputs.Opts.PreserveRecoveryASTType = true;
6462
Inputs.Opts.ClangTidyOpts.Checks = ClangTidyChecks;
6563
Inputs.Opts.ClangTidyOpts.WarningsAsErrors = ClangTidyWarningsAsErrors;
6664
Inputs.Index = ExternalIndex;

0 commit comments

Comments
 (0)