Skip to content

Commit 2ab5fd2

Browse files
committed
[clangd] Retire some flags for uncontroversial, stable features.
And mark a couple to be retired afther the next release branch. Differential Revision: https://reviews.llvm.org/D94727
1 parent e6be5c7 commit 2ab5fd2

File tree

6 files changed

+25
-48
lines changed

6 files changed

+25
-48
lines changed

clang-tools-extra/clangd/ClangdServer.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB,
146146
Opts.CollectMainFileRefs)
147147
: nullptr),
148148
ClangTidyProvider(Opts.ClangTidyProvider),
149-
SuggestMissingIncludes(Opts.SuggestMissingIncludes),
150149
WorkspaceRoot(Opts.WorkspaceRoot),
151150
// Pass a callback into `WorkScheduler` to extract symbols from a newly
152151
// parsed file and rebuild the file index synchronously each time an AST
@@ -201,7 +200,6 @@ void ClangdServer::addDocument(PathRef File, llvm::StringRef Contents,
201200
llvm::StringRef Version,
202201
WantDiagnostics WantDiags, bool ForceRebuild) {
203202
ParseOptions Opts;
204-
Opts.SuggestMissingIncludes = SuggestMissingIncludes;
205203

206204
// Compile command is set asynchronously during update, as it can be slow.
207205
ParseInputs Inputs;

clang-tools-extra/clangd/ClangdServer.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,6 @@ class ClangdServer {
136136
/*RebuildRatio=*/1,
137137
};
138138

139-
bool SuggestMissingIncludes = false;
140-
141139
/// Clangd will execute compiler drivers matching one of these globs to
142140
/// fetch system include path.
143141
std::vector<std::string> QueryDriverGlobs;
@@ -376,10 +374,6 @@ class ClangdServer {
376374
// When set, provides clang-tidy options for a specific file.
377375
TidyProviderRef ClangTidyProvider;
378376

379-
// If this is true, suggest include insertion fixes for diagnostic errors that
380-
// can be caused by missing includes (e.g. member access in incomplete type).
381-
bool SuggestMissingIncludes = false;
382-
383377
// GUARDED_BY(CachedCompletionFuzzyFindRequestMutex)
384378
llvm::StringMap<llvm::Optional<FuzzyFindRequest>>
385379
CachedCompletionFuzzyFindRequestByFile;

clang-tools-extra/clangd/Compiler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class IgnoreDiagnostics : public DiagnosticConsumer {
3737

3838
// Options to run clang e.g. when parsing AST.
3939
struct ParseOptions {
40-
bool SuggestMissingIncludes = false;
40+
// (empty at present, formerly controlled recovery AST, include-fixer etc)
4141
};
4242

4343
/// Information required to run clang, e.g. to parse AST or do code completion.

clang-tools-extra/clangd/ParsedAST.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,7 @@ ParsedAST::build(llvm::StringRef Filename, const ParseInputs &Inputs,
351351
// (e.g. incomplete type) and attach include insertion fixes to diagnostics.
352352
llvm::Optional<IncludeFixer> FixIncludes;
353353
auto BuildDir = VFS->getCurrentWorkingDirectory();
354-
if (Inputs.Opts.SuggestMissingIncludes && Inputs.Index &&
355-
!BuildDir.getError()) {
354+
if (Inputs.Index && !BuildDir.getError()) {
356355
auto Style = getFormatStyleForFile(Filename, Inputs.Contents, *Inputs.TFS);
357356
auto Inserter = std::make_shared<IncludeInserter>(
358357
Filename, Inputs.Contents, Style, BuildDir.get(),

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

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,21 @@ OptionCategory CompileCommands("clangd compilation flags options");
8080
OptionCategory Features("clangd feature options");
8181
OptionCategory Misc("clangd miscellaneous options");
8282
OptionCategory Protocol("clangd protocol and logging options");
83+
OptionCategory Retired("clangd flags no longer in use");
8384
const OptionCategory *ClangdCategories[] = {&Features, &Protocol,
84-
&CompileCommands, &Misc};
85+
&CompileCommands, &Misc, &Retired};
86+
87+
template <typename T> class RetiredFlag {
88+
opt<T> Option;
89+
90+
public:
91+
RetiredFlag(llvm::StringRef Name)
92+
: Option(Name, cat(Retired), desc("Obsolete flag, ignored"), Hidden,
93+
llvm::cl::callback([Name](const T &) {
94+
llvm::errs()
95+
<< "The flag `-" << Name << "` is obsolete and ignored.\n";
96+
})) {}
97+
};
8598

8699
enum CompileArgsFrom { LSPCompileArgs, FilesystemCompileArgs };
87100
opt<CompileArgsFrom> CompileArgsFrom{
@@ -267,15 +280,7 @@ opt<bool> IncludeIneligibleResults{
267280
Hidden,
268281
};
269282

270-
opt<bool> EnableIndex{
271-
"index",
272-
cat(Features),
273-
desc("Enable index-based features. By default, clangd maintains an index "
274-
"built from symbols in opened files. Global index support needs to "
275-
"enabled separatedly"),
276-
init(true),
277-
Hidden,
278-
};
283+
RetiredFlag<bool> EnableIndex("index");
279284

280285
opt<int> LimitResults{
281286
"limit-results",
@@ -285,13 +290,7 @@ opt<int> LimitResults{
285290
init(100),
286291
};
287292

288-
opt<bool> SuggestMissingIncludes{
289-
"suggest-missing-includes",
290-
cat(Features),
291-
desc("Attempts to fix diagnostic errors caused by missing "
292-
"includes using index"),
293-
init(true),
294-
};
293+
RetiredFlag<bool> SuggestMissingIncludes("suggest-missing-includes");
295294

296295
list<std::string> TweakList{
297296
"tweaks",
@@ -308,21 +307,8 @@ opt<bool> CrossFileRename{
308307
init(true),
309308
};
310309

311-
opt<bool> RecoveryAST{
312-
"recovery-ast",
313-
cat(Features),
314-
desc("Preserve expressions in AST for broken code."),
315-
init(false),
316-
Hidden,
317-
};
318-
319-
opt<bool> RecoveryASTType{
320-
"recovery-ast-type",
321-
cat(Features),
322-
desc("Preserve the type for recovery AST."),
323-
init(false),
324-
Hidden,
325-
};
310+
RetiredFlag<bool> RecoveryAST("recovery-ast");
311+
RetiredFlag<bool> RecoveryASTType("recovery-ast-type");
326312

327313
opt<bool> FoldingRanges{
328314
"folding-ranges",
@@ -464,6 +450,7 @@ opt<bool> PrettyPrint{
464450
init(false),
465451
};
466452

453+
// FIXME: retire this flag in llvm 13 release cycle.
467454
opt<bool> AsyncPreamble{
468455
"async-preamble",
469456
cat(Misc),
@@ -487,11 +474,13 @@ opt<bool> EnableConfig{
487474
init(true),
488475
};
489476

477+
// FIXME: retire this flag in llvm 13 release cycle.
490478
opt<bool> CollectMainFileRefs{
491479
"collect-main-file-refs",
492480
cat(Misc),
493481
desc("Store references to main-file-only symbols in the index"),
494482
init(ClangdServer::Options().CollectMainFileRefs),
483+
Hidden,
495484
};
496485

497486
#if defined(__GLIBC__) && CLANGD_MALLOC_TRIM
@@ -770,12 +759,12 @@ clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment var
770759
}
771760
if (!ResourceDir.empty())
772761
Opts.ResourceDir = ResourceDir;
773-
Opts.BuildDynamicSymbolIndex = EnableIndex;
762+
Opts.BuildDynamicSymbolIndex = true;
774763
Opts.CollectMainFileRefs = CollectMainFileRefs;
775764
std::vector<std::unique_ptr<SymbolIndex>> IdxStack;
776765
std::unique_ptr<SymbolIndex> StaticIdx;
777766
std::future<void> AsyncIndexLoad; // Block exit while loading the index.
778-
if (EnableIndex && !IndexFile.empty()) {
767+
if (!IndexFile.empty()) {
779768
// Load the index asynchronously. Meanwhile SwapIndex returns no results.
780769
SwapIndex *Placeholder;
781770
StaticIdx.reset(Placeholder = new SwapIndex(std::make_unique<MemIndex>()));
@@ -872,7 +861,6 @@ clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment var
872861
Opts.ClangTidyProvider = ClangTidyOptProvider;
873862
}
874863
Opts.AsyncPreambleBuilds = AsyncPreamble;
875-
Opts.SuggestMissingIncludes = SuggestMissingIncludes;
876864
Opts.QueryDriverGlobs = std::move(QueryDriverGlobs);
877865
Opts.TweakFilter = [&](const Tweak &T) {
878866
if (T.hidden() && !HiddenFeatures)

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ ParseInputs TestTU::inputs(MockFS &FS) const {
6262
if (ClangTidyProvider)
6363
Inputs.ClangTidyProvider = ClangTidyProvider;
6464
Inputs.Index = ExternalIndex;
65-
if (Inputs.Index)
66-
Inputs.Opts.SuggestMissingIncludes = true;
6765
return Inputs;
6866
}
6967

0 commit comments

Comments
 (0)