diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-02-17 19:14:32 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-02-17 19:14:32 +0000 |
commit | 1b73abd1c3c9185f4a1f62c5e657e07daf3d4774 (patch) | |
tree | 33542cd2b44bd5290f18baebee460b487008035a | |
parent | 64755b5e1f68290a2518b0bbc2f0007f95cd2632 (diff) | |
parent | 2c9b91ad326c387190bedab9dae9d08d3eb0705a (diff) |
Merge #3200
3200: Merge ra_vfs_glob and ra_lsp_server r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
16 files changed, 201 insertions, 230 deletions
diff --git a/Cargo.lock b/Cargo.lock index 82f910c1b..c22cbca3a 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -942,30 +942,6 @@ dependencies = [ | |||
942 | ] | 942 | ] |
943 | 943 | ||
944 | [[package]] | 944 | [[package]] |
945 | name = "ra_cli" | ||
946 | version = "0.1.0" | ||
947 | dependencies = [ | ||
948 | "anyhow", | ||
949 | "crossbeam-channel", | ||
950 | "env_logger", | ||
951 | "itertools", | ||
952 | "log", | ||
953 | "pico-args", | ||
954 | "ra_db", | ||
955 | "ra_hir", | ||
956 | "ra_hir_def", | ||
957 | "ra_hir_ty", | ||
958 | "ra_ide", | ||
959 | "ra_prof", | ||
960 | "ra_project_model", | ||
961 | "ra_syntax", | ||
962 | "ra_vfs", | ||
963 | "ra_vfs_glob", | ||
964 | "rand", | ||
965 | "rustc-hash", | ||
966 | ] | ||
967 | |||
968 | [[package]] | ||
969 | name = "ra_db" | 945 | name = "ra_db" |
970 | version = "0.1.0" | 946 | version = "0.1.0" |
971 | dependencies = [ | 947 | dependencies = [ |
@@ -1122,22 +1098,30 @@ dependencies = [ | |||
1122 | name = "ra_lsp_server" | 1098 | name = "ra_lsp_server" |
1123 | version = "0.1.0" | 1099 | version = "0.1.0" |
1124 | dependencies = [ | 1100 | dependencies = [ |
1101 | "anyhow", | ||
1125 | "crossbeam-channel", | 1102 | "crossbeam-channel", |
1126 | "either", | 1103 | "either", |
1127 | "env_logger", | 1104 | "env_logger", |
1105 | "globset", | ||
1106 | "itertools", | ||
1128 | "jod-thread", | 1107 | "jod-thread", |
1129 | "log", | 1108 | "log", |
1130 | "lsp-server", | 1109 | "lsp-server", |
1131 | "lsp-types", | 1110 | "lsp-types", |
1132 | "parking_lot", | 1111 | "parking_lot", |
1112 | "pico-args", | ||
1133 | "ra_cargo_watch", | 1113 | "ra_cargo_watch", |
1114 | "ra_db", | ||
1115 | "ra_hir", | ||
1116 | "ra_hir_def", | ||
1117 | "ra_hir_ty", | ||
1134 | "ra_ide", | 1118 | "ra_ide", |
1135 | "ra_prof", | 1119 | "ra_prof", |
1136 | "ra_project_model", | 1120 | "ra_project_model", |
1137 | "ra_syntax", | 1121 | "ra_syntax", |
1138 | "ra_text_edit", | 1122 | "ra_text_edit", |
1139 | "ra_vfs", | 1123 | "ra_vfs", |
1140 | "ra_vfs_glob", | 1124 | "rand", |
1141 | "relative-path", | 1125 | "relative-path", |
1142 | "rustc-hash", | 1126 | "rustc-hash", |
1143 | "serde", | 1127 | "serde", |
@@ -1244,14 +1228,6 @@ dependencies = [ | |||
1244 | ] | 1228 | ] |
1245 | 1229 | ||
1246 | [[package]] | 1230 | [[package]] |
1247 | name = "ra_vfs_glob" | ||
1248 | version = "0.1.0" | ||
1249 | dependencies = [ | ||
1250 | "globset", | ||
1251 | "ra_vfs", | ||
1252 | ] | ||
1253 | |||
1254 | [[package]] | ||
1255 | name = "rand" | 1231 | name = "rand" |
1256 | version = "0.7.3" | 1232 | version = "0.7.3" |
1257 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1233 | source = "registry+https://github.com/rust-lang/crates.io-index" |
diff --git a/crates/ra_cli/Cargo.toml b/crates/ra_cli/Cargo.toml deleted file mode 100644 index ce88a76b1..000000000 --- a/crates/ra_cli/Cargo.toml +++ /dev/null | |||
@@ -1,31 +0,0 @@ | |||
1 | [package] | ||
2 | edition = "2018" | ||
3 | name = "ra_cli" | ||
4 | version = "0.1.0" | ||
5 | authors = ["rust-analyzer developers"] | ||
6 | publish = false | ||
7 | |||
8 | [dependencies] | ||
9 | crossbeam-channel = "0.4.0" | ||
10 | env_logger = { version = "0.7.1", default-features = false } | ||
11 | itertools = "0.8.0" | ||
12 | log = "0.4.5" | ||
13 | pico-args = "0.3.0" | ||
14 | rand = { version = "0.7.0", features = ["small_rng"] } | ||
15 | rustc-hash = "1.0" | ||
16 | anyhow = "1.0" | ||
17 | |||
18 | hir = { path = "../ra_hir", package = "ra_hir" } | ||
19 | hir_def = { path = "../ra_hir_def", package = "ra_hir_def" } | ||
20 | hir_ty = { path = "../ra_hir_ty", package = "ra_hir_ty" } | ||
21 | ra_db = { path = "../ra_db" } | ||
22 | ra_ide = { path = "../ra_ide" } | ||
23 | ra_project_model = { path = "../ra_project_model" } | ||
24 | ra_syntax = { path = "../ra_syntax" } | ||
25 | ra_vfs = "0.5.0" | ||
26 | ra_vfs_glob = { path = "../ra_vfs_glob" } | ||
27 | |||
28 | [dependencies.ra_prof] | ||
29 | path = "../ra_prof" | ||
30 | # features = [ "cpu_profiler" ] | ||
31 | # features = [ "jemalloc" ] | ||
diff --git a/crates/ra_lsp_server/Cargo.toml b/crates/ra_lsp_server/Cargo.toml index 0066929c0..da523ba8a 100644 --- a/crates/ra_lsp_server/Cargo.toml +++ b/crates/ra_lsp_server/Cargo.toml | |||
@@ -8,13 +8,18 @@ authors = ["rust-analyzer developers"] | |||
8 | doctest = false | 8 | doctest = false |
9 | 9 | ||
10 | [dependencies] | 10 | [dependencies] |
11 | anyhow = "1.0" | ||
11 | crossbeam-channel = "0.4" | 12 | crossbeam-channel = "0.4" |
12 | either = "1.5" | 13 | either = "1.5" |
13 | env_logger = { version = "0.7.1", default-features = false } | 14 | env_logger = { version = "0.7.1", default-features = false } |
15 | globset = "0.4.4" | ||
16 | itertools = "0.8.0" | ||
14 | jod-thread = "0.1.0" | 17 | jod-thread = "0.1.0" |
15 | log = "0.4.3" | 18 | log = "0.4.3" |
16 | lsp-types = { version = "0.70.0", features = ["proposed"] } | 19 | lsp-types = { version = "0.70.0", features = ["proposed"] } |
17 | parking_lot = "0.10.0" | 20 | parking_lot = "0.10.0" |
21 | pico-args = "0.3.0" | ||
22 | rand = { version = "0.7.0", features = ["small_rng"] } | ||
18 | relative-path = "1.0.0" | 23 | relative-path = "1.0.0" |
19 | rustc-hash = "1.0" | 24 | rustc-hash = "1.0" |
20 | serde = { version = "1.0.83", features = ["derive"] } | 25 | serde = { version = "1.0.83", features = ["derive"] } |
@@ -29,7 +34,13 @@ ra_project_model = { path = "../ra_project_model" } | |||
29 | ra_syntax = { path = "../ra_syntax" } | 34 | ra_syntax = { path = "../ra_syntax" } |
30 | ra_text_edit = { path = "../ra_text_edit" } | 35 | ra_text_edit = { path = "../ra_text_edit" } |
31 | ra_vfs = "0.5.0" | 36 | ra_vfs = "0.5.0" |
32 | ra_vfs_glob = { path = "../ra_vfs_glob" } | 37 | |
38 | # This should only be used in CLI | ||
39 | ra_db = { path = "../ra_db" } | ||
40 | hir = { path = "../ra_hir", package = "ra_hir" } | ||
41 | hir_def = { path = "../ra_hir_def", package = "ra_hir_def" } | ||
42 | hir_ty = { path = "../ra_hir_ty", package = "ra_hir_ty" } | ||
43 | |||
33 | 44 | ||
34 | [target.'cfg(windows)'.dependencies] | 45 | [target.'cfg(windows)'.dependencies] |
35 | winapi = "0.3" | 46 | winapi = "0.3" |
diff --git a/crates/ra_cli/src/main.rs b/crates/ra_lsp_server/src/args.rs index 4cf062f47..89e2139ce 100644 --- a/crates/ra_cli/src/main.rs +++ b/crates/ra_lsp_server/src/args.rs | |||
@@ -1,65 +1,20 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! Command like parsing for rust-analyzer. |
2 | 2 | //! | |
3 | mod load_cargo; | 3 | //! If run started args, we run the LSP server loop. With a subcommand, we do a |
4 | mod analysis_stats; | 4 | //! one-time batch processing. |
5 | mod analysis_bench; | ||
6 | mod progress_report; | ||
7 | |||
8 | use std::{fmt::Write, io::Read, path::PathBuf, str::FromStr}; | ||
9 | 5 | ||
6 | use anyhow::{bail, Result}; | ||
10 | use pico_args::Arguments; | 7 | use pico_args::Arguments; |
11 | use ra_ide::{file_structure, Analysis}; | 8 | use ra_lsp_server::cli::{BenchWhat, Position, Verbosity}; |
12 | use ra_prof::profile; | ||
13 | use ra_syntax::{AstNode, SourceFile}; | ||
14 | |||
15 | use anyhow::{bail, format_err, Result}; | ||
16 | |||
17 | fn main() -> Result<()> { | ||
18 | env_logger::try_init()?; | ||
19 | |||
20 | let command = match Command::from_env_args()? { | ||
21 | Ok(it) => it, | ||
22 | Err(HelpPrinted) => return Ok(()), | ||
23 | }; | ||
24 | match command { | ||
25 | Command::Parse { no_dump } => { | ||
26 | let _p = profile("parsing"); | ||
27 | let file = file()?; | ||
28 | if !no_dump { | ||
29 | println!("{:#?}", file.syntax()); | ||
30 | } | ||
31 | std::mem::forget(file); | ||
32 | } | ||
33 | Command::Symbols => { | ||
34 | let file = file()?; | ||
35 | for s in file_structure(&file) { | ||
36 | println!("{:?}", s); | ||
37 | } | ||
38 | } | ||
39 | Command::Highlight { rainbow } => { | ||
40 | let (analysis, file_id) = Analysis::from_single_file(read_stdin()?); | ||
41 | let html = analysis.highlight_as_html(file_id, rainbow).unwrap(); | ||
42 | println!("{}", html); | ||
43 | } | ||
44 | Command::Stats { verbosity, randomize, memory_usage, only, with_deps, path } => { | ||
45 | analysis_stats::run( | ||
46 | verbosity, | ||
47 | memory_usage, | ||
48 | path.as_ref(), | ||
49 | only.as_ref().map(String::as_ref), | ||
50 | with_deps, | ||
51 | randomize, | ||
52 | )?; | ||
53 | } | ||
54 | Command::Bench { verbosity, path, what } => { | ||
55 | analysis_bench::run(verbosity, path.as_ref(), what)?; | ||
56 | } | ||
57 | } | ||
58 | 9 | ||
59 | Ok(()) | 10 | use std::{fmt::Write, path::PathBuf}; |
11 | |||
12 | pub(crate) struct Args { | ||
13 | pub(crate) verbosity: Verbosity, | ||
14 | pub(crate) command: Command, | ||
60 | } | 15 | } |
61 | 16 | ||
62 | enum Command { | 17 | pub(crate) enum Command { |
63 | Parse { | 18 | Parse { |
64 | no_dump: bool, | 19 | no_dump: bool, |
65 | }, | 20 | }, |
@@ -68,7 +23,6 @@ enum Command { | |||
68 | rainbow: bool, | 23 | rainbow: bool, |
69 | }, | 24 | }, |
70 | Stats { | 25 | Stats { |
71 | verbosity: Verbosity, | ||
72 | randomize: bool, | 26 | randomize: bool, |
73 | memory_usage: bool, | 27 | memory_usage: bool, |
74 | only: Option<String>, | 28 | only: Option<String>, |
@@ -76,67 +30,21 @@ enum Command { | |||
76 | path: PathBuf, | 30 | path: PathBuf, |
77 | }, | 31 | }, |
78 | Bench { | 32 | Bench { |
79 | verbosity: Verbosity, | ||
80 | path: PathBuf, | 33 | path: PathBuf, |
81 | what: BenchWhat, | 34 | what: BenchWhat, |
82 | }, | 35 | }, |
36 | RunServer, | ||
37 | Version, | ||
83 | } | 38 | } |
84 | 39 | ||
85 | #[derive(Clone, Copy)] | 40 | impl Args { |
86 | pub enum Verbosity { | 41 | pub(crate) fn parse() -> Result<Result<Args, HelpPrinted>> { |
87 | Spammy, | 42 | let mut matches = Arguments::from_env(); |
88 | Verbose, | ||
89 | Normal, | ||
90 | Quiet, | ||
91 | } | ||
92 | 43 | ||
93 | impl Verbosity { | 44 | if matches.contains("--version") { |
94 | fn is_verbose(self) -> bool { | 45 | matches.finish().or_else(handle_extra_flags)?; |
95 | match self { | 46 | return Ok(Ok(Args { verbosity: Verbosity::Normal, command: Command::Version })); |
96 | Verbosity::Verbose | Verbosity::Spammy => true, | ||
97 | _ => false, | ||
98 | } | ||
99 | } | ||
100 | fn is_spammy(self) -> bool { | ||
101 | match self { | ||
102 | Verbosity::Spammy => true, | ||
103 | _ => false, | ||
104 | } | 47 | } |
105 | } | ||
106 | } | ||
107 | |||
108 | enum BenchWhat { | ||
109 | Highlight { path: PathBuf }, | ||
110 | Complete(Position), | ||
111 | GotoDef(Position), | ||
112 | } | ||
113 | |||
114 | pub(crate) struct Position { | ||
115 | path: PathBuf, | ||
116 | line: u32, | ||
117 | column: u32, | ||
118 | } | ||
119 | |||
120 | impl FromStr for Position { | ||
121 | type Err = anyhow::Error; | ||
122 | fn from_str(s: &str) -> Result<Self> { | ||
123 | let (path_line, column) = rsplit_at_char(s, ':')?; | ||
124 | let (path, line) = rsplit_at_char(path_line, ':')?; | ||
125 | Ok(Position { path: path.into(), line: line.parse()?, column: column.parse()? }) | ||
126 | } | ||
127 | } | ||
128 | |||
129 | fn rsplit_at_char(s: &str, c: char) -> Result<(&str, &str)> { | ||
130 | let idx = s.rfind(c).ok_or_else(|| format_err!("no `{}` in {}", c, s))?; | ||
131 | Ok((&s[..idx], &s[idx + 1..])) | ||
132 | } | ||
133 | |||
134 | struct HelpPrinted; | ||
135 | |||
136 | impl Command { | ||
137 | fn from_env_args() -> Result<Result<Command, HelpPrinted>> { | ||
138 | let mut matches = Arguments::from_env(); | ||
139 | let subcommand = matches.subcommand()?.unwrap_or_default(); | ||
140 | 48 | ||
141 | let verbosity = match ( | 49 | let verbosity = match ( |
142 | matches.contains(["-vv", "--spammy"]), | 50 | matches.contains(["-vv", "--spammy"]), |
@@ -151,6 +59,13 @@ impl Command { | |||
151 | (false, true, true) => bail!("Invalid flags: -q conflicts with -v"), | 59 | (false, true, true) => bail!("Invalid flags: -q conflicts with -v"), |
152 | }; | 60 | }; |
153 | 61 | ||
62 | let subcommand = match matches.subcommand()? { | ||
63 | Some(it) => it, | ||
64 | None => { | ||
65 | matches.finish().or_else(handle_extra_flags)?; | ||
66 | return Ok(Ok(Args { verbosity, command: Command::RunServer })); | ||
67 | } | ||
68 | }; | ||
154 | let command = match subcommand.as_str() { | 69 | let command = match subcommand.as_str() { |
155 | "parse" => { | 70 | "parse" => { |
156 | if matches.contains(["-h", "--help"]) { | 71 | if matches.contains(["-h", "--help"]) { |
@@ -247,7 +162,7 @@ ARGS: | |||
247 | trailing.pop().unwrap().into() | 162 | trailing.pop().unwrap().into() |
248 | }; | 163 | }; |
249 | 164 | ||
250 | Command::Stats { verbosity, randomize, memory_usage, only, with_deps, path } | 165 | Command::Stats { randomize, memory_usage, only, with_deps, path } |
251 | } | 166 | } |
252 | "analysis-bench" => { | 167 | "analysis-bench" => { |
253 | if matches.contains(["-h", "--help"]) { | 168 | if matches.contains(["-h", "--help"]) { |
@@ -284,7 +199,7 @@ ARGS: | |||
284 | "exactly one of `--highlight`, `--complete` or `--goto-def` must be set" | 199 | "exactly one of `--highlight`, `--complete` or `--goto-def` must be set" |
285 | ), | 200 | ), |
286 | }; | 201 | }; |
287 | Command::Bench { verbosity, path, what } | 202 | Command::Bench { path, what } |
288 | } | 203 | } |
289 | _ => { | 204 | _ => { |
290 | eprintln!( | 205 | eprintln!( |
@@ -307,10 +222,12 @@ SUBCOMMANDS: | |||
307 | return Ok(Err(HelpPrinted)); | 222 | return Ok(Err(HelpPrinted)); |
308 | } | 223 | } |
309 | }; | 224 | }; |
310 | Ok(Ok(command)) | 225 | Ok(Ok(Args { verbosity, command })) |
311 | } | 226 | } |
312 | } | 227 | } |
313 | 228 | ||
229 | pub(crate) struct HelpPrinted; | ||
230 | |||
314 | fn handle_extra_flags(e: pico_args::Error) -> Result<()> { | 231 | fn handle_extra_flags(e: pico_args::Error) -> Result<()> { |
315 | if let pico_args::Error::UnusedArgsLeft(flags) = e { | 232 | if let pico_args::Error::UnusedArgsLeft(flags) = e { |
316 | let mut invalid_flags = String::new(); | 233 | let mut invalid_flags = String::new(); |
@@ -323,14 +240,3 @@ fn handle_extra_flags(e: pico_args::Error) -> Result<()> { | |||
323 | bail!(e); | 240 | bail!(e); |
324 | } | 241 | } |
325 | } | 242 | } |
326 | |||
327 | fn file() -> Result<SourceFile> { | ||
328 | let text = read_stdin()?; | ||
329 | Ok(SourceFile::parse(&text).tree()) | ||
330 | } | ||
331 | |||
332 | fn read_stdin() -> Result<String> { | ||
333 | let mut buff = String::new(); | ||
334 | std::io::stdin().read_to_string(&mut buff)?; | ||
335 | Ok(buff) | ||
336 | } | ||
diff --git a/crates/ra_lsp_server/src/cli.rs b/crates/ra_lsp_server/src/cli.rs new file mode 100644 index 000000000..3c7b8e250 --- /dev/null +++ b/crates/ra_lsp_server/src/cli.rs | |||
@@ -0,0 +1,75 @@ | |||
1 | //! FIXME: write short doc here | ||
2 | |||
3 | mod load_cargo; | ||
4 | mod analysis_stats; | ||
5 | mod analysis_bench; | ||
6 | mod progress_report; | ||
7 | |||
8 | use std::io::Read; | ||
9 | |||
10 | use anyhow::Result; | ||
11 | use ra_ide::{file_structure, Analysis}; | ||
12 | use ra_prof::profile; | ||
13 | use ra_syntax::{AstNode, SourceFile}; | ||
14 | |||
15 | #[derive(Clone, Copy)] | ||
16 | pub enum Verbosity { | ||
17 | Spammy, | ||
18 | Verbose, | ||
19 | Normal, | ||
20 | Quiet, | ||
21 | } | ||
22 | |||
23 | impl Verbosity { | ||
24 | pub fn is_verbose(self) -> bool { | ||
25 | match self { | ||
26 | Verbosity::Verbose | Verbosity::Spammy => true, | ||
27 | _ => false, | ||
28 | } | ||
29 | } | ||
30 | pub fn is_spammy(self) -> bool { | ||
31 | match self { | ||
32 | Verbosity::Spammy => true, | ||
33 | _ => false, | ||
34 | } | ||
35 | } | ||
36 | } | ||
37 | |||
38 | pub fn parse(no_dump: bool) -> Result<()> { | ||
39 | let _p = profile("parsing"); | ||
40 | let file = file()?; | ||
41 | if !no_dump { | ||
42 | println!("{:#?}", file.syntax()); | ||
43 | } | ||
44 | std::mem::forget(file); | ||
45 | Ok(()) | ||
46 | } | ||
47 | |||
48 | pub fn symbols() -> Result<()> { | ||
49 | let file = file()?; | ||
50 | for s in file_structure(&file) { | ||
51 | println!("{:?}", s); | ||
52 | } | ||
53 | Ok(()) | ||
54 | } | ||
55 | |||
56 | pub fn highlight(rainbow: bool) -> Result<()> { | ||
57 | let (analysis, file_id) = Analysis::from_single_file(read_stdin()?); | ||
58 | let html = analysis.highlight_as_html(file_id, rainbow).unwrap(); | ||
59 | println!("{}", html); | ||
60 | Ok(()) | ||
61 | } | ||
62 | |||
63 | pub use analysis_bench::{analysis_bench, BenchWhat, Position}; | ||
64 | pub use analysis_stats::analysis_stats; | ||
65 | |||
66 | fn file() -> Result<SourceFile> { | ||
67 | let text = read_stdin()?; | ||
68 | Ok(SourceFile::parse(&text).tree()) | ||
69 | } | ||
70 | |||
71 | fn read_stdin() -> Result<String> { | ||
72 | let mut buff = String::new(); | ||
73 | std::io::stdin().read_to_string(&mut buff)?; | ||
74 | Ok(buff) | ||
75 | } | ||
diff --git a/crates/ra_cli/src/analysis_bench.rs b/crates/ra_lsp_server/src/cli/analysis_bench.rs index 91fc55fe2..e00f81073 100644 --- a/crates/ra_cli/src/analysis_bench.rs +++ b/crates/ra_lsp_server/src/cli/analysis_bench.rs | |||
@@ -1,17 +1,48 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use std::{path::Path, sync::Arc, time::Instant}; | 3 | use std::{ |
4 | path::{Path, PathBuf}, | ||
5 | str::FromStr, | ||
6 | sync::Arc, | ||
7 | time::Instant, | ||
8 | }; | ||
4 | 9 | ||
5 | use anyhow::format_err; | 10 | use anyhow::{format_err, Result}; |
6 | use ra_db::{ | 11 | use ra_db::{ |
7 | salsa::{Database, Durability}, | 12 | salsa::{Database, Durability}, |
8 | FileId, SourceDatabaseExt, | 13 | FileId, SourceDatabaseExt, |
9 | }; | 14 | }; |
10 | use ra_ide::{Analysis, AnalysisChange, AnalysisHost, FilePosition, LineCol}; | 15 | use ra_ide::{Analysis, AnalysisChange, AnalysisHost, FilePosition, LineCol}; |
11 | 16 | ||
12 | use crate::{load_cargo::load_cargo, BenchWhat, Result, Verbosity}; | 17 | use crate::cli::{load_cargo::load_cargo, Verbosity}; |
18 | |||
19 | pub enum BenchWhat { | ||
20 | Highlight { path: PathBuf }, | ||
21 | Complete(Position), | ||
22 | GotoDef(Position), | ||
23 | } | ||
24 | |||
25 | pub struct Position { | ||
26 | pub path: PathBuf, | ||
27 | pub line: u32, | ||
28 | pub column: u32, | ||
29 | } | ||
30 | |||
31 | impl FromStr for Position { | ||
32 | type Err = anyhow::Error; | ||
33 | fn from_str(s: &str) -> Result<Self> { | ||
34 | let (path_line, column) = rsplit_at_char(s, ':')?; | ||
35 | let (path, line) = rsplit_at_char(path_line, ':')?; | ||
36 | Ok(Position { path: path.into(), line: line.parse()?, column: column.parse()? }) | ||
37 | } | ||
38 | } | ||
39 | |||
40 | fn rsplit_at_char(s: &str, c: char) -> Result<(&str, &str)> { | ||
41 | let idx = s.rfind(c).ok_or_else(|| format_err!("no `{}` in {}", c, s))?; | ||
42 | Ok((&s[..idx], &s[idx + 1..])) | ||
43 | } | ||
13 | 44 | ||
14 | pub(crate) fn run(verbosity: Verbosity, path: &Path, what: BenchWhat) -> Result<()> { | 45 | pub fn analysis_bench(verbosity: Verbosity, path: &Path, what: BenchWhat) -> Result<()> { |
15 | ra_prof::init(); | 46 | ra_prof::init(); |
16 | 47 | ||
17 | let start = Instant::now(); | 48 | let start = Instant::now(); |
diff --git a/crates/ra_cli/src/analysis_stats.rs b/crates/ra_lsp_server/src/cli/analysis_stats.rs index d40f04391..c27fabe3c 100644 --- a/crates/ra_cli/src/analysis_stats.rs +++ b/crates/ra_lsp_server/src/cli/analysis_stats.rs | |||
@@ -13,9 +13,9 @@ use ra_db::SourceDatabaseExt; | |||
13 | use ra_syntax::AstNode; | 13 | use ra_syntax::AstNode; |
14 | use rand::{seq::SliceRandom, thread_rng}; | 14 | use rand::{seq::SliceRandom, thread_rng}; |
15 | 15 | ||
16 | use crate::{load_cargo::load_cargo, progress_report::ProgressReport, Result, Verbosity}; | 16 | use crate::cli::{load_cargo::load_cargo, progress_report::ProgressReport, Result, Verbosity}; |
17 | 17 | ||
18 | pub fn run( | 18 | pub fn analysis_stats( |
19 | verbosity: Verbosity, | 19 | verbosity: Verbosity, |
20 | memory_usage: bool, | 20 | memory_usage: bool, |
21 | path: &Path, | 21 | path: &Path, |
diff --git a/crates/ra_cli/src/load_cargo.rs b/crates/ra_lsp_server/src/cli/load_cargo.rs index b9a4e6aba..bb3e1513b 100644 --- a/crates/ra_cli/src/load_cargo.rs +++ b/crates/ra_lsp_server/src/cli/load_cargo.rs | |||
@@ -7,9 +7,10 @@ use ra_db::{CrateGraph, FileId, SourceRootId}; | |||
7 | use ra_ide::{AnalysisChange, AnalysisHost, FeatureFlags}; | 7 | use ra_ide::{AnalysisChange, AnalysisHost, FeatureFlags}; |
8 | use ra_project_model::{get_rustc_cfg_options, PackageRoot, ProjectWorkspace}; | 8 | use ra_project_model::{get_rustc_cfg_options, PackageRoot, ProjectWorkspace}; |
9 | use ra_vfs::{RootEntry, Vfs, VfsChange, VfsTask, Watch}; | 9 | use ra_vfs::{RootEntry, Vfs, VfsChange, VfsTask, Watch}; |
10 | use ra_vfs_glob::RustPackageFilterBuilder; | ||
11 | use rustc_hash::FxHashMap; | 10 | use rustc_hash::FxHashMap; |
12 | 11 | ||
12 | use crate::vfs_glob::RustPackageFilterBuilder; | ||
13 | |||
13 | use anyhow::Result; | 14 | use anyhow::Result; |
14 | 15 | ||
15 | fn vfs_file_to_id(f: ra_vfs::VfsFile) -> FileId { | 16 | fn vfs_file_to_id(f: ra_vfs::VfsFile) -> FileId { |
diff --git a/crates/ra_cli/src/progress_report.rs b/crates/ra_lsp_server/src/cli/progress_report.rs index 31867a1e9..31867a1e9 100644 --- a/crates/ra_cli/src/progress_report.rs +++ b/crates/ra_lsp_server/src/cli/progress_report.rs | |||
diff --git a/crates/ra_lsp_server/src/lib.rs b/crates/ra_lsp_server/src/lib.rs index a3464a5a3..958c70fe5 100644 --- a/crates/ra_lsp_server/src/lib.rs +++ b/crates/ra_lsp_server/src/lib.rs | |||
@@ -7,6 +7,8 @@ | |||
7 | //! state, and `main_loop` module defines the rules for modifying it. | 7 | //! state, and `main_loop` module defines the rules for modifying it. |
8 | #![recursion_limit = "512"] | 8 | #![recursion_limit = "512"] |
9 | 9 | ||
10 | pub mod cli; | ||
11 | |||
10 | #[allow(unused)] | 12 | #[allow(unused)] |
11 | macro_rules! println { | 13 | macro_rules! println { |
12 | ($($tt:tt)*) => { | 14 | ($($tt:tt)*) => { |
@@ -21,6 +23,7 @@ macro_rules! print { | |||
21 | }; | 23 | }; |
22 | } | 24 | } |
23 | 25 | ||
26 | mod vfs_glob; | ||
24 | mod caps; | 27 | mod caps; |
25 | mod cargo_target_spec; | 28 | mod cargo_target_spec; |
26 | mod conv; | 29 | mod conv; |
diff --git a/crates/ra_lsp_server/src/main.rs b/crates/ra_lsp_server/src/main.rs index ed2eaabd4..a549e5ff1 100644 --- a/crates/ra_lsp_server/src/main.rs +++ b/crates/ra_lsp_server/src/main.rs | |||
@@ -1,14 +1,39 @@ | |||
1 | //! `ra_lsp_server` binary | 1 | //! `ra_lsp_server` binary |
2 | mod args; | ||
2 | 3 | ||
3 | use lsp_server::Connection; | 4 | use lsp_server::Connection; |
4 | use ra_lsp_server::{from_json, show_message, Result, ServerConfig}; | 5 | use ra_lsp_server::{cli, from_json, show_message, Result, ServerConfig}; |
5 | use ra_prof; | 6 | use ra_prof; |
6 | 7 | ||
8 | use crate::args::HelpPrinted; | ||
9 | |||
7 | fn main() -> Result<()> { | 10 | fn main() -> Result<()> { |
8 | setup_logging()?; | 11 | setup_logging()?; |
9 | match Args::parse()? { | 12 | let args = match args::Args::parse()? { |
10 | Args::Version => println!("rust-analyzer {}", env!("REV")), | 13 | Ok(it) => it, |
11 | Args::Run => run_server()?, | 14 | Err(HelpPrinted) => return Ok(()), |
15 | }; | ||
16 | match args.command { | ||
17 | args::Command::Parse { no_dump } => cli::parse(no_dump)?, | ||
18 | args::Command::Symbols => cli::symbols()?, | ||
19 | args::Command::Highlight { rainbow } => cli::highlight(rainbow)?, | ||
20 | args::Command::Stats { randomize, memory_usage, only, with_deps, path } => { | ||
21 | cli::analysis_stats( | ||
22 | args.verbosity, | ||
23 | memory_usage, | ||
24 | path.as_ref(), | ||
25 | only.as_ref().map(String::as_ref), | ||
26 | with_deps, | ||
27 | randomize, | ||
28 | )? | ||
29 | } | ||
30 | |||
31 | args::Command::Bench { path, what } => { | ||
32 | cli::analysis_bench(args.verbosity, path.as_ref(), what)? | ||
33 | } | ||
34 | |||
35 | args::Command::RunServer => run_server()?, | ||
36 | args::Command::Version => println!("rust-analyzer {}", env!("REV")), | ||
12 | } | 37 | } |
13 | Ok(()) | 38 | Ok(()) |
14 | } | 39 | } |
@@ -20,19 +45,6 @@ fn setup_logging() -> Result<()> { | |||
20 | Ok(()) | 45 | Ok(()) |
21 | } | 46 | } |
22 | 47 | ||
23 | enum Args { | ||
24 | Version, | ||
25 | Run, | ||
26 | } | ||
27 | |||
28 | impl Args { | ||
29 | fn parse() -> Result<Args> { | ||
30 | let res = | ||
31 | if std::env::args().any(|it| it == "--version") { Args::Version } else { Args::Run }; | ||
32 | Ok(res) | ||
33 | } | ||
34 | } | ||
35 | |||
36 | fn run_server() -> Result<()> { | 48 | fn run_server() -> Result<()> { |
37 | log::info!("lifecycle: server started"); | 49 | log::info!("lifecycle: server started"); |
38 | 50 | ||
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index 7ae2e1e6f..944074118 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs | |||
@@ -135,7 +135,7 @@ pub fn main_loop( | |||
135 | let globs = config | 135 | let globs = config |
136 | .exclude_globs | 136 | .exclude_globs |
137 | .iter() | 137 | .iter() |
138 | .map(|glob| ra_vfs_glob::Glob::new(glob)) | 138 | .map(|glob| crate::vfs_glob::Glob::new(glob)) |
139 | .collect::<std::result::Result<Vec<_>, _>>()?; | 139 | .collect::<std::result::Result<Vec<_>, _>>()?; |
140 | 140 | ||
141 | if config.use_client_watching { | 141 | if config.use_client_watching { |
diff --git a/crates/ra_vfs_glob/src/lib.rs b/crates/ra_lsp_server/src/vfs_glob.rs index 12401d75a..12401d75a 100644 --- a/crates/ra_vfs_glob/src/lib.rs +++ b/crates/ra_lsp_server/src/vfs_glob.rs | |||
diff --git a/crates/ra_lsp_server/src/world.rs b/crates/ra_lsp_server/src/world.rs index d993c5fc4..71c95d4af 100644 --- a/crates/ra_lsp_server/src/world.rs +++ b/crates/ra_lsp_server/src/world.rs | |||
@@ -19,12 +19,12 @@ use ra_ide::{ | |||
19 | }; | 19 | }; |
20 | use ra_project_model::{get_rustc_cfg_options, ProjectWorkspace}; | 20 | use ra_project_model::{get_rustc_cfg_options, ProjectWorkspace}; |
21 | use ra_vfs::{LineEndings, RootEntry, Vfs, VfsChange, VfsFile, VfsRoot, VfsTask, Watch}; | 21 | use ra_vfs::{LineEndings, RootEntry, Vfs, VfsChange, VfsFile, VfsRoot, VfsTask, Watch}; |
22 | use ra_vfs_glob::{Glob, RustPackageFilterBuilder}; | ||
23 | use relative_path::RelativePathBuf; | 22 | use relative_path::RelativePathBuf; |
24 | 23 | ||
25 | use crate::{ | 24 | use crate::{ |
26 | diagnostics::{CheckFixes, DiagnosticCollection}, | 25 | diagnostics::{CheckFixes, DiagnosticCollection}, |
27 | main_loop::pending_requests::{CompletedRequest, LatestRequests}, | 26 | main_loop::pending_requests::{CompletedRequest, LatestRequests}, |
27 | vfs_glob::{Glob, RustPackageFilterBuilder}, | ||
28 | LspError, Result, | 28 | LspError, Result, |
29 | }; | 29 | }; |
30 | 30 | ||
diff --git a/crates/ra_vfs_glob/Cargo.toml b/crates/ra_vfs_glob/Cargo.toml deleted file mode 100644 index 094d6d6f4..000000000 --- a/crates/ra_vfs_glob/Cargo.toml +++ /dev/null | |||
@@ -1,12 +0,0 @@ | |||
1 | [package] | ||
2 | edition = "2018" | ||
3 | name = "ra_vfs_glob" | ||
4 | version = "0.1.0" | ||
5 | authors = ["rust-analyzer developers"] | ||
6 | |||
7 | [lib] | ||
8 | doctest = false | ||
9 | |||
10 | [dependencies] | ||
11 | ra_vfs = "0.5.0" | ||
12 | globset = "0.4.4" | ||
diff --git a/xtask/tests/tidy-tests/docs.rs b/xtask/tests/tidy-tests/docs.rs index a8ed9793f..b2571df25 100644 --- a/xtask/tests/tidy-tests/docs.rs +++ b/xtask/tests/tidy-tests/docs.rs | |||
@@ -73,7 +73,6 @@ fn no_docs_comments() { | |||
73 | } | 73 | } |
74 | 74 | ||
75 | let whitelist = [ | 75 | let whitelist = [ |
76 | "ra_cli", | ||
77 | "ra_db", | 76 | "ra_db", |
78 | "ra_hir", | 77 | "ra_hir", |
79 | "ra_hir_expand", | 78 | "ra_hir_expand", |