#How indexing works The server has a root URI for the workspace. Every source file under the workspace is indexed, depending on the extension (.cpp, .c, etc). When a file is indexed, #include directives are tracked in order to build a dependency graph between the files. An "indexer action" handles every occurrence of symbols in a source file and stores function definitions. ##How data is stored Each file is represented by a ClangdIndexFile. Files are inserted in a BTree for fast lookup, by file name. Each symbol definition is a ClangdIndexSymbol. Symbols are inserted in another BTree for fast lookup, by USR (Unified Symbol Resolution). Only functions are stored at the moment. Each file "owns" the symbols that are defined within itself. ClangdIndexFile has a linked list of ClangdIndexSymbols. ClangdIndexHeaderInclusion stores the inclusion relationships between files (ClangdIndexFile). When a file is deleted or modified, its symbols are deleted along with the file. Then it is recreated if necessary. Data is allocated and stored on disk via ClangdIndexDataStorage, a utility that provides a malloc-like interface for writing data to a file. ## What works - Basic dependency tracking - An index of function definition and their location - Reacting to some file events. File addition should be OK. Modification and deletion to some extent. - A command to reindex (for testing purposes?) - A command to dump header inclusions (for testing purposes). Could be the basis for "Include browser" functionality. - A command to dump "included by" files (for testing purposes). Could be the basis for "Include browser" functionality. - The data storage code (ClangdIndexDataStorage and BTree) are commented and pretty tested. ## What doesn't work/Left to do A lot! - Cycles in includes are not handled at all. - Re-indexing dependent files is not triggered yet. - Modifying files invalidates some dependencies ("included-by" relationships). - Multiple definition for the same USRs is not supported. - Tracking file time stamps and content hash (to index changed files on restart, etc). - Some task/scheduling system for indexing multiple files at the same time. - The model code (ClangdIndexFile, ClangdIndexSymbol, etc) is not very polished. - The header dependency tracking code is not polished. - The code for walking the tree and triggering the indexing is not very polished. - Tests for file events and the indexer reacting to them. - Many indexing related features are missing! - Possibly replace ClangdIndexDataStorage and BTree with libLMDB.