diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_batch/Cargo.toml | 20 | ||||
-rw-r--r-- | crates/ra_cli/Cargo.toml | 15 | ||||
-rw-r--r-- | crates/ra_cli/src/analysis_bench.rs | 4 | ||||
-rw-r--r-- | crates/ra_cli/src/analysis_stats.rs | 9 | ||||
-rw-r--r-- | crates/ra_cli/src/help.rs | 75 | ||||
-rw-r--r-- | crates/ra_cli/src/load_cargo.rs (renamed from crates/ra_batch/src/lib.rs) | 3 | ||||
-rw-r--r-- | crates/ra_cli/src/main.rs | 116 |
7 files changed, 117 insertions, 125 deletions
diff --git a/crates/ra_batch/Cargo.toml b/crates/ra_batch/Cargo.toml deleted file mode 100644 index 3bf351fe3..000000000 --- a/crates/ra_batch/Cargo.toml +++ /dev/null | |||
@@ -1,20 +0,0 @@ | |||
1 | [package] | ||
2 | edition = "2018" | ||
3 | name = "ra_batch" | ||
4 | version = "0.1.0" | ||
5 | authors = ["rust-analyzer developers"] | ||
6 | |||
7 | [lib] | ||
8 | doctest = false | ||
9 | |||
10 | [dependencies] | ||
11 | log = "0.4.5" | ||
12 | rustc-hash = "1.0" | ||
13 | crossbeam-channel = "0.4.0" | ||
14 | |||
15 | ra_vfs = "0.5.0" | ||
16 | ra_vfs_glob = { path = "../ra_vfs_glob" } | ||
17 | ra_db = { path = "../ra_db" } | ||
18 | ra_ide = { path = "../ra_ide" } | ||
19 | ra_hir = { path = "../ra_hir" } | ||
20 | ra_project_model = { path = "../ra_project_model" } | ||
diff --git a/crates/ra_cli/Cargo.toml b/crates/ra_cli/Cargo.toml index 53d4876f6..03494a809 100644 --- a/crates/ra_cli/Cargo.toml +++ b/crates/ra_cli/Cargo.toml | |||
@@ -6,18 +6,23 @@ authors = ["rust-analyzer developers"] | |||
6 | publish = false | 6 | publish = false |
7 | 7 | ||
8 | [dependencies] | 8 | [dependencies] |
9 | crossbeam-channel = "0.4.0" | ||
10 | env_logger = { version = "0.7.1", default-features = false } | ||
9 | itertools = "0.8.0" | 11 | itertools = "0.8.0" |
12 | log = "0.4.5" | ||
10 | pico-args = "0.3.0" | 13 | pico-args = "0.3.0" |
11 | env_logger = { version = "0.7.1", default-features = false } | ||
12 | rand = { version = "0.7.0", features = ["small_rng"] } | 14 | rand = { version = "0.7.0", features = ["small_rng"] } |
15 | rustc-hash = "1.0" | ||
13 | 16 | ||
14 | ra_syntax = { path = "../ra_syntax" } | ||
15 | ra_ide = { path = "../ra_ide" } | ||
16 | ra_batch = { path = "../ra_batch" } | ||
17 | hir = { path = "../ra_hir", package = "ra_hir" } | 17 | hir = { path = "../ra_hir", package = "ra_hir" } |
18 | hir_ty = { path = "../ra_hir_ty", package = "ra_hir_ty" } | ||
19 | hir_def = { path = "../ra_hir_def", package = "ra_hir_def" } | 18 | hir_def = { path = "../ra_hir_def", package = "ra_hir_def" } |
19 | hir_ty = { path = "../ra_hir_ty", package = "ra_hir_ty" } | ||
20 | ra_db = { path = "../ra_db" } | 20 | ra_db = { path = "../ra_db" } |
21 | ra_ide = { path = "../ra_ide" } | ||
22 | ra_project_model = { path = "../ra_project_model" } | ||
23 | ra_syntax = { path = "../ra_syntax" } | ||
24 | ra_vfs = "0.5.0" | ||
25 | ra_vfs_glob = { path = "../ra_vfs_glob" } | ||
21 | 26 | ||
22 | [dependencies.ra_prof] | 27 | [dependencies.ra_prof] |
23 | path = "../ra_prof" | 28 | path = "../ra_prof" |
diff --git a/crates/ra_cli/src/analysis_bench.rs b/crates/ra_cli/src/analysis_bench.rs index 4835a68ce..3f10ed400 100644 --- a/crates/ra_cli/src/analysis_bench.rs +++ b/crates/ra_cli/src/analysis_bench.rs | |||
@@ -13,7 +13,7 @@ use ra_db::{ | |||
13 | }; | 13 | }; |
14 | use ra_ide::{Analysis, AnalysisChange, AnalysisHost, FilePosition, LineCol}; | 14 | use ra_ide::{Analysis, AnalysisChange, AnalysisHost, FilePosition, LineCol}; |
15 | 15 | ||
16 | use crate::Result; | 16 | use crate::{load_cargo::load_cargo, Result}; |
17 | 17 | ||
18 | pub(crate) struct Position { | 18 | pub(crate) struct Position { |
19 | path: PathBuf, | 19 | path: PathBuf, |
@@ -46,7 +46,7 @@ pub(crate) fn run(verbose: bool, path: &Path, op: Op) -> Result<()> { | |||
46 | 46 | ||
47 | let start = Instant::now(); | 47 | let start = Instant::now(); |
48 | eprint!("loading: "); | 48 | eprint!("loading: "); |
49 | let (mut host, roots) = ra_batch::load_cargo(path)?; | 49 | let (mut host, roots) = load_cargo(path)?; |
50 | let db = host.raw_database(); | 50 | let db = host.raw_database(); |
51 | eprintln!("{:?}\n", start.elapsed()); | 51 | eprintln!("{:?}\n", start.elapsed()); |
52 | 52 | ||
diff --git a/crates/ra_cli/src/analysis_stats.rs b/crates/ra_cli/src/analysis_stats.rs index 6d2dd34c6..d40f04391 100644 --- a/crates/ra_cli/src/analysis_stats.rs +++ b/crates/ra_cli/src/analysis_stats.rs | |||
@@ -2,19 +2,18 @@ | |||
2 | 2 | ||
3 | use std::{collections::HashSet, fmt::Write, path::Path, time::Instant}; | 3 | use std::{collections::HashSet, fmt::Write, path::Path, time::Instant}; |
4 | 4 | ||
5 | use itertools::Itertools; | ||
6 | use rand::{seq::SliceRandom, thread_rng}; | ||
7 | |||
8 | use hir::{ | 5 | use hir::{ |
9 | db::{DefDatabase, HirDatabase}, | 6 | db::{DefDatabase, HirDatabase}, |
10 | AssocItem, Crate, HasSource, HirDisplay, ModuleDef, | 7 | AssocItem, Crate, HasSource, HirDisplay, ModuleDef, |
11 | }; | 8 | }; |
12 | use hir_def::FunctionId; | 9 | use hir_def::FunctionId; |
13 | use hir_ty::{Ty, TypeWalk}; | 10 | use hir_ty::{Ty, TypeWalk}; |
11 | use itertools::Itertools; | ||
14 | use ra_db::SourceDatabaseExt; | 12 | use ra_db::SourceDatabaseExt; |
15 | use ra_syntax::AstNode; | 13 | use ra_syntax::AstNode; |
14 | use rand::{seq::SliceRandom, thread_rng}; | ||
16 | 15 | ||
17 | use crate::{progress_report::ProgressReport, Result, Verbosity}; | 16 | use crate::{load_cargo::load_cargo, progress_report::ProgressReport, Result, Verbosity}; |
18 | 17 | ||
19 | pub fn run( | 18 | pub fn run( |
20 | verbosity: Verbosity, | 19 | verbosity: Verbosity, |
@@ -25,7 +24,7 @@ pub fn run( | |||
25 | randomize: bool, | 24 | randomize: bool, |
26 | ) -> Result<()> { | 25 | ) -> Result<()> { |
27 | let db_load_time = Instant::now(); | 26 | let db_load_time = Instant::now(); |
28 | let (mut host, roots) = ra_batch::load_cargo(path)?; | 27 | let (mut host, roots) = load_cargo(path)?; |
29 | let db = host.raw_database(); | 28 | let db = host.raw_database(); |
30 | println!("Database loaded, {} roots, {:?}", roots.len(), db_load_time.elapsed()); | 29 | println!("Database loaded, {} roots, {:?}", roots.len(), db_load_time.elapsed()); |
31 | let analysis_time = Instant::now(); | 30 | let analysis_time = Instant::now(); |
diff --git a/crates/ra_cli/src/help.rs b/crates/ra_cli/src/help.rs deleted file mode 100644 index d3c4c7d0b..000000000 --- a/crates/ra_cli/src/help.rs +++ /dev/null | |||
@@ -1,75 +0,0 @@ | |||
1 | //! FIXME: write short doc here | ||
2 | |||
3 | pub const GLOBAL_HELP: &str = "ra-cli | ||
4 | |||
5 | USAGE: | ||
6 | ra_cli <SUBCOMMAND> | ||
7 | |||
8 | FLAGS: | ||
9 | -h, --help Prints help information | ||
10 | |||
11 | SUBCOMMANDS: | ||
12 | analysis-bench | ||
13 | analysis-stats | ||
14 | highlight | ||
15 | parse | ||
16 | symbols"; | ||
17 | |||
18 | pub const ANALYSIS_BENCH_HELP: &str = "ra_cli-analysis-bench | ||
19 | |||
20 | USAGE: | ||
21 | ra_cli analysis-bench [FLAGS] [OPTIONS] [PATH] | ||
22 | |||
23 | FLAGS: | ||
24 | -h, --help Prints help information | ||
25 | -v, --verbose | ||
26 | |||
27 | OPTIONS: | ||
28 | --complete <PATH:LINE:COLUMN> Compute completions at this location | ||
29 | --highlight <PATH> Hightlight this file | ||
30 | |||
31 | ARGS: | ||
32 | <PATH> Project to analyse"; | ||
33 | |||
34 | pub const ANALYSIS_STATS_HELP: &str = "ra-cli-analysis-stats | ||
35 | |||
36 | USAGE: | ||
37 | ra_cli analysis-stats [FLAGS] [OPTIONS] [PATH] | ||
38 | |||
39 | FLAGS: | ||
40 | -h, --help Prints help information | ||
41 | --memory-usage | ||
42 | -v, --verbose | ||
43 | -q, --quiet | ||
44 | |||
45 | OPTIONS: | ||
46 | -o <ONLY> | ||
47 | |||
48 | ARGS: | ||
49 | <PATH>"; | ||
50 | |||
51 | pub const HIGHLIGHT_HELP: &str = "ra-cli-highlight | ||
52 | |||
53 | USAGE: | ||
54 | ra_cli highlight [FLAGS] | ||
55 | |||
56 | FLAGS: | ||
57 | -h, --help Prints help information | ||
58 | -r, --rainbow"; | ||
59 | |||
60 | pub const SYMBOLS_HELP: &str = "ra-cli-symbols | ||
61 | |||
62 | USAGE: | ||
63 | ra_cli highlight [FLAGS] | ||
64 | |||
65 | FLAGS: | ||
66 | -h, --help Prints help inforamtion"; | ||
67 | |||
68 | pub const PARSE_HELP: &str = "ra-cli-parse | ||
69 | |||
70 | USAGE: | ||
71 | ra_cli parse [FLAGS] | ||
72 | |||
73 | FLAGS: | ||
74 | -h, --help Prints help inforamtion | ||
75 | --no-dump"; | ||
diff --git a/crates/ra_batch/src/lib.rs b/crates/ra_cli/src/load_cargo.rs index 7744ba85a..2d6433f18 100644 --- a/crates/ra_batch/src/lib.rs +++ b/crates/ra_cli/src/load_cargo.rs | |||
@@ -139,7 +139,8 @@ pub fn load( | |||
139 | #[cfg(test)] | 139 | #[cfg(test)] |
140 | mod tests { | 140 | mod tests { |
141 | use super::*; | 141 | use super::*; |
142 | use ra_hir::Crate; | 142 | |
143 | use hir::Crate; | ||
143 | 144 | ||
144 | #[test] | 145 | #[test] |
145 | fn test_loading_rust_analyzer() { | 146 | fn test_loading_rust_analyzer() { |
diff --git a/crates/ra_cli/src/main.rs b/crates/ra_cli/src/main.rs index 750cbab86..4a428faff 100644 --- a/crates/ra_cli/src/main.rs +++ b/crates/ra_cli/src/main.rs | |||
@@ -1,8 +1,8 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | mod load_cargo; | ||
3 | mod analysis_stats; | 4 | mod analysis_stats; |
4 | mod analysis_bench; | 5 | mod analysis_bench; |
5 | mod help; | ||
6 | mod progress_report; | 6 | mod progress_report; |
7 | 7 | ||
8 | use std::{error::Error, fmt::Write, io::Read}; | 8 | use std::{error::Error, fmt::Write, io::Read}; |
@@ -40,21 +40,26 @@ impl Verbosity { | |||
40 | fn main() -> Result<()> { | 40 | fn main() -> Result<()> { |
41 | env_logger::try_init()?; | 41 | env_logger::try_init()?; |
42 | 42 | ||
43 | let subcommand = match std::env::args_os().nth(1) { | 43 | let mut matches = Arguments::from_env(); |
44 | None => { | 44 | let subcommand = matches.subcommand()?.unwrap_or_default(); |
45 | eprintln!("{}", help::GLOBAL_HELP); | ||
46 | return Ok(()); | ||
47 | } | ||
48 | Some(s) => s, | ||
49 | }; | ||
50 | let mut matches = Arguments::from_vec(std::env::args_os().skip(2).collect()); | ||
51 | 45 | ||
52 | match &*subcommand.to_string_lossy() { | 46 | match subcommand.as_str() { |
53 | "parse" => { | 47 | "parse" => { |
54 | if matches.contains(["-h", "--help"]) { | 48 | if matches.contains(["-h", "--help"]) { |
55 | eprintln!("{}", help::PARSE_HELP); | 49 | eprintln!( |
50 | "\ | ||
51 | ra-cli-parse | ||
52 | |||
53 | USAGE: | ||
54 | ra_cli parse [FLAGS] | ||
55 | |||
56 | FLAGS: | ||
57 | -h, --help Prints help inforamtion | ||
58 | --no-dump" | ||
59 | ); | ||
56 | return Ok(()); | 60 | return Ok(()); |
57 | } | 61 | } |
62 | |||
58 | let no_dump = matches.contains("--no-dump"); | 63 | let no_dump = matches.contains("--no-dump"); |
59 | matches.finish().or_else(handle_extra_flags)?; | 64 | matches.finish().or_else(handle_extra_flags)?; |
60 | 65 | ||
@@ -67,10 +72,21 @@ fn main() -> Result<()> { | |||
67 | } | 72 | } |
68 | "symbols" => { | 73 | "symbols" => { |
69 | if matches.contains(["-h", "--help"]) { | 74 | if matches.contains(["-h", "--help"]) { |
70 | eprintln!("{}", help::SYMBOLS_HELP); | 75 | eprintln!( |
76 | "\ | ||
77 | ra-cli-symbols | ||
78 | |||
79 | USAGE: | ||
80 | ra_cli highlight [FLAGS] | ||
81 | |||
82 | FLAGS: | ||
83 | -h, --help Prints help inforamtion" | ||
84 | ); | ||
71 | return Ok(()); | 85 | return Ok(()); |
72 | } | 86 | } |
87 | |||
73 | matches.finish().or_else(handle_extra_flags)?; | 88 | matches.finish().or_else(handle_extra_flags)?; |
89 | |||
74 | let file = file()?; | 90 | let file = file()?; |
75 | for s in file_structure(&file) { | 91 | for s in file_structure(&file) { |
76 | println!("{:?}", s); | 92 | println!("{:?}", s); |
@@ -78,20 +94,51 @@ fn main() -> Result<()> { | |||
78 | } | 94 | } |
79 | "highlight" => { | 95 | "highlight" => { |
80 | if matches.contains(["-h", "--help"]) { | 96 | if matches.contains(["-h", "--help"]) { |
81 | eprintln!("{}", help::HIGHLIGHT_HELP); | 97 | eprintln!( |
98 | "\ | ||
99 | ra-cli-highlight | ||
100 | |||
101 | USAGE: | ||
102 | ra_cli highlight [FLAGS] | ||
103 | |||
104 | FLAGS: | ||
105 | -h, --help Prints help information | ||
106 | -r, --rainbow" | ||
107 | ); | ||
82 | return Ok(()); | 108 | return Ok(()); |
83 | } | 109 | } |
110 | |||
84 | let rainbow_opt = matches.contains(["-r", "--rainbow"]); | 111 | let rainbow_opt = matches.contains(["-r", "--rainbow"]); |
85 | matches.finish().or_else(handle_extra_flags)?; | 112 | matches.finish().or_else(handle_extra_flags)?; |
113 | |||
86 | let (analysis, file_id) = Analysis::from_single_file(read_stdin()?); | 114 | let (analysis, file_id) = Analysis::from_single_file(read_stdin()?); |
87 | let html = analysis.highlight_as_html(file_id, rainbow_opt).unwrap(); | 115 | let html = analysis.highlight_as_html(file_id, rainbow_opt).unwrap(); |
88 | println!("{}", html); | 116 | println!("{}", html); |
89 | } | 117 | } |
90 | "analysis-stats" => { | 118 | "analysis-stats" => { |
91 | if matches.contains(["-h", "--help"]) { | 119 | if matches.contains(["-h", "--help"]) { |
92 | eprintln!("{}", help::ANALYSIS_STATS_HELP); | 120 | eprintln!( |
121 | "\ | ||
122 | ra-cli-analysis-stats | ||
123 | |||
124 | USAGE: | ||
125 | ra_cli analysis-stats [FLAGS] [OPTIONS] [PATH] | ||
126 | |||
127 | FLAGS: | ||
128 | -h, --help Prints help information | ||
129 | --memory-usage | ||
130 | -v, --verbose | ||
131 | -q, --quiet | ||
132 | |||
133 | OPTIONS: | ||
134 | -o <ONLY> | ||
135 | |||
136 | ARGS: | ||
137 | <PATH>" | ||
138 | ); | ||
93 | return Ok(()); | 139 | return Ok(()); |
94 | } | 140 | } |
141 | |||
95 | let verbosity = match ( | 142 | let verbosity = match ( |
96 | matches.contains(["-vv", "--spammy"]), | 143 | matches.contains(["-vv", "--spammy"]), |
97 | matches.contains(["-v", "--verbose"]), | 144 | matches.contains(["-v", "--verbose"]), |
@@ -111,11 +158,11 @@ fn main() -> Result<()> { | |||
111 | let path = { | 158 | let path = { |
112 | let mut trailing = matches.free()?; | 159 | let mut trailing = matches.free()?; |
113 | if trailing.len() != 1 { | 160 | if trailing.len() != 1 { |
114 | eprintln!("{}", help::ANALYSIS_STATS_HELP); | ||
115 | Err("Invalid flags")?; | 161 | Err("Invalid flags")?; |
116 | } | 162 | } |
117 | trailing.pop().unwrap() | 163 | trailing.pop().unwrap() |
118 | }; | 164 | }; |
165 | |||
119 | analysis_stats::run( | 166 | analysis_stats::run( |
120 | verbosity, | 167 | verbosity, |
121 | memory_usage, | 168 | memory_usage, |
@@ -127,9 +174,27 @@ fn main() -> Result<()> { | |||
127 | } | 174 | } |
128 | "analysis-bench" => { | 175 | "analysis-bench" => { |
129 | if matches.contains(["-h", "--help"]) { | 176 | if matches.contains(["-h", "--help"]) { |
130 | eprintln!("{}", help::ANALYSIS_BENCH_HELP); | 177 | eprintln!( |
178 | "\ | ||
179 | ra_cli-analysis-bench | ||
180 | |||
181 | USAGE: | ||
182 | ra_cli analysis-bench [FLAGS] [OPTIONS] [PATH] | ||
183 | |||
184 | FLAGS: | ||
185 | -h, --help Prints help information | ||
186 | -v, --verbose | ||
187 | |||
188 | OPTIONS: | ||
189 | --complete <PATH:LINE:COLUMN> Compute completions at this location | ||
190 | --highlight <PATH> Hightlight this file | ||
191 | |||
192 | ARGS: | ||
193 | <PATH> Project to analyse" | ||
194 | ); | ||
131 | return Ok(()); | 195 | return Ok(()); |
132 | } | 196 | } |
197 | |||
133 | let verbose = matches.contains(["-v", "--verbose"]); | 198 | let verbose = matches.contains(["-v", "--verbose"]); |
134 | let path: String = matches.opt_value_from_str("--path")?.unwrap_or_default(); | 199 | let path: String = matches.opt_value_from_str("--path")?.unwrap_or_default(); |
135 | let highlight_path: Option<String> = matches.opt_value_from_str("--highlight")?; | 200 | let highlight_path: Option<String> = matches.opt_value_from_str("--highlight")?; |
@@ -144,9 +209,26 @@ fn main() -> Result<()> { | |||
144 | ), | 209 | ), |
145 | }; | 210 | }; |
146 | matches.finish().or_else(handle_extra_flags)?; | 211 | matches.finish().or_else(handle_extra_flags)?; |
212 | |||
147 | analysis_bench::run(verbose, path.as_ref(), op)?; | 213 | analysis_bench::run(verbose, path.as_ref(), op)?; |
148 | } | 214 | } |
149 | _ => eprintln!("{}", help::GLOBAL_HELP), | 215 | _ => eprintln!( |
216 | "\ | ||
217 | ra-cli | ||
218 | |||
219 | USAGE: | ||
220 | ra_cli <SUBCOMMAND> | ||
221 | |||
222 | FLAGS: | ||
223 | -h, --help Prints help information | ||
224 | |||
225 | SUBCOMMANDS: | ||
226 | analysis-bench | ||
227 | analysis-stats | ||
228 | highlight | ||
229 | parse | ||
230 | symbols" | ||
231 | ), | ||
150 | } | 232 | } |
151 | Ok(()) | 233 | Ok(()) |
152 | } | 234 | } |