https://github.com/mrexodia updated https://github.com/llvm/llvm-project/pull/170003
>From 9429f24e4b7a703e0f898cfe555ec5ef448c69f2 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 --- clang-tools-extra/clangd/index/BackgroundIndexStorage.cpp | 8 ++++++++ clang-tools-extra/clangd/test/background-index.test | 4 ++++ clang-tools-extra/docs/ReleaseNotes.rst | 2 ++ 3 files changed, 14 insertions(+) diff --git a/clang-tools-extra/clangd/index/BackgroundIndexStorage.cpp b/clang-tools-extra/clangd/index/BackgroundIndexStorage.cpp index d887b09482a95..e189d0be9f632 100644 --- a/clang-tools-extra/clangd/index/BackgroundIndexStorage.cpp +++ b/clang-tools-extra/clangd/index/BackgroundIndexStorage.cpp @@ -45,7 +45,15 @@ class DiskBackedIndexStorage : public BackgroundIndexStorage { if (EC != OK) { elog("Failed to create directory {0} for index storage: {1}", DiskShardRoot, EC.message()); + return; } + // Create a .gitignore file in the directory to ignore all files. + llvm::SmallString<128> GitignorePath(DiskShardRoot); + llvm::sys::path::append(GitignorePath, ".gitignore"); + llvm::writeToOutput(GitignorePath, [](llvm::raw_ostream &OS) { + OS << "# This file is autogenerated by clangd.\n*\n"; + return llvm::Error::success(); + }); } std::unique_ptr<IndexFileIn> diff --git a/clang-tools-extra/clangd/test/background-index.test b/clang-tools-extra/clangd/test/background-index.test index 1983f0957dccf..6eb418198395a 100644 --- a/clang-tools-extra/clangd/test/background-index.test +++ b/clang-tools-extra/clangd/test/background-index.test @@ -21,3 +21,7 @@ # Test the index is read from disk: delete code and restart clangd. # RUN: rm %/t/foo.cpp # RUN: clangd -background-index -lit-test < %/t/definition.jsonrpc | FileCheck %/t/definition.jsonrpc --check-prefixes=CHECK,USE + +# Test that the the newly created index directories also have a .gitignore file present. +# RUN: ls %/t/.cache/clangd/index/.gitignore +# RUN: ls %/t/sub_dir/.cache/clangd/index/.gitignore diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index a6f80e3721db1..b1a3c7dd9ba07 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -126,6 +126,8 @@ Objective-C Miscellaneous ^^^^^^^^^^^^^ +- Add wildcard ``.gitignore`` file to the clangd index directory. + Improvements to clang-doc ------------------------- _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
