//===--- FileIndex.h - Index for files. ---------------------------- C++-*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // FileIndex implements SymbolIndex for symbols from a set of files. Symbols are // maintained at source-file granularity (e.g. with ASTs), and files can be // updated dynamically. // //===----------------------------------------------------------------------===// #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_FILEINDEX_H #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_FILEINDEX_H #include "Headers.h" #include "clang-include-cleaner/Record.h" #include "index/Index.h" #include "index/Merge.h" #include "index/Ref.h" #include "index/Relation.h" #include "index/Serialization.h" #include "index/Symbol.h" #include "support/MemoryTree.h" #include "support/Path.h" #include "clang/Lex/Preprocessor.h" #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" #include <memory> #include <optional> #include <vector> namespace clang { class ASTContext; namespace clangd { class ParsedAST; /// Select between in-memory index implementations, which have tradeoffs. enum class IndexType { … }; /// How to handle duplicated symbols across multiple files. enum class DuplicateHandling { … }; /// A container of slabs associated with a key. It can be updated at key /// granularity, replacing all slabs belonging to a key with a new set. Keys are /// usually file paths/uris. /// /// This implements snapshot semantics. Each update will create a new snapshot /// for all slabs of the Key. Snapshots are managed with shared pointers that /// are shared between this class and the users. For each key, this class only /// stores a pointer pointing to the newest snapshot, and an outdated snapshot /// is deleted by the last owner of the snapshot, either this class or the /// symbol index. /// /// The snapshot semantics keeps critical sections minimal since we only need /// locking when we swap or obtain references to snapshots. class FileSymbols { … }; /// This manages symbols from files and an in-memory index on all symbols. /// FIXME: Expose an interface to remove files that are closed. class FileIndex : public MergedIndex { … }; SlabTuple; /// Retrieves symbols and refs of local top level decls in \p AST (i.e. /// `AST.getLocalTopLevelDecls()`). /// Exposed to assist in unit tests. SlabTuple indexMainDecls(ParsedAST &AST); /// Index declarations from \p AST and macros from \p PP that are declared in /// included headers. SlabTuple indexHeaderSymbols(llvm::StringRef Version, ASTContext &AST, Preprocessor &PP, const include_cleaner::PragmaIncludes &PI); /// Takes slabs coming from a TU (multiple files) and shards them per /// declaration location. struct FileShardedIndex { … }; } // namespace clangd } // namespace clang #endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_FILEINDEX_H