Skip to content

Commit a1c0d62

Browse files
boomanaiden154github-actions[bot]
authored andcommitted
Automerge: Revert "[clangd] Add a (currently hidden) --strong-workspace-mode flag (#155905)"
This reverts commit 2fa4927. This caused sanitizer bots to fail and sanitizer errors to show up in our downstream testing: ``` [ RUN ] LSPTest.DiagnosticsHeaderSaved <<< initialize: {} <-- initialize(0) third_party/llvm/llvm-project/clang-tools-extra/clangd/ClangdLSPServer.cpp:557:14: runtime error: load of value 112, which is not a valid value for type 'bool' ``` With ASan at -O1.
2 parents c5832c4 + 01c4eb5 commit a1c0d62

File tree

7 files changed

+16
-92
lines changed

7 files changed

+16
-92
lines changed

clang-tools-extra/clangd/ClangdLSPServer.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,6 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
554554
if (const auto &Dir = Params.initializationOptions.compilationDatabasePath)
555555
CDBOpts.CompileCommandsDir = Dir;
556556
CDBOpts.ContextProvider = Opts.ContextProvider;
557-
if (Opts.StrongWorkspaceMode)
558-
CDBOpts.applyFallbackWorkingDirectory(Opts.WorkspaceRoot);
559557
BaseCDB =
560558
std::make_unique<DirectoryBasedGlobalCompilationDatabase>(CDBOpts);
561559
}

