Index: clangd/tool/ClangdMain.cpp =================================================================== --- clangd/tool/ClangdMain.cpp +++ clangd/tool/ClangdMain.cpp @@ -253,14 +253,27 @@ Optional CompileCommandsDirPath; if (CompileCommandsDir.empty()) { CompileCommandsDirPath = None; - } else if (!sys::path::is_absolute(CompileCommandsDir) || - !sys::fs::exists(CompileCommandsDir)) { - errs() << "Path specified by --compile-commands-dir either does not " - "exist or is not an absolute " - "path. The argument will be ignored.\n"; + } else if (!sys::fs::exists(CompileCommandsDir)) { + errs() << "Path specified by --compile-commands-dir does not exist. The " + "argument will be ignored.\n"; CompileCommandsDirPath = None; } else { - CompileCommandsDirPath = CompileCommandsDir; + // If the compile-commands-dir arg path is absolute, use it directly. If + // the path is relative, try to convert it to an absolute path first. + if (sys::path::is_absolute(CompileCommandsDir)) { + CompileCommandsDirPath = CompileCommandsDir; + } else { + SmallString<128> Path(CompileCommandsDir); + std::error_code EC = sys::fs::make_absolute(Path); + if (EC) { + errs() << "Error while converting the relative path specified by " + "--compile-commands-dir to an absolute path: " + << EC.message() << ". The argument will be ignored.\n"; + CompileCommandsDirPath = None; + } else { + CompileCommandsDirPath = Path.str(); + } + } } ClangdServer::Options Opts;