https://github.com/mrexodia updated https://github.com/llvm/llvm-project/pull/170003
>From 1d0f1896d717bbd206f5adda36a5428ae65666b2 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..2c8619ec6aa20 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"); + (void)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 42f35daa942e7..b4358da700e35 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -130,6 +130,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
