diff options
author | Aleksey Kladov <[email protected]> | 2020-02-17 18:03:03 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-02-17 18:03:03 +0000 |
commit | 659b0e73cfd9ef7755d032f90622a08576f1d86d (patch) | |
tree | 238a2cb3e021502608d357785ebbe3b21f94573f /crates/ra_lsp_server/src/cli.rs | |
parent | 2d1b3da5fb69d932c65884a361ec10d81e8a51d8 (diff) |
Merge cli and ra_lsp_server
Diffstat (limited to 'crates/ra_lsp_server/src/cli.rs')
-rw-r--r-- | crates/ra_lsp_server/src/cli.rs | 75 |
1 files changed, 75 insertions, 0 deletions
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 | } | ||