116 releases

0.0.149 Jan 16, 2023
0.0.145 Dec 26, 2022
0.0.141 Nov 28, 2022
0.0.122 Jul 25, 2022
0.0.26 Nov 30, 2020

#134 in Filesystem

Download history 1447/week @ 2022-10-12 1332/week @ 2022-10-19 1414/week @ 2022-10-26 1244/week @ 2022-11-02 1595/week @ 2022-11-09 1521/week @ 2022-11-16 1055/week @ 2022-11-23 1251/week @ 2022-11-30 1475/week @ 2022-12-07 1168/week @ 2022-12-14 1997/week @ 2022-12-21 1523/week @ 2022-12-28 1506/week @ 2023-01-04 1343/week @ 2023-01-11 1313/week @ 2023-01-18 1711/week @ 2023-01-25

6,216 downloads per month
Used in 24 crates (5 directly)


782 lines

Virtual File System

VFS stores all files read by rust-analyzer. Reading file contents from VFS always returns the same contents, unless VFS was explicitly modified with set_file_contents. All changes to VFS are logged, and can be retrieved via take_changes method. The pack of changes is then pushed to salsa and triggers incremental recomputation.

Files in VFS are identified with [FileId]s -- interned paths. The notion of the path, [VfsPath] is somewhat abstract: at the moment, it is represented as an [std::path::PathBuf] internally, but this is an implementation detail.

VFS doesn't do IO or file watching itself. For that, see the [loader] module. [loader::Handle] is an object-safe trait which abstracts both file loading and file watching. Handle is dynamically configured with a set of directory entries which should be scanned and watched. Handle then asynchronously pushes file changes. Directory entries are configured in free-form via list of globs, it's up to the Handle to interpret the globs in any specific way.

VFS stores a flat list of files. [file_set::FileSet] can partition this list of files into disjoint sets of files. Traversal-like operations (including getting the neighbor file by the relative path) are handled by the FileSet. FileSets are also pushed to salsa and cause it to re-check mod foo; declarations when files are created or deleted.

FileSet and [loader::Entry] play similar, but different roles. Both specify the "set of paths/files", one is geared towards file watching, the other towards salsa changes. In particular, single FileSet may correspond to several [loader::Entry]. For example, a crate from crates.io which uses code generation would have two Entries -- for sources in ~/.cargo, and for generated code in ./target/debug/build. It will have a single FileSet which unions the two sources.


~72K SLoC