@@ -55,7 +55,7 @@ void actOnAllParentDirectories(PathRef FileName,
5555} // namespace
5656
5757tooling::CompileCommand
58- GlobalCompilationDatabase::getFallbackCommand (PathRef File, std::optional<std::string> ProjectRoot ) const {
58+ GlobalCompilationDatabase::getFallbackCommand (PathRef File, bool StrongWorkspaceMode ) const {
5959 std::vector<std::string> Argv = {" clang" };
6060 // Clang treats .h files as C by default and files without extension as linker
6161 // input, resulting in unhelpful diagnostics.
@@ -64,7 +64,12 @@ GlobalCompilationDatabase::getFallbackCommand(PathRef File, std::optional<std::s
6464 if (FileExtension.empty () || FileExtension == " .h" )
6565 Argv.push_back (" -xobjective-c++-header" );
6666 Argv.push_back (std::string (File));
67- tooling::CompileCommand Cmd (ProjectRoot ? *ProjectRoot : llvm::sys::path::parent_path (File),
67+ SmallString<256 > WorkingDir;
68+ if (StrongWorkspaceMode)
69+ llvm::sys::fs::current_path (WorkingDir);
70+ else
71+ WorkingDir = llvm::sys::path::parent_path (File);
72+ tooling::CompileCommand Cmd (WorkingDir,
6873 llvm::sys::path::filename (File), std::move (Argv),
6974 /* Output=*/ " " );
7075 Cmd.Heuristic = " clangd fallback" ;
@@ -797,8 +802,8 @@ OverlayCDB::getCompileCommand(PathRef File) const {
797802 return Cmd;
798803}
799804
800- tooling::CompileCommand OverlayCDB::getFallbackCommand (PathRef File, std::optional<std::string> ProjectRoot ) const {
801- auto Cmd = DelegatingCDB::getFallbackCommand (File, ProjectRoot );
805+ tooling::CompileCommand OverlayCDB::getFallbackCommand (PathRef File, bool StrongWorkspaceMode ) const {
806+ auto Cmd = DelegatingCDB::getFallbackCommand (File, StrongWorkspaceMode );
802807 std::lock_guard<std::mutex> Lock (Mutex);
803808 Cmd.CommandLine .insert (Cmd.CommandLine .end (), FallbackFlags.begin (),
804809 FallbackFlags.end ());
@@ -877,10 +882,10 @@ DelegatingCDB::getProjectModules(PathRef File) const {
877882 return Base->getProjectModules (File);
878883}
879884
880- tooling::CompileCommand DelegatingCDB::getFallbackCommand (PathRef File, std::optional<std::string> ProjectRoot ) const {
885+ tooling::CompileCommand DelegatingCDB::getFallbackCommand (PathRef File, bool StrongWorkspaceMode ) const {
881886 if (!Base)
882- return GlobalCompilationDatabase::getFallbackCommand (File, ProjectRoot );
883- return Base->getFallbackCommand (File, ProjectRoot );
887+ return GlobalCompilationDatabase::getFallbackCommand (File, StrongWorkspaceMode );
888+ return Base->getFallbackCommand (File, StrongWorkspaceMode );
884889}
885890
886891bool DelegatingCDB::blockUntilIdle (Deadline D) const {
0 commit comments