[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:39:16 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clangd

Author: SR_team (sr-tream)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/72635.diff


1 Files Affected:

- (modified) clang-tools-extra/clangd/ClangdLSPServer.cpp (+4-1) 


``````````diff
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);
     }
   }

``````````

</details>


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


More information about the cfe-commits mailing list