Skip to content

Conversation

@mrexodia
Copy link

This solves a common issue where users have to manually add the .cache/clangd/index/ folder to their .gitignore. I got this idea from ruff, which creates .ruff_cache/.gitignore and it would greatly improve the user experience for everyone without requiring per-computer configurations and without any significant cost.

@github-actions
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented Nov 29, 2025

@llvm/pr-subscribers-clang-tools-extra

@llvm/pr-subscribers-clangd

Author: Duncan Ogilvie (mrexodia)

Changes

This solves a common issue where users have to manually add the .cache/clangd/index/ folder to their .gitignore. I got this idea from ruff, which creates .ruff_cache/.gitignore and it would greatly improve the user experience for everyone without requiring per-computer configurations and without any significant cost.


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

1 Files Affected:

  • (modified) clang-tools-extra/clangd/index/BackgroundIndexStorage.cpp (+14)
diff --git a/clang-tools-extra/clangd/index/BackgroundIndexStorage.cpp b/clang-tools-extra/clangd/index/BackgroundIndexStorage.cpp
index d887b09482a95..1dff0b55f82cd 100644
--- a/clang-tools-extra/clangd/index/BackgroundIndexStorage.cpp
+++ b/clang-tools-extra/clangd/index/BackgroundIndexStorage.cpp
@@ -45,6 +45,20 @@ class DiskBackedIndexStorage : public BackgroundIndexStorage {
     if (EC != OK) {
       elog("Failed to create directory {0} for index storage: {1}",
            DiskShardRoot, EC.message());
+    } else {
+      // Create a .gitignore file in the directory to ignore all files.
+      llvm::SmallString<128> GitignorePath(DiskShardRoot);
+      llvm::sys::path::append(GitignorePath, ".gitignore");
+      if (!llvm::sys::fs::exists(GitignorePath)) {
+        llvm::raw_fd_ostream GitignoreFile(GitignorePath, EC,
+                                          llvm::sys::fs::OF_None);
+        if (EC == OK) {
+          GitignoreFile << "*\n";
+        } else {
+          elog("Failed to create .gitignore in {0}: {1}", DiskShardRoot,
+              EC.message());
+        }
+      }
     }
   }
 

@github-actions
Copy link

github-actions bot commented Nov 29, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@mrexodia
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants