diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-10 11:42:42 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-10 11:42:42 +0000 |
commit | 8e4be2708635818aa3e210f0e39fb871cc433004 (patch) | |
tree | 569110cbb504c0516b136c414610b0f2edbe5044 /crates/ra_vfs | |
parent | 01b15c9fc2ce128149872ffe02de022bdb157286 (diff) | |
parent | 2e9194a621ccb33872d6189ecc30a83c17e6e33a (diff) |
Merge #774
774: Batch crate & command r=matklad a=flodiebold
This adds a new crate, `ra_batch`, which is intended for scenarios where you're loading a workspace once and then running some analyses using the HIR API. Also, it adds a command to `ra_cli` which uses that to type-check all crates in a workspace and print some statistics:
E.g. in rust-analyzer:
```
> $ time target/release/ra_cli analysis-stats
Database loaded, 21 roots
Crates in this dir: 28
Total modules found: 231
Total declarations: 3694
Total functions: 2408
Total expressions: 47017
Expressions of unknown type: 19826 (42%)
Expressions of partially unknown type: 4482 (9%)
target/release/ra_cli analysis-stats 3,23s user 0,60s system 100% cpu 3,821 total
```
Or in rust-lang/rust:
```
> $ time ../opensource/rust-analyzer/target/release/ra_cli analysis-stats
Database loaded, 77 roots
Crates in this dir: 130
Total modules found: 1820
Total declarations: 35038
Total functions: 25914
Total expressions: 753678
Expressions of unknown type: 337975 (44%)
Expressions of partially unknown type: 92314 (12%)
../opensource/rust-analyzer/target/release/ra_cli analysis-stats 13,45s user 2,08s system 100% cpu 15,477 total
```
~This still needs a test. Type-checking all of rust-analyzer sadly takes almost a minute when compiled in debug mode :sweat_smile: So I'll need to add something simpler (maybe just looking at a few modules).~
Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_vfs')
-rw-r--r-- | crates/ra_vfs/src/lib.rs | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/crates/ra_vfs/src/lib.rs b/crates/ra_vfs/src/lib.rs index 6b4eb6842..3805be570 100644 --- a/crates/ra_vfs/src/lib.rs +++ b/crates/ra_vfs/src/lib.rs | |||
@@ -94,6 +94,7 @@ impl Roots { | |||
94 | let mut roots = Arena::default(); | 94 | let mut roots = Arena::default(); |
95 | // A hack to make nesting work. | 95 | // A hack to make nesting work. |
96 | paths.sort_by_key(|it| Reverse(it.as_os_str().len())); | 96 | paths.sort_by_key(|it| Reverse(it.as_os_str().len())); |
97 | paths.dedup(); | ||
97 | for (i, path) in paths.iter().enumerate() { | 98 | for (i, path) in paths.iter().enumerate() { |
98 | let nested_roots = paths[..i] | 99 | let nested_roots = paths[..i] |
99 | .iter() | 100 | .iter() |
@@ -181,6 +182,10 @@ impl Vfs { | |||
181 | None | 182 | None |
182 | } | 183 | } |
183 | 184 | ||
185 | pub fn num_roots(&self) -> usize { | ||
186 | self.roots.len() | ||
187 | } | ||
188 | |||
184 | pub fn load(&mut self, path: &Path) -> Option<VfsFile> { | 189 | pub fn load(&mut self, path: &Path) -> Option<VfsFile> { |
185 | if let Some((root, rel_path, file)) = self.find_root(path) { | 190 | if let Some((root, rel_path, file)) = self.find_root(path) { |
186 | return if let Some(file) = file { | 191 | return if let Some(file) = file { |