-
Notifications
You must be signed in to change notification settings - Fork 16.1k
Add .gitignore file in .cache/clangd/index #170003
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
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 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. |
|
@llvm/pr-subscribers-clang-tools-extra @llvm/pr-subscribers-clangd Author: Duncan Ogilvie (mrexodia) ChangesThis solves a common issue where users have to manually add the Full diff: https://github.com/llvm/llvm-project/pull/170003.diff 1 Files Affected:
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());
+ }
+ }
}
}
|
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
7c929d3 to
7c74cf4
Compare
|
|
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) |
vbvictor
left a comment
There was a problem hiding this 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:
llvm-project/clang-tools-extra/docs/ReleaseNotes.rst
Lines 89 to 90 in 333ee93
| Improvements to clangd | |
| ---------------------- |
7c74cf4 to
cfcbfba
Compare
There was a problem hiding this 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
.gitignorecreation 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.
cfcbfba to
9429f24
Compare
🐧 Linux x64 Test Results
✅ The build succeeded and all tests passed. |
🪟 Windows x64 Test Results
✅ The build succeeded and all tests passed. |
1d0f189 to
3903c37
Compare
3903c37 to
fcaec12
Compare
|
I think this can be merged if it looks good to you @kadircet |
|
thanks a lot! |
|
@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! |
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.
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.

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/.gitignoreand it would greatly improve the user experience for everyone without requiring per-computer configurations and without any significant cost.