https://github.com/mrexodia created https://github.com/llvm/llvm-project/pull/170003
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. >From 7c929d3fa47612e48ecc390a183c481c7087a6d6 Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie <[email protected]> Date: Sat, 29 Nov 2025 17:07:37 +0100 Subject: [PATCH] Add .gitignore file in .cache/clangd/index --- .../clangd/index/BackgroundIndexStorage.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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()); + } + } } } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
