diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-12-09 16:07:33 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-12-09 16:07:33 +0000 |
commit | 99118eeccdf6564876bbe6ec0672b04ffcbe3442 (patch) | |
tree | 08f0fd7d99ad22a3d1db782482b66548e99ba8b2 /crates/vfs/src/anchored_path.rs | |
parent | 42be522c80cf0cc2d49b60f3c1d66afdc51fcbbb (diff) | |
parent | 6e24321e4579d25686982002ed18f321db23cb9f (diff) |
Merge #6784
6784: Introduce anchored_path r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/vfs/src/anchored_path.rs')
-rw-r--r-- | crates/vfs/src/anchored_path.rs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/crates/vfs/src/anchored_path.rs b/crates/vfs/src/anchored_path.rs new file mode 100644 index 000000000..02720a32e --- /dev/null +++ b/crates/vfs/src/anchored_path.rs | |||
@@ -0,0 +1,39 @@ | |||
1 | //! Analysis-level representation of file-system paths. | ||
2 | //! | ||
3 | //! The primary goal of this is to losslessly represent paths like | ||
4 | //! | ||
5 | //! ``` | ||
6 | //! #[path = "./bar.rs"] | ||
7 | //! mod foo; | ||
8 | //! ``` | ||
9 | //! | ||
10 | //! The first approach one might reach for is to use `PathBuf`. The problem here | ||
11 | //! is that `PathBuf` depends on host target (windows or linux), but | ||
12 | //! rust-analyzer should be capable to process `#[path = r"C:\bar.rs"]` on Unix. | ||
13 | //! | ||
14 | //! The second try is to use a `String`. This also fails, however. Consider a | ||
15 | //! hypothetical scenario, where rust-analyzer operates in a | ||
16 | //! networked/distributed mode. There's one global instance of rust-analyzer, | ||
17 | //! which processes requests from different machines. Now, the semantics of | ||
18 | //! `#[path = "/abs/path.rs"]` actually depends on which file-system we are at! | ||
19 | //! That is, even absolute paths exist relative to a file system! | ||
20 | //! | ||
21 | //! A more realistic scenario here is virtual VFS paths we use for testing. More | ||
22 | //! generally, there can be separate "universes" of VFS paths. | ||
23 | //! | ||
24 | //! That's why we use anchored representation -- each path carries an info about | ||
25 | //! a file this path originates from. We can fetch fs/"universe" information | ||
26 | //! from the anchor than. | ||
27 | use crate::FileId; | ||
28 | |||
29 | #[derive(Clone, PartialEq, Eq, Debug)] | ||
30 | pub struct AnchoredPathBuf { | ||
31 | pub anchor: FileId, | ||
32 | pub path: String, | ||
33 | } | ||
34 | |||
35 | #[derive(Clone, Copy, PartialEq, Eq, Debug)] | ||
36 | pub struct AnchoredPath<'a> { | ||
37 | pub anchor: FileId, | ||
38 | pub path: &'a str, | ||
39 | } | ||