clang-tools-extra/clangd/ClangdServer.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,6 @@ class ClangdServer {
152152
/// FIXME: If not set, should use the current working directory.
153153
std::optional<std::string> WorkspaceRoot;
154154

155-
/// Sets an alternate mode of operation. Current effects are:
156-
/// - Using the current working directory as the working directory for
157-
/// fallback commands
158-
bool StrongWorkspaceMode;
159-
160155
/// The resource directory is used to find internal headers, overriding
161156
/// defaults and -resource-dir compiler flag).
162157
/// If std::nullopt, ClangdServer calls

clang-tools-extra/clangd/GlobalCompilationDatabase.cpp

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ GlobalCompilationDatabase::getFallbackCommand(PathRef File) const {
6464
if (FileExtension.empty() || FileExtension == ".h")
6565
Argv.push_back("-xobjective-c++-header");
6666
Argv.push_back(std::string(File));
67-
tooling::CompileCommand Cmd(FallbackWorkingDirectory
68-
? *FallbackWorkingDirectory
69-
: llvm::sys::path::parent_path(File),
67+
tooling::CompileCommand Cmd(llvm::sys::path::parent_path(File),
7068
llvm::sys::path::filename(File), std::move(Argv),
7169
/*Output=*/"");
7270
Cmd.Heuristic = "clangd fallback";
@@ -351,8 +349,7 @@ bool DirectoryBasedGlobalCompilationDatabase::DirectoryCache::load(
351349

352350
DirectoryBasedGlobalCompilationDatabase::
353351
DirectoryBasedGlobalCompilationDatabase(const Options &Opts)
354-
: GlobalCompilationDatabase(Opts.FallbackWorkingDirectory), Opts(Opts),
355-
Broadcaster(std::make_unique<BroadcastThread>(*this)) {
352+
: Opts(Opts), Broadcaster(std::make_unique<BroadcastThread>(*this)) {
356353
if (!this->Opts.ContextProvider)
357354
this->Opts.ContextProvider = [](llvm::StringRef) {
358355
return Context::current().clone();
@@ -463,21 +460,6 @@ DirectoryBasedGlobalCompilationDatabase::lookupCDB(
463460
return Result;
464461
}
465462

466-
void DirectoryBasedGlobalCompilationDatabase::Options::
467-
applyFallbackWorkingDirectory(
468-
std::optional<std::string> FallbackWorkingDirectory) {
469-
if (FallbackWorkingDirectory)
470-
this->FallbackWorkingDirectory = *FallbackWorkingDirectory;
471-
else {
472-
// Clangd is running in strong workspace mode but the client didn't
473-
// specify a workspace path in the `initialize` request.
474-
// Fallback to current working directory.
475-
SmallString<256> CWD;
476-
llvm::sys::fs::current_path(CWD);
477-
this->FallbackWorkingDirectory = std::string(CWD);
478-
}
479-
}
480-
481463
// The broadcast thread announces files with new compile commands to the world.
482464
// Primarily this is used to enqueue them for background indexing.
483465
//
@@ -777,10 +759,9 @@ DirectoryBasedGlobalCompilationDatabase::getProjectModules(PathRef File) const {
777759

778760
OverlayCDB::OverlayCDB(const GlobalCompilationDatabase *Base,
779761
std::vector<std::string> FallbackFlags,
780-
CommandMangler Mangler,
781-
std::optional<std::string> FallbackWorkingDirectory)
782-
: DelegatingCDB(Base, FallbackWorkingDirectory),
783-
Mangler(std::move(Mangler)), FallbackFlags(std::move(FallbackFlags)) {}
762+
CommandMangler Mangler)
763+
: DelegatingCDB(Base), Mangler(std::move(Mangler)),
764+
FallbackFlags(std::move(FallbackFlags)) {}
784765

785766
std::optional<tooling::CompileCommand>
786767
OverlayCDB::getCompileCommand(PathRef File) const {
@@ -863,20 +844,16 @@ OverlayCDB::getProjectModules(PathRef File) const {
863844
return MDB;
864845
}
865846

866-
DelegatingCDB::DelegatingCDB(
867-
const GlobalCompilationDatabase *Base,
868-
std::optional<std::string> FallbackWorkingDirectory)
869-
: GlobalCompilationDatabase(FallbackWorkingDirectory), Base(Base) {
847+
DelegatingCDB::DelegatingCDB(const GlobalCompilationDatabase *Base)
848+
: Base(Base) {
870849
if (Base)
871850
BaseChanged = Base->watch([this](const std::vector<std::string> Changes) {
872851
OnCommandChanged.broadcast(Changes);
873852
});
874853
}
875854

876-
DelegatingCDB::DelegatingCDB(
877-
std::unique_ptr<GlobalCompilationDatabase> Base,
878-
std::optional<std::string> FallbackWorkingDirectory)
879-
: DelegatingCDB(Base.get(), FallbackWorkingDirectory) {
855+
DelegatingCDB::DelegatingCDB(std::unique_ptr<GlobalCompilationDatabase> Base)
856+
: DelegatingCDB(Base.get()) {
880857
BaseOwner = std::move(Base);
881858
}
882859

clang-tools-extra/clangd/GlobalCompilationDatabase.h

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ struct ProjectInfo {
3535
/// Provides compilation arguments used for parsing C and C++ files.
3636
class GlobalCompilationDatabase {
3737
public:
38-
GlobalCompilationDatabase(
39-
std::optional<std::string> FallbackWorkingDirectory = std::nullopt)
40-
: FallbackWorkingDirectory(FallbackWorkingDirectory) {}
4138
virtual ~GlobalCompilationDatabase() = default;
4239

4340
/// If there are any known-good commands for building this file, returns one.
@@ -72,19 +69,14 @@ class GlobalCompilationDatabase {
7269
}
7370

7471
protected:
75-
std::optional<std::string> FallbackWorkingDirectory;
7672
mutable CommandChanged OnCommandChanged;
7773
};
7874

7975
// Helper class for implementing GlobalCompilationDatabases that wrap others.
8076
class DelegatingCDB : public GlobalCompilationDatabase {
8177
public:
82-
DelegatingCDB(
83-
const GlobalCompilationDatabase *Base,
84-
std::optional<std::string> FallbackWorkingDirectory = std::nullopt);
85-
DelegatingCDB(
86-
std::unique_ptr<GlobalCompilationDatabase> Base,
87-
std::optional<std::string> FallbackWorkingDirectory = std::nullopt);
78+
DelegatingCDB(const GlobalCompilationDatabase *Base);
79+
DelegatingCDB(std::unique_ptr<GlobalCompilationDatabase> Base);
8880

8981
std::optional<tooling::CompileCommand>
9082
getCompileCommand(PathRef File) const override;
@@ -125,12 +117,6 @@ class DirectoryBasedGlobalCompilationDatabase
125117
// Only look for a compilation database in this one fixed directory.
126118
// FIXME: fold this into config/context mechanism.
127119
std::optional<Path> CompileCommandsDir;
128-
// Working directory for fallback commands
129-
// If unset, parent directory of file should be used
130-
std::optional<std::string> FallbackWorkingDirectory;
131-
132-
void applyFallbackWorkingDirectory(
133-
std::optional<std::string> FallbackWorkingDirectory);
134120
};
135121

136122
DirectoryBasedGlobalCompilationDatabase(const Options &Opts);
@@ -208,11 +194,9 @@ class OverlayCDB : public DelegatingCDB {
208194
// Base may be null, in which case no entries are inherited.
209195
// FallbackFlags are added to the fallback compile command.
210196
// Adjuster is applied to all commands, fallback or not.
211-
OverlayCDB(
212-
const GlobalCompilationDatabase *Base,
213-
std::vector<std::string> FallbackFlags = {},
214-
CommandMangler Mangler = nullptr,
215-
std::optional<std::string> FallbackWorkingDirectory = std::nullopt);
197+
OverlayCDB(const GlobalCompilationDatabase *Base,
198+
std::vector<std::string> FallbackFlags = {},
199+
CommandMangler Mangler = nullptr);
216200

217201
std::optional<tooling::CompileCommand>
218202
getCompileCommand(PathRef File) const override;

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,6 @@ class Checker {
169169
bool buildCommand(const ThreadsafeFS &TFS) {
170170
log("Loading compilation database...");
171171
DirectoryBasedGlobalCompilationDatabase::Options CDBOpts(TFS);
172-
if (Opts.StrongWorkspaceMode)
173-
CDBOpts.applyFallbackWorkingDirectory(Opts.WorkspaceRoot);
174172
CDBOpts.CompileCommandsDir =
175173
Config::current().CompileFlags.CDBSearch.FixedCDBPath;
176174
BaseCDB =
@@ -180,10 +178,8 @@ class Checker {
180178
getSystemIncludeExtractor(llvm::ArrayRef(Opts.QueryDriverGlobs));
181179
if (Opts.ResourceDir)
182180
Mangler.ResourceDir = *Opts.ResourceDir;
183-
184181
CDB = std::make_unique<OverlayCDB>(
185-
BaseCDB.get(), std::vector<std::string>{}, std::move(Mangler),
186-
CDBOpts.FallbackWorkingDirectory);
182+
BaseCDB.get(), std::vector<std::string>{}, std::move(Mangler));
187183

188184
if (auto TrueCmd = CDB->getCompileCommand(File)) {
189185
Cmd = std::move(*TrueCmd);
@@ -506,7 +502,7 @@ bool check(llvm::StringRef File, const ThreadsafeFS &TFS,
506502
config::DiagnosticCallback Diag) const override {
507503
config::Fragment F;
508504
// If we're timing clang-tidy checks, implicitly disabling the slow ones
509-
// is counterproductive!
505+
// is counterproductive!
510506
if (CheckTidyTime.getNumOccurrences())
511507
F.Diagnostics.ClangTidy.FastCheckFilter.emplace("None");
512508
return {std::move(F).compile(Diag)};

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -500,17 +500,6 @@ opt<bool> EnableConfig{
500500
init(true),
501501
};
502502

503-
opt<bool> StrongWorkspaceMode{
504-
"strong-workspace-mode",
505-
cat(Features),
506-
desc("An alternate mode of operation for clangd, where the clangd instance "
507-
"is used to edit a single workspace.\n"
508-
"When enabled, fallback commands use the workspace directory as their "
509-
"working directory instead of the parent folder."),
510-
init(false),
511-
Hidden,
512-
};
513-
514503
opt<bool> UseDirtyHeaders{"use-dirty-headers", cat(Misc),
515504
desc("Use files open in the editor when parsing "
516505
"headers instead of reading from the disk"),
@@ -918,7 +907,6 @@ clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment var
918907
}
919908
if (!ResourceDir.empty())
920909
Opts.ResourceDir = ResourceDir;
921-
Opts.StrongWorkspaceMode = StrongWorkspaceMode;
922910
Opts.BuildDynamicSymbolIndex = true;
923911
#if CLANGD_ENABLE_REMOTE
924912
if (RemoteIndexAddress.empty() != ProjectRoot.empty()) {

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,6 @@ TEST(GlobalCompilationDatabaseTest, FallbackCommand) {
5555
testPath("foo/bar")));
5656
}
5757

58-
TEST(GlobalCompilationDatabaseTest, FallbackWorkingDirectory) {
59-
MockFS TFS;
60-
DirectoryBasedGlobalCompilationDatabase::Options CDBOpts(TFS);
61-
CDBOpts.applyFallbackWorkingDirectory(testPath("foo"));
62-
EXPECT_EQ(CDBOpts.FallbackWorkingDirectory, testPath("foo"));
63-
64-
DirectoryBasedGlobalCompilationDatabase DB(CDBOpts);
65-
auto Cmd = DB.getFallbackCommand(testPath("foo/src/bar.cc"));
66-
EXPECT_EQ(Cmd.Directory, testPath("foo"));
67-
EXPECT_THAT(Cmd.CommandLine,
68-
ElementsAre("clang", testPath("foo/src/bar.cc")));
69-
EXPECT_EQ(Cmd.Output, "");
70-
}
71-
7258
static tooling::CompileCommand cmd(llvm::StringRef File, llvm::StringRef Arg) {
7359
return tooling::CompileCommand(
7460
testRoot(), File, {"clang", std::string(Arg), std::string(File)}, "");

0 commit comments

Comments
 (0)