[clang-tools-extra] [clangd] Fix SIGSEGV crash when receiving a textDocument/didOpen request with the URI pointing to a directory (PR #177834)

Nathan Ridge via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 30 00:06:58 PST 2026


================
@@ -730,6 +731,9 @@ void ClangdLSPServer::onSync(const NoParams &, Callback<std::nullptr_t> Reply) {
 void ClangdLSPServer::onDocumentDidOpen(
     const DidOpenTextDocumentParams &Params) {
   PathRef File = Params.textDocument.uri.file();
+  if (llvm::sys::fs::is_directory(File)) {
+    return;
----------------
HighCommander4 wrote:

We shouldn't silently early-return, let's log an error similar to [this](https://searchfox.org/llvm/rev/3f1386b9861758beb7a9ba15c24bdba3a9f8c03d/clang-tools-extra/clangd/ClangdLSPServer.cpp#761).

(A fancier thing we could do is produce a diagnostic here in clangd code and send it to the client with `textDocument/publishDiagnostics`, but I'm guessing the utility of that would be limited since the client is probably also not going to be able to do its usual thing (e.g. show an editor) for a directory.)

https://github.com/llvm/llvm-project/pull/177834


More information about the cfe-commits mailing list