[clang-tools-extra] [clangd] Add way to remove file from CDB via LSP (PR #72635)

via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 17 02:38:40 PST 2023


https://github.com/sr-tream created https://github.com/llvm/llvm-project/pull/72635

Currently, impossible to remove irrelevant files from CDB via LSP notification `workspace/didChangeConfiguration`. This PR change clangd behavior to remove file from CDB, when LSP pass empty parameters for them.

>From 587dbb0a2329a0fe06894271405acae5f03bbd7d Mon Sep 17 00:00:00 2001
From: SR_team <me at sr.team>
Date: Fri, 17 Nov 2023 11:58:13 +0200
Subject: [PATCH] Add way to remove file from CDB via LSP

---
 clang-tools-extra/clangd/ClangdLSPServer.cpp | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index a87da252b7a7e9b..0a228df4f0b5f4c 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -1385,7 +1385,10 @@ void ClangdLSPServer::applyConfiguration(
                                 std::move(Entry.second.compilationCommand),
                                 /*Output=*/"");
     if (Old != New) {
-      CDB->setCompileCommand(File, std::move(New));
+      if (New.CommandLine.empty() && New.Directory.empty())
+        CDB->setCompileCommand(File, std::nullopt);
+      else
+        CDB->setCompileCommand(File, std::move(New));
       ModifiedFiles.insert(File);
     }
   }



More information about the cfe-commits mailing list