Skip to content

Conversation

@mrexodia
Copy link
Contributor

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
Contributor Author

@badumbatish
Copy link
Contributor

hi @kadircet , i'm not in the clangd team but would this be a helpful addition to the clangd functionality? (I've tagged you in the reviewer section just in case)

Copy link
Contributor

@vbvictor vbvictor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for raising this once again.

Would be good to add release notes here:

Improvements to clangd
----------------------

Copilot AI review requested due to automatic review settings December 12, 2025 23:57
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR automatically creates a .gitignore file in the clangd index directory (.cache/clangd/index/) to prevent index files from being tracked by Git. This improves user experience by eliminating the need for manual .gitignore configuration.

Key Changes:

  • Adds automatic .gitignore creation during index directory initialization
  • Updates release notes to document this new behavior

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
clang-tools-extra/clangd/index/BackgroundIndexStorage.cpp Implements .gitignore creation logic in the DiskBackedIndexStorage constructor, creating a wildcard ignore file when the index directory is first initialized
clang-tools-extra/docs/ReleaseNotes.rst Documents the new automatic .gitignore file creation feature in the Miscellaneous section

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link

github-actions bot commented Dec 13, 2025

🐧 Linux x64 Test Results

  • 3050 tests passed
  • 7 tests skipped

✅ The build succeeded and all tests passed.

@github-actions
Copy link

github-actions bot commented Dec 13, 2025

🪟 Windows x64 Test Results

  • 2988 tests passed
  • 30 tests skipped

✅ The build succeeded and all tests passed.

@mrexodia mrexodia force-pushed the clangd-gitignore branch 2 times, most recently from 1d0f189 to 3903c37 Compare December 13, 2025 02:40
@mrexodia
Copy link
Contributor Author

Thanks a lot for the help everyone! I added a test and made sure everything works locally.

image

@sweiglbosker
Copy link
Member

I think this can be merged if it looks good to you @kadircet

@kadircet
Copy link
Member

thanks a lot!

@kadircet kadircet merged commit 5785b4a into llvm:main Dec 15, 2025
11 checks passed
@github-actions
Copy link

@mrexodia Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

mahesh-attarde pushed a commit to mahesh-attarde/llvm-project that referenced this pull request Dec 19, 2025
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](https://github.com/astral-sh/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.
valadaptive pushed a commit to valadaptive/llvm-project that referenced this pull request Dec 24, 2025
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](https://github.com/astral-sh/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.
@mrexodia mrexodia deleted the clangd-gitignore branch January 11, 2026 10:52
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.

6 participants