Skip to content

Commit 9b55bc4

Browse files
committed
[clangd] Store index in '.cache/clangd/index' instead of '.clangd/index'
Summary: .clangd/index was well-intentioned in 2754942, but `.clangd` is the best filename for the clangd config file (matching .clang-format and .clang-tidy). And of course we can't have both .clangd/index and .clangd... There are a few overlapping goals to satisfy: - it should be clear from the directory name that this is transient data that is safe to delete at the cost of recomputation, i.e. a cache - it should be easy and self-documenting to blacklist these files in .gitignore - we should have some consistency between filenames in-tree and corresponding files in user storage (e.g. under XDG's ~/.cache/) - we should be consistent across platforms (including windows, which doesn't have distinct cache vs config directories) So the plan is: $PROJECT/.clangd (project config) $PROJECT/.cache/clangd/index/ (project index) $PROJECT/.cache/clangd/modules/ (maybe in future) $XDG_CONFIG_HOME/clangd/config.yaml (user config) $XDG_CACHE_HOME/clangd/index/ (index of non-project files) $XDG_CACHE_HOME/clangd/modules/ (maybe in future) This is sensible if XDG_{CONFIG,CACHE}_HOME coincide, and has a simple .gitignore rule going forward: `.cache/`. The monorepo gitignore is updated to reflect the backwards-compatible practice: ignore .clangd/ (with trailing slash) matching index files from clangd 9/10 ignore .cache matching index from clangd 11+, and potentially other tools. The entries from llvm-project/llvm gitignore are removed (obsolete). Reviewers: kadircet, hokein Subscribers: ilya-biryukov, MaskRay, jkorous, omtcyfz, arphaman, usaxena95, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D83099
1 parent cca4ac5 commit 9b55bc4

File tree

5 files changed

+12
-13
lines changed

5 files changed

+12
-13
lines changed

.gitignore

+4-3
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@ autoconf/autom4te.cache
5353
# VS2017 and VSCode config files.
5454
.vscode
5555
.vs
56-
# clangd index
57-
.clangd
56+
# clangd index. (".clangd" is a config file now, thus trailing slash)
57+
.clangd/
58+
.cache
5859
# static analyzer regression testing project files
5960
/clang/utils/analyzer/projects/*/CachedSource
6061
/clang/utils/analyzer/projects/*/PatchedSource
6162
/clang/utils/analyzer/projects/*/ScanBuildResults
62-
/clang/utils/analyzer/projects/*/RefScanBuildResults
63+
/clang/utils/analyzer/projects/*/RefScanBuildResults

clang-tools-extra/clangd/index/Background.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ class BackgroundIndexStorage {
5656
using Factory = llvm::unique_function<BackgroundIndexStorage *(PathRef)>;
5757

5858
// Creates an Index Storage that saves shards into disk. Index storage uses
59-
// CDBDirectory + ".clangd/index/" as the folder to save shards. CDBDirectory
60-
// is the first directory containing a CDB in parent directories of a file, or
61-
// user's home directory if none was found, e.g. standard library headers.
59+
// CDBDirectory + ".cache/clangd/index/" as the folder to save shards.
60+
// CDBDirectory is the first directory containing a CDB in parent directories
61+
// of a file, or user cache directory if none was found, e.g. stdlib headers.
6262
static Factory createDiskBackedStorageFactory(
6363
std::function<llvm::Optional<ProjectInfo>(PathRef)> GetProjectInfo);
6464
};

clang-tools-extra/clangd/index/BackgroundIndexStorage.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ class NullStorage : public BackgroundIndexStorage {
9595
};
9696

9797
// Creates and owns IndexStorages for multiple CDBs.
98-
// When a CDB root is found, shards are stored in $ROOT/.clangd/index.
99-
// When no root is found, the fallback path is ~/.cache/clangd/index.
98+
// When a CDB root is found, shards are stored in $ROOT/.cache/clangd/index/.
99+
// When no root is found, the fallback path is ~/.cache/clangd/index/.
100100
class DiskBackedIndexStorageManager {
101101
public:
102102
DiskBackedIndexStorageManager(
@@ -115,7 +115,7 @@ class DiskBackedIndexStorageManager {
115115
llvm::SmallString<128> StorageDir(FallbackDir);
116116
if (auto PI = GetProjectInfo(File)) {
117117
StorageDir = PI->SourceRoot;
118-
llvm::sys::path::append(StorageDir, ".clangd", "index");
118+
llvm::sys::path::append(StorageDir, ".cache", "clangd", "index");
119119
}
120120
auto &IndexStorage = IndexStorageMap[StorageDir];
121121
if (!IndexStorage)

clang-tools-extra/clangd/test/background-index.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
# RUN: clangd -background-index -lit-test < %t/definition.jsonrpc | FileCheck %t/definition.jsonrpc --check-prefixes=CHECK,BUILD
1616

1717
# Test that the index is writing files in the expected location.
18-
# RUN: ls %t/.clangd/index/foo.cpp.*.idx
19-
# RUN: ls %t/sub_dir/.clangd/index/foo.h.*.idx
18+
# RUN: ls %t/.cache/clangd/index/foo.cpp.*.idx
19+
# RUN: ls %t/sub_dir/.cache/clangd/index/foo.h.*.idx
2020

2121
# Test the index is read from disk: delete code and restart clangd.
2222
# RUN: rm %t/foo.cpp

llvm/.gitignore

-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ docs/_build
5959
# VS2017 and VSCode config files.
6060
.vscode
6161
.vs
62-
# clangd index
63-
.clangd
6462

6563
#==============================================================================#
6664
# Files created in tree by the Go bindings.

0 commit comments

Comments
 (0)