aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_db/src/input.rs2
-rw-r--r--crates/ra_ide_db/src/feature_flags.rs2
-rw-r--r--crates/ra_lsp_server/src/cargo_target_spec.rs113
-rw-r--r--crates/ra_prof/src/lib.rs4
-rw-r--r--crates/ra_project_model/src/sysroot.rs72
-rw-r--r--crates/ra_syntax/Cargo.toml2
-rw-r--r--crates/ra_tt/Cargo.toml2
-rw-r--r--crates/rust-analyzer/Cargo.toml (renamed from crates/ra_lsp_server/Cargo.toml)7
-rw-r--r--crates/rust-analyzer/build.rs (renamed from crates/ra_lsp_server/build.rs)0
-rw-r--r--crates/rust-analyzer/src/bin/args.rs (renamed from crates/ra_lsp_server/src/args.rs)16
-rw-r--r--crates/rust-analyzer/src/bin/main.rs (renamed from crates/ra_lsp_server/src/main.rs)10
-rw-r--r--crates/rust-analyzer/src/caps.rs (renamed from crates/ra_lsp_server/src/caps.rs)0
-rw-r--r--crates/rust-analyzer/src/cargo_target_spec.rs118
-rw-r--r--crates/rust-analyzer/src/cli.rs (renamed from crates/ra_lsp_server/src/cli.rs)2
-rw-r--r--crates/rust-analyzer/src/cli/analysis_bench.rs (renamed from crates/ra_lsp_server/src/cli/analysis_bench.rs)2
-rw-r--r--crates/rust-analyzer/src/cli/analysis_stats.rs (renamed from crates/ra_lsp_server/src/cli/analysis_stats.rs)3
-rw-r--r--crates/rust-analyzer/src/cli/load_cargo.rs (renamed from crates/ra_lsp_server/src/cli/load_cargo.rs)18
-rw-r--r--crates/rust-analyzer/src/cli/progress_report.rs (renamed from crates/ra_lsp_server/src/cli/progress_report.rs)0
-rw-r--r--crates/rust-analyzer/src/config.rs (renamed from crates/ra_lsp_server/src/config.rs)0
-rw-r--r--crates/rust-analyzer/src/conv.rs (renamed from crates/ra_lsp_server/src/conv.rs)3
-rw-r--r--crates/rust-analyzer/src/diagnostics.rs (renamed from crates/ra_lsp_server/src/diagnostics.rs)4
-rw-r--r--crates/rust-analyzer/src/lib.rs (renamed from crates/ra_lsp_server/src/lib.rs)7
-rw-r--r--crates/rust-analyzer/src/main_loop.rs (renamed from crates/ra_lsp_server/src/main_loop.rs)4
-rw-r--r--crates/rust-analyzer/src/main_loop/handlers.rs (renamed from crates/ra_lsp_server/src/main_loop/handlers.rs)10
-rw-r--r--crates/rust-analyzer/src/main_loop/pending_requests.rs (renamed from crates/ra_lsp_server/src/main_loop/pending_requests.rs)2
-rw-r--r--crates/rust-analyzer/src/main_loop/subscriptions.rs (renamed from crates/ra_lsp_server/src/main_loop/subscriptions.rs)3
-rw-r--r--crates/rust-analyzer/src/markdown.rs (renamed from crates/ra_lsp_server/src/markdown.rs)0
-rw-r--r--crates/rust-analyzer/src/req.rs (renamed from crates/ra_lsp_server/src/req.rs)0
-rw-r--r--crates/rust-analyzer/src/vfs_glob.rs (renamed from crates/ra_lsp_server/src/vfs_glob.rs)2
-rw-r--r--crates/rust-analyzer/src/world.rs (renamed from crates/ra_lsp_server/src/world.rs)4
-rw-r--r--crates/rust-analyzer/tests/heavy_tests/main.rs (renamed from crates/ra_lsp_server/tests/heavy_tests/main.rs)2
-rw-r--r--crates/rust-analyzer/tests/heavy_tests/support.rs (renamed from crates/ra_lsp_server/tests/heavy_tests/support.rs)2
32 files changed, 228 insertions, 188 deletions
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs
index 1f1dcea42..1b4b47215 100644
--- a/crates/ra_db/src/input.rs
+++ b/crates/ra_db/src/input.rs
@@ -3,7 +3,7 @@
3//! derived from this input. 3//! derived from this input.
4//! 4//!
5//! Note that neither this module, nor any other part of the analyzer's core do 5//! Note that neither this module, nor any other part of the analyzer's core do
6//! actual IO. See `vfs` and `project_model` in the `ra_lsp_server` crate for how 6//! actual IO. See `vfs` and `project_model` in the `rust-analyzer` crate for how
7//! actual IO is done and lowered to input. 7//! actual IO is done and lowered to input.
8 8
9use std::{fmt, str::FromStr}; 9use std::{fmt, str::FromStr};
diff --git a/crates/ra_ide_db/src/feature_flags.rs b/crates/ra_ide_db/src/feature_flags.rs
index 1b3cabf4d..76655f572 100644
--- a/crates/ra_ide_db/src/feature_flags.rs
+++ b/crates/ra_ide_db/src/feature_flags.rs
@@ -13,7 +13,7 @@ use rustc_hash::FxHashMap;
13/// checked at compile time, to keep things simple and flexible. 13/// checked at compile time, to keep things simple and flexible.
14/// 14///
15/// Also note that, at the moment, `FeatureFlags` also store features for 15/// Also note that, at the moment, `FeatureFlags` also store features for
16/// `ra_lsp_server`. This should be benign layering violation. 16/// `rust-analyzer`. This should be benign layering violation.
17#[derive(Debug)] 17#[derive(Debug)]
18pub struct FeatureFlags { 18pub struct FeatureFlags {
19 flags: FxHashMap<String, bool>, 19 flags: FxHashMap<String, bool>,
diff --git a/crates/ra_lsp_server/src/cargo_target_spec.rs b/crates/ra_lsp_server/src/cargo_target_spec.rs
deleted file mode 100644
index 5fd1e7b6b..000000000
--- a/crates/ra_lsp_server/src/cargo_target_spec.rs
+++ /dev/null
@@ -1,113 +0,0 @@
1//! FIXME: write short doc here
2
3use ra_ide::{FileId, RunnableKind, TestId};
4use ra_project_model::{self, ProjectWorkspace, TargetKind};
5
6use crate::{world::WorldSnapshot, Result};
7
8pub(crate) fn runnable_args(
9 world: &WorldSnapshot,
10 file_id: FileId,
11 kind: &RunnableKind,
12) -> Result<Vec<String>> {
13 let spec = CargoTargetSpec::for_file(world, file_id)?;
14 let mut res = Vec::new();
15 match kind {
16 RunnableKind::Test { test_id } => {
17 res.push("test".to_string());
18 if let Some(spec) = spec {
19 spec.push_to(&mut res);
20 }
21 res.push("--".to_string());
22 res.push(test_id.to_string());
23 if let TestId::Path(_) = test_id {
24 res.push("--exact".to_string());
25 }
26 res.push("--nocapture".to_string());
27 }
28 RunnableKind::TestMod { path } => {
29 res.push("test".to_string());
30 if let Some(spec) = spec {
31 spec.push_to(&mut res);
32 }
33 res.push("--".to_string());
34 res.push(path.to_string());
35 res.push("--nocapture".to_string());
36 }
37 RunnableKind::Bench { test_id } => {
38 res.push("bench".to_string());
39 if let Some(spec) = spec {
40 spec.push_to(&mut res);
41 }
42 res.push("--".to_string());
43 res.push(test_id.to_string());
44 if let TestId::Path(_) = test_id {
45 res.push("--exact".to_string());
46 }
47 res.push("--nocapture".to_string());
48 }
49 RunnableKind::Bin => {
50 res.push("run".to_string());
51 if let Some(spec) = spec {
52 spec.push_to(&mut res);
53 }
54 }
55 }
56 Ok(res)
57}
58
59pub struct CargoTargetSpec {
60 pub package: String,
61 pub target: String,
62 pub target_kind: TargetKind,
63}
64
65impl CargoTargetSpec {
66 pub fn for_file(world: &WorldSnapshot, file_id: FileId) -> Result<Option<CargoTargetSpec>> {
67 let &crate_id = match world.analysis().crate_for(file_id)?.first() {
68 Some(crate_id) => crate_id,
69 None => return Ok(None),
70 };
71 let file_id = world.analysis().crate_root(crate_id)?;
72 let path = world.file_id_to_path(file_id);
73 let res = world.workspaces.iter().find_map(|ws| match ws {
74 ProjectWorkspace::Cargo { cargo, .. } => {
75 let tgt = cargo.target_by_root(&path)?;
76 Some(CargoTargetSpec {
77 package: tgt.package(&cargo).name(&cargo).to_string(),
78 target: tgt.name(&cargo).to_string(),
79 target_kind: tgt.kind(&cargo),
80 })
81 }
82 ProjectWorkspace::Json { .. } => None,
83 });
84 Ok(res)
85 }
86
87 pub fn push_to(self, buf: &mut Vec<String>) {
88 buf.push("--package".to_string());
89 buf.push(self.package);
90 match self.target_kind {
91 TargetKind::Bin => {
92 buf.push("--bin".to_string());
93 buf.push(self.target);
94 }
95 TargetKind::Test => {
96 buf.push("--test".to_string());
97 buf.push(self.target);
98 }
99 TargetKind::Bench => {
100 buf.push("--bench".to_string());
101 buf.push(self.target);
102 }
103 TargetKind::Example => {
104 buf.push("--example".to_string());
105 buf.push(self.target);
106 }
107 TargetKind::Lib => {
108 buf.push("--lib".to_string());
109 }
110 TargetKind::Other => (),
111 }
112 }
113}
diff --git a/crates/ra_prof/src/lib.rs b/crates/ra_prof/src/lib.rs
index 7ff8db58a..c267bc85f 100644
--- a/crates/ra_prof/src/lib.rs
+++ b/crates/ra_prof/src/lib.rs
@@ -351,13 +351,13 @@ impl Drop for Scope {
351/// 2. Build with `cpu_profiler` feature. 351/// 2. Build with `cpu_profiler` feature.
352/// 3. Tun the code, the *raw* output would be in the `./out.profile` file. 352/// 3. Tun the code, the *raw* output would be in the `./out.profile` file.
353/// 4. Install pprof for visualization (https://github.com/google/pprof). 353/// 4. Install pprof for visualization (https://github.com/google/pprof).
354/// 5. Use something like `pprof -svg target/release/ra_lsp_server ./out.profile` to see the results. 354/// 5. Use something like `pprof -svg target/release/rust-analyzer ./out.profile` to see the results.
355/// 355///
356/// For example, here's how I run profiling on NixOS: 356/// For example, here's how I run profiling on NixOS:
357/// 357///
358/// ```bash 358/// ```bash
359/// $ nix-shell -p gperftools --run \ 359/// $ nix-shell -p gperftools --run \
360/// 'cargo run --release -p ra_lsp_server -- parse < ~/projects/rustbench/parser.rs > /dev/null' 360/// 'cargo run --release -p rust-analyzer -- parse < ~/projects/rustbench/parser.rs > /dev/null'
361/// ``` 361/// ```
362#[derive(Debug)] 362#[derive(Debug)]
363pub struct CpuProfiler { 363pub struct CpuProfiler {
diff --git a/crates/ra_project_model/src/sysroot.rs b/crates/ra_project_model/src/sysroot.rs
index 7b9cc899c..db779a2d2 100644
--- a/crates/ra_project_model/src/sysroot.rs
+++ b/crates/ra_project_model/src/sysroot.rs
@@ -1,10 +1,10 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use anyhow::{anyhow, bail, Context, Result}; 3use anyhow::{bail, Context, Result};
4use std::{ 4use std::{
5 env, 5 env,
6 path::{Path, PathBuf}, 6 path::{Path, PathBuf},
7 process::Command, 7 process::{Command, Output},
8}; 8};
9 9
10use ra_arena::{impl_arena_id, Arena, RawId}; 10use ra_arena::{impl_arena_id, Arena, RawId};
@@ -47,18 +47,7 @@ impl Sysroot {
47 } 47 }
48 48
49 pub fn discover(cargo_toml: &Path) -> Result<Sysroot> { 49 pub fn discover(cargo_toml: &Path) -> Result<Sysroot> {
50 let src = try_find_src_path(cargo_toml)?; 50 let src = get_or_install_rust_src(cargo_toml)?;
51
52 if !src.exists() {
53 Err(anyhow!(
54 "can't load standard library from sysroot\n\
55 {}\n\
56 (discovered via `rustc --print sysroot`)\n\
57 try running `rustup component add rust-src` or set `RUST_SRC_PATH`",
58 src.display(),
59 ))?;
60 }
61
62 let mut sysroot = Sysroot { crates: Arena::default() }; 51 let mut sysroot = Sysroot { crates: Arena::default() };
63 for name in SYSROOT_CRATES.trim().lines() { 52 for name in SYSROOT_CRATES.trim().lines() {
64 let root = src.join(format!("lib{}", name)).join("lib.rs"); 53 let root = src.join(format!("lib{}", name)).join("lib.rs");
@@ -90,27 +79,54 @@ impl Sysroot {
90 } 79 }
91} 80}
92 81
93fn try_find_src_path(cargo_toml: &Path) -> Result<PathBuf> { 82fn create_command_text(program: &str, args: &[&str]) -> String {
94 if let Ok(path) = env::var("RUST_SRC_PATH") { 83 format!("{} {}", program, args.join(" "))
95 return Ok(path.into()); 84}
96 }
97 85
98 let rustc_output = Command::new("rustc") 86fn run_command_in_cargo_dir(cargo_toml: &Path, program: &str, args: &[&str]) -> Result<Output> {
87 let output = Command::new(program)
99 .current_dir(cargo_toml.parent().unwrap()) 88 .current_dir(cargo_toml.parent().unwrap())
100 .args(&["--print", "sysroot"]) 89 .args(args)
101 .output() 90 .output()
102 .context("rustc --print sysroot failed")?; 91 .context(format!("{} failed", create_command_text(program, args)))?;
103 if !rustc_output.status.success() { 92 if !output.status.success() {
104 match rustc_output.status.code() { 93 match output.status.code() {
105 Some(code) => { 94 Some(code) => bail!(
106 bail!("failed to locate sysroot: rustc --print sysroot exited with code {}", code) 95 "failed to run the command: '{}' exited with code {}",
107 } 96 create_command_text(program, args),
108 None => bail!("failed to locate sysroot: rustc --print sysroot terminated by signal"), 97 code
98 ),
99 None => bail!(
100 "failed to run the command: '{}' terminated by signal",
101 create_command_text(program, args)
102 ),
109 }; 103 };
110 } 104 }
105 Ok(output)
106}
107
108fn get_or_install_rust_src(cargo_toml: &Path) -> Result<PathBuf> {
109 if let Ok(path) = env::var("RUST_SRC_PATH") {
110 return Ok(path.into());
111 }
112 let rustc_output = run_command_in_cargo_dir(cargo_toml, "rustc", &["--print", "sysroot"])?;
111 let stdout = String::from_utf8(rustc_output.stdout)?; 113 let stdout = String::from_utf8(rustc_output.stdout)?;
112 let sysroot_path = Path::new(stdout.trim()); 114 let sysroot_path = Path::new(stdout.trim());
113 Ok(sysroot_path.join("lib/rustlib/src/rust/src")) 115 let src_path = sysroot_path.join("lib/rustlib/src/rust/src");
116
117 if !src_path.exists() {
118 run_command_in_cargo_dir(cargo_toml, "rustup", &["component", "add", "rust-src"])?;
119 }
120 if !src_path.exists() {
121 bail!(
122 "can't load standard library from sysroot\n\
123 {}\n\
124 (discovered via `rustc --print sysroot`)\n\
125 try running `rustup component add rust-src` or set `RUST_SRC_PATH`",
126 src_path.display(),
127 )
128 }
129 Ok(src_path)
114} 130}
115 131
116impl SysrootCrate { 132impl SysrootCrate {
diff --git a/crates/ra_syntax/Cargo.toml b/crates/ra_syntax/Cargo.toml
index 83db943fe..cb72972c5 100644
--- a/crates/ra_syntax/Cargo.toml
+++ b/crates/ra_syntax/Cargo.toml
@@ -22,7 +22,7 @@ ra_text_edit = { path = "../ra_text_edit" }
22ra_parser = { path = "../ra_parser" } 22ra_parser = { path = "../ra_parser" }
23 23
24# This crate transitively depends on `smol_str` via `rowan`. 24# This crate transitively depends on `smol_str` via `rowan`.
25# ideally, `serde` should be enabled by `ra_lsp_server`, but we enable it here 25# ideally, `serde` should be enabled by `rust-analyzer`, but we enable it here
26# to reduce number of compilations 26# to reduce number of compilations
27smol_str = { version = "0.1.12", features = ["serde"] } 27smol_str = { version = "0.1.12", features = ["serde"] }
28serde = { version = "1", features = ["derive"] } 28serde = { version = "1", features = ["derive"] }
diff --git a/crates/ra_tt/Cargo.toml b/crates/ra_tt/Cargo.toml
index b8dceb92a..c9601fdcc 100644
--- a/crates/ra_tt/Cargo.toml
+++ b/crates/ra_tt/Cargo.toml
@@ -8,6 +8,6 @@ authors = ["rust-analyzer developers"]
8doctest = false 8doctest = false
9 9
10[dependencies] 10[dependencies]
11# ideally, `serde` should be enabled by `ra_lsp_server`, but we enable it here 11# ideally, `serde` should be enabled by `rust-analyzer`, but we enable it here
12# to reduce number of compilations 12# to reduce number of compilations
13smol_str = { version = "0.1.12", features = ["serde"] } 13smol_str = { version = "0.1.12", features = ["serde"] }
diff --git a/crates/ra_lsp_server/Cargo.toml b/crates/rust-analyzer/Cargo.toml
index da523ba8a..3dae43d2a 100644
--- a/crates/ra_lsp_server/Cargo.toml
+++ b/crates/rust-analyzer/Cargo.toml
@@ -1,12 +1,17 @@
1[package] 1[package]
2edition = "2018" 2edition = "2018"
3name = "ra_lsp_server" 3name = "rust-analyzer"
4version = "0.1.0" 4version = "0.1.0"
5authors = ["rust-analyzer developers"] 5authors = ["rust-analyzer developers"]
6autobins = false
6 7
7[lib] 8[lib]
8doctest = false 9doctest = false
9 10
11[[bin]]
12name = "rust-analyzer"
13path = "./src/bin/main.rs"
14
10[dependencies] 15[dependencies]
11anyhow = "1.0" 16anyhow = "1.0"
12crossbeam-channel = "0.4" 17crossbeam-channel = "0.4"
diff --git a/crates/ra_lsp_server/build.rs b/crates/rust-analyzer/build.rs
index 05f9772c0..05f9772c0 100644
--- a/crates/ra_lsp_server/build.rs
+++ b/crates/rust-analyzer/build.rs
diff --git a/crates/ra_lsp_server/src/args.rs b/crates/rust-analyzer/src/bin/args.rs
index 3890fe13a..5ad3963a2 100644
--- a/crates/ra_lsp_server/src/args.rs
+++ b/crates/rust-analyzer/src/bin/args.rs
@@ -5,7 +5,7 @@
5 5
6use anyhow::{bail, Result}; 6use anyhow::{bail, Result};
7use pico_args::Arguments; 7use pico_args::Arguments;
8use ra_lsp_server::cli::{BenchWhat, Position, Verbosity}; 8use rust_analyzer::cli::{BenchWhat, Position, Verbosity};
9 9
10use std::{fmt::Write, path::PathBuf}; 10use std::{fmt::Write, path::PathBuf};
11 11
@@ -74,7 +74,7 @@ impl Args {
74ra-cli-parse 74ra-cli-parse
75 75
76USAGE: 76USAGE:
77 ra_lsp_server parse [FLAGS] 77 rust-analyzer parse [FLAGS]
78 78
79FLAGS: 79FLAGS:
80 -h, --help Prints help inforamtion 80 -h, --help Prints help inforamtion
@@ -94,7 +94,7 @@ FLAGS:
94ra-cli-symbols 94ra-cli-symbols
95 95
96USAGE: 96USAGE:
97 ra_lsp_server highlight [FLAGS] 97 rust-analyzer highlight [FLAGS]
98 98
99FLAGS: 99FLAGS:
100 -h, --help Prints help inforamtion" 100 -h, --help Prints help inforamtion"
@@ -113,7 +113,7 @@ FLAGS:
113ra-cli-highlight 113ra-cli-highlight
114 114
115USAGE: 115USAGE:
116 ra_lsp_server highlight [FLAGS] 116 rust-analyzer highlight [FLAGS]
117 117
118FLAGS: 118FLAGS:
119 -h, --help Prints help information 119 -h, --help Prints help information
@@ -133,7 +133,7 @@ FLAGS:
133ra-cli-analysis-stats 133ra-cli-analysis-stats
134 134
135USAGE: 135USAGE:
136 ra_lsp_server analysis-stats [FLAGS] [OPTIONS] [PATH] 136 rust-analyzer analysis-stats [FLAGS] [OPTIONS] [PATH]
137 137
138FLAGS: 138FLAGS:
139 -h, --help Prints help information 139 -h, --help Prints help information
@@ -168,10 +168,10 @@ ARGS:
168 if matches.contains(["-h", "--help"]) { 168 if matches.contains(["-h", "--help"]) {
169 eprintln!( 169 eprintln!(
170 "\ 170 "\
171ra_lsp_server-analysis-bench 171rust-analyzer-analysis-bench
172 172
173USAGE: 173USAGE:
174 ra_lsp_server analysis-bench [FLAGS] [OPTIONS] [PATH] 174 rust-analyzer analysis-bench [FLAGS] [OPTIONS] [PATH]
175 175
176FLAGS: 176FLAGS:
177 -h, --help Prints help information 177 -h, --help Prints help information
@@ -207,7 +207,7 @@ ARGS:
207ra-cli 207ra-cli
208 208
209USAGE: 209USAGE:
210 ra_lsp_server <SUBCOMMAND> 210 rust-analyzer <SUBCOMMAND>
211 211
212FLAGS: 212FLAGS:
213 -h, --help Prints help information 213 -h, --help Prints help information
diff --git a/crates/ra_lsp_server/src/main.rs b/crates/rust-analyzer/src/bin/main.rs
index a549e5ff1..69e709a25 100644
--- a/crates/ra_lsp_server/src/main.rs
+++ b/crates/rust-analyzer/src/bin/main.rs
@@ -1,9 +1,11 @@
1//! `ra_lsp_server` binary 1//! Driver for rust-analyzer.
2//!
3//! Based on cli flags, either spawns an LSP server, or runs a batch analysis
2mod args; 4mod args;
3 5
4use lsp_server::Connection; 6use lsp_server::Connection;
5use ra_lsp_server::{cli, from_json, show_message, Result, ServerConfig};
6use ra_prof; 7use ra_prof;
8use rust_analyzer::{cli, from_json, show_message, Result, ServerConfig};
7 9
8use crate::args::HelpPrinted; 10use crate::args::HelpPrinted;
9 11
@@ -49,7 +51,7 @@ fn run_server() -> Result<()> {
49 log::info!("lifecycle: server started"); 51 log::info!("lifecycle: server started");
50 52
51 let (connection, io_threads) = Connection::stdio(); 53 let (connection, io_threads) = Connection::stdio();
52 let server_capabilities = serde_json::to_value(ra_lsp_server::server_capabilities()).unwrap(); 54 let server_capabilities = serde_json::to_value(rust_analyzer::server_capabilities()).unwrap();
53 55
54 let initialize_params = connection.initialize(server_capabilities)?; 56 let initialize_params = connection.initialize(server_capabilities)?;
55 let initialize_params = 57 let initialize_params =
@@ -82,7 +84,7 @@ fn run_server() -> Result<()> {
82 }) 84 })
83 .unwrap_or_default(); 85 .unwrap_or_default();
84 86
85 ra_lsp_server::main_loop( 87 rust_analyzer::main_loop(
86 workspace_roots, 88 workspace_roots,
87 initialize_params.capabilities, 89 initialize_params.capabilities,
88 server_config, 90 server_config,
diff --git a/crates/ra_lsp_server/src/caps.rs b/crates/rust-analyzer/src/caps.rs
index c4711076c..c4711076c 100644
--- a/crates/ra_lsp_server/src/caps.rs
+++ b/crates/rust-analyzer/src/caps.rs
diff --git a/crates/rust-analyzer/src/cargo_target_spec.rs b/crates/rust-analyzer/src/cargo_target_spec.rs
new file mode 100644
index 000000000..53751aafb
--- /dev/null
+++ b/crates/rust-analyzer/src/cargo_target_spec.rs
@@ -0,0 +1,118 @@
1//! See `CargoTargetSpec`
2
3use ra_ide::{FileId, RunnableKind, TestId};
4use ra_project_model::{self, ProjectWorkspace, TargetKind};
5
6use crate::{world::WorldSnapshot, Result};
7
8/// Abstract representation of Cargo target.
9///
10/// We use it to cook up the set of cli args we need to pass to Cargo to
11/// build/test/run the target.
12pub(crate) struct CargoTargetSpec {
13 pub(crate) package: String,
14 pub(crate) target: String,
15 pub(crate) target_kind: TargetKind,
16}
17
18impl CargoTargetSpec {
19 pub(crate) fn runnable_args(
20 spec: Option<CargoTargetSpec>,
21 kind: &RunnableKind,
22 ) -> Result<Vec<String>> {
23 let mut res = Vec::new();
24 match kind {
25 RunnableKind::Test { test_id } => {
26 res.push("test".to_string());
27 if let Some(spec) = spec {
28 spec.push_to(&mut res);
29 }
30 res.push("--".to_string());
31 res.push(test_id.to_string());
32 if let TestId::Path(_) = test_id {
33 res.push("--exact".to_string());
34 }
35 res.push("--nocapture".to_string());
36 }
37 RunnableKind::TestMod { path } => {
38 res.push("test".to_string());
39 if let Some(spec) = spec {
40 spec.push_to(&mut res);
41 }
42 res.push("--".to_string());
43 res.push(path.to_string());
44 res.push("--nocapture".to_string());
45 }
46 RunnableKind::Bench { test_id } => {
47 res.push("bench".to_string());
48 if let Some(spec) = spec {
49 spec.push_to(&mut res);
50 }
51 res.push("--".to_string());
52 res.push(test_id.to_string());
53 if let TestId::Path(_) = test_id {
54 res.push("--exact".to_string());
55 }
56 res.push("--nocapture".to_string());
57 }
58 RunnableKind::Bin => {
59 res.push("run".to_string());
60 if let Some(spec) = spec {
61 spec.push_to(&mut res);
62 }
63 }
64 }
65 Ok(res)
66 }
67
68 pub(crate) fn for_file(
69 world: &WorldSnapshot,
70 file_id: FileId,
71 ) -> Result<Option<CargoTargetSpec>> {
72 let &crate_id = match world.analysis().crate_for(file_id)?.first() {
73 Some(crate_id) => crate_id,
74 None => return Ok(None),
75 };
76 let file_id = world.analysis().crate_root(crate_id)?;
77 let path = world.file_id_to_path(file_id);
78 let res = world.workspaces.iter().find_map(|ws| match ws {
79 ProjectWorkspace::Cargo { cargo, .. } => {
80 let tgt = cargo.target_by_root(&path)?;
81 Some(CargoTargetSpec {
82 package: tgt.package(&cargo).name(&cargo).to_string(),
83 target: tgt.name(&cargo).to_string(),
84 target_kind: tgt.kind(&cargo),
85 })
86 }
87 ProjectWorkspace::Json { .. } => None,
88 });
89 Ok(res)
90 }
91
92 pub(crate) fn push_to(self, buf: &mut Vec<String>) {
93 buf.push("--package".to_string());
94 buf.push(self.package);
95 match self.target_kind {
96 TargetKind::Bin => {
97 buf.push("--bin".to_string());
98 buf.push(self.target);
99 }
100 TargetKind::Test => {
101 buf.push("--test".to_string());
102 buf.push(self.target);
103 }
104 TargetKind::Bench => {
105 buf.push("--bench".to_string());
106 buf.push(self.target);
107 }
108 TargetKind::Example => {
109 buf.push("--example".to_string());
110 buf.push(self.target);
111 }
112 TargetKind::Lib => {
113 buf.push("--lib".to_string());
114 }
115 TargetKind::Other => (),
116 }
117 }
118}
diff --git a/crates/ra_lsp_server/src/cli.rs b/crates/rust-analyzer/src/cli.rs
index 3c7b8e250..c9738d101 100644
--- a/crates/ra_lsp_server/src/cli.rs
+++ b/crates/rust-analyzer/src/cli.rs
@@ -1,4 +1,4 @@
1//! FIXME: write short doc here 1//! Various batch processing tasks, intended primarily for debugging.
2 2
3mod load_cargo; 3mod load_cargo;
4mod analysis_stats; 4mod analysis_stats;
diff --git a/crates/ra_lsp_server/src/cli/analysis_bench.rs b/crates/rust-analyzer/src/cli/analysis_bench.rs
index e00f81073..91855e592 100644
--- a/crates/ra_lsp_server/src/cli/analysis_bench.rs
+++ b/crates/rust-analyzer/src/cli/analysis_bench.rs
@@ -1,4 +1,4 @@
1//! FIXME: write short doc here 1//! Benchmark operations like highlighting or goto definition.
2 2
3use std::{ 3use std::{
4 path::{Path, PathBuf}, 4 path::{Path, PathBuf},
diff --git a/crates/ra_lsp_server/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs
index c27fabe3c..99ab6e443 100644
--- a/crates/ra_lsp_server/src/cli/analysis_stats.rs
+++ b/crates/rust-analyzer/src/cli/analysis_stats.rs
@@ -1,4 +1,5 @@
1//! FIXME: write short doc here 1//! Fully type-check project and print various stats, like the number of type
2//! errors.
2 3
3use std::{collections::HashSet, fmt::Write, path::Path, time::Instant}; 4use std::{collections::HashSet, fmt::Write, path::Path, time::Instant};
4 5
diff --git a/crates/ra_lsp_server/src/cli/load_cargo.rs b/crates/rust-analyzer/src/cli/load_cargo.rs
index bb3e1513b..8cd08ecb6 100644
--- a/crates/ra_lsp_server/src/cli/load_cargo.rs
+++ b/crates/rust-analyzer/src/cli/load_cargo.rs
@@ -1,18 +1,18 @@
1//! FIXME: write short doc here 1//! Loads a Cargo project into a static instance of analysis, without support
2//! for incorporating changes.
2 3
3use std::{collections::HashSet, path::Path}; 4use std::path::Path;
4 5
6use anyhow::Result;
5use crossbeam_channel::{unbounded, Receiver}; 7use crossbeam_channel::{unbounded, Receiver};
6use ra_db::{CrateGraph, FileId, SourceRootId}; 8use ra_db::{CrateGraph, FileId, SourceRootId};
7use ra_ide::{AnalysisChange, AnalysisHost, FeatureFlags}; 9use ra_ide::{AnalysisChange, AnalysisHost, FeatureFlags};
8use ra_project_model::{get_rustc_cfg_options, PackageRoot, ProjectWorkspace}; 10use ra_project_model::{get_rustc_cfg_options, PackageRoot, ProjectWorkspace};
9use ra_vfs::{RootEntry, Vfs, VfsChange, VfsTask, Watch}; 11use ra_vfs::{RootEntry, Vfs, VfsChange, VfsTask, Watch};
10use rustc_hash::FxHashMap; 12use rustc_hash::{FxHashMap, FxHashSet};
11 13
12use crate::vfs_glob::RustPackageFilterBuilder; 14use crate::vfs_glob::RustPackageFilterBuilder;
13 15
14use anyhow::Result;
15
16fn vfs_file_to_id(f: ra_vfs::VfsFile) -> FileId { 16fn vfs_file_to_id(f: ra_vfs::VfsFile) -> FileId {
17 FileId(f.0) 17 FileId(f.0)
18} 18}
@@ -20,7 +20,9 @@ fn vfs_root_to_id(r: ra_vfs::VfsRoot) -> SourceRootId {
20 SourceRootId(r.0) 20 SourceRootId(r.0)
21} 21}
22 22
23pub fn load_cargo(root: &Path) -> Result<(AnalysisHost, FxHashMap<SourceRootId, PackageRoot>)> { 23pub(crate) fn load_cargo(
24 root: &Path,
25) -> Result<(AnalysisHost, FxHashMap<SourceRootId, PackageRoot>)> {
24 let root = std::env::current_dir()?.join(root); 26 let root = std::env::current_dir()?.join(root);
25 let ws = ProjectWorkspace::discover(root.as_ref(), &Default::default())?; 27 let ws = ProjectWorkspace::discover(root.as_ref(), &Default::default())?;
26 let project_roots = ws.to_roots(); 28 let project_roots = ws.to_roots();
@@ -74,7 +76,7 @@ pub fn load_cargo(root: &Path) -> Result<(AnalysisHost, FxHashMap<SourceRootId,
74 Ok((host, source_roots)) 76 Ok((host, source_roots))
75} 77}
76 78
77pub fn load( 79pub(crate) fn load(
78 source_roots: &FxHashMap<SourceRootId, PackageRoot>, 80 source_roots: &FxHashMap<SourceRootId, PackageRoot>,
79 crate_graph: CrateGraph, 81 crate_graph: CrateGraph,
80 vfs: &mut Vfs, 82 vfs: &mut Vfs,
@@ -86,7 +88,7 @@ pub fn load(
86 analysis_change.set_crate_graph(crate_graph); 88 analysis_change.set_crate_graph(crate_graph);
87 89
88 // wait until Vfs has loaded all roots 90 // wait until Vfs has loaded all roots
89 let mut roots_loaded = HashSet::new(); 91 let mut roots_loaded = FxHashSet::default();
90 for task in receiver { 92 for task in receiver {
91 vfs.handle_task(task); 93 vfs.handle_task(task);
92 let mut done = false; 94 let mut done = false;
diff --git a/crates/ra_lsp_server/src/cli/progress_report.rs b/crates/rust-analyzer/src/cli/progress_report.rs
index 31867a1e9..31867a1e9 100644
--- a/crates/ra_lsp_server/src/cli/progress_report.rs
+++ b/crates/rust-analyzer/src/cli/progress_report.rs
diff --git a/crates/ra_lsp_server/src/config.rs b/crates/rust-analyzer/src/config.rs
index 3314269ec..3314269ec 100644
--- a/crates/ra_lsp_server/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/rust-analyzer/src/conv.rs
index 8af74b211..90ef74056 100644
--- a/crates/ra_lsp_server/src/conv.rs
+++ b/crates/rust-analyzer/src/conv.rs
@@ -1,4 +1,5 @@
1//! Convenience module responsible for translating between rust-analyzer's types and LSP types. 1//! Convenience module responsible for translating between rust-analyzer's types
2//! and LSP types.
2 3
3use lsp_types::{ 4use lsp_types::{
4 self, CreateFile, DiagnosticSeverity, DocumentChangeOperation, DocumentChanges, Documentation, 5 self, CreateFile, DiagnosticSeverity, DocumentChangeOperation, DocumentChanges, Documentation,
diff --git a/crates/ra_lsp_server/src/diagnostics.rs b/crates/rust-analyzer/src/diagnostics.rs
index ea08bce24..e7924f0a3 100644
--- a/crates/ra_lsp_server/src/diagnostics.rs
+++ b/crates/rust-analyzer/src/diagnostics.rs
@@ -1,7 +1,9 @@
1//! Book keeping for keeping diagnostics easily in sync with the client. 1//! Book keeping for keeping diagnostics easily in sync with the client.
2
3use std::{collections::HashMap, sync::Arc};
4
2use lsp_types::{CodeActionOrCommand, Diagnostic, Range}; 5use lsp_types::{CodeActionOrCommand, Diagnostic, Range};
3use ra_ide::FileId; 6use ra_ide::FileId;
4use std::{collections::HashMap, sync::Arc};
5 7
6pub type CheckFixes = Arc<HashMap<FileId, Vec<Fix>>>; 8pub type CheckFixes = Arc<HashMap<FileId, Vec<Fix>>>;
7 9
diff --git a/crates/ra_lsp_server/src/lib.rs b/crates/rust-analyzer/src/lib.rs
index 958c70fe5..0dae30e46 100644
--- a/crates/ra_lsp_server/src/lib.rs
+++ b/crates/rust-analyzer/src/lib.rs
@@ -1,10 +1,13 @@
1//! Implementation of the LSP for rust-analyzer. 1//! Implementation of the LSP for rust-analyzer.
2//! 2//!
3//! This crate takes Rust-specific analysis results from ra_ide and 3//! This crate takes Rust-specific analysis results from ra_ide and translates
4//! translates into LSP types. 4//! into LSP types.
5//! 5//!
6//! It also is the root of all state. `world` module defines the bulk of the 6//! It also is the root of all state. `world` module defines the bulk of the
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//!
9//! The `cli` submodule implements some batch-processing analysis, primarily as
10//! a debugging aid.
8#![recursion_limit = "512"] 11#![recursion_limit = "512"]
9 12
10pub mod cli; 13pub mod cli;
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index 944074118..dc16a234d 100644
--- a/crates/ra_lsp_server/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -1,5 +1,5 @@
1//! The main loop of `ra_lsp_server` responsible for dispatching LSP requests/replies and 1//! The main loop of `rust-analyzer` responsible for dispatching LSP
2//! notifications back to the client. 2//! requests/replies and notifications back to the client.
3 3
4mod handlers; 4mod handlers;
5mod subscriptions; 5mod subscriptions;
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/rust-analyzer/src/main_loop/handlers.rs
index ae51141cb..bb7bab372 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/rust-analyzer/src/main_loop/handlers.rs
@@ -1,5 +1,6 @@
1//! This module is responsible for implementing handlers for Lanuage Server Protocol. 1//! This module is responsible for implementing handlers for Language Server
2//! The majority of requests are fulfilled by calling into the `ra_ide` crate. 2//! Protocol. The majority of requests are fulfilled by calling into the
3//! `ra_ide` crate.
3 4
4use std::{ 5use std::{
5 collections::hash_map::Entry, 6 collections::hash_map::Entry,
@@ -29,7 +30,7 @@ use serde::{Deserialize, Serialize};
29use serde_json::to_value; 30use serde_json::to_value;
30 31
31use crate::{ 32use crate::{
32 cargo_target_spec::{runnable_args, CargoTargetSpec}, 33 cargo_target_spec::CargoTargetSpec,
33 conv::{ 34 conv::{
34 to_call_hierarchy_item, to_location, Conv, ConvWith, FoldConvCtx, MapConvWith, TryConvWith, 35 to_call_hierarchy_item, to_location, Conv, ConvWith, FoldConvCtx, MapConvWith, TryConvWith,
35 TryConvWithToVec, 36 TryConvWithToVec,
@@ -921,7 +922,8 @@ fn to_lsp_runnable(
921 file_id: FileId, 922 file_id: FileId,
922 runnable: Runnable, 923 runnable: Runnable,
923) -> Result<req::Runnable> { 924) -> Result<req::Runnable> {
924 let args = runnable_args(world, file_id, &runnable.kind)?; 925 let spec = CargoTargetSpec::for_file(world, file_id)?;
926 let args = CargoTargetSpec::runnable_args(spec, &runnable.kind)?;
925 let line_index = world.analysis().file_line_index(file_id)?; 927 let line_index = world.analysis().file_line_index(file_id)?;
926 let label = match &runnable.kind { 928 let label = match &runnable.kind {
927 RunnableKind::Test { test_id } => format!("test {}", test_id), 929 RunnableKind::Test { test_id } => format!("test {}", test_id),
diff --git a/crates/ra_lsp_server/src/main_loop/pending_requests.rs b/crates/rust-analyzer/src/main_loop/pending_requests.rs
index 2d2213464..73b33e419 100644
--- a/crates/ra_lsp_server/src/main_loop/pending_requests.rs
+++ b/crates/rust-analyzer/src/main_loop/pending_requests.rs
@@ -1,4 +1,4 @@
1//! Datastructures that keep track of inflight requests. 1//! Data structures that keep track of inflight requests.
2 2
3use std::time::{Duration, Instant}; 3use std::time::{Duration, Instant};
4 4
diff --git a/crates/ra_lsp_server/src/main_loop/subscriptions.rs b/crates/rust-analyzer/src/main_loop/subscriptions.rs
index b0bae90f5..bee6437cf 100644
--- a/crates/ra_lsp_server/src/main_loop/subscriptions.rs
+++ b/crates/rust-analyzer/src/main_loop/subscriptions.rs
@@ -1,4 +1,5 @@
1//! Keeps track of file subscriptions. 1//! Keeps track of file subscriptions -- the set of currently opened files for
2//! which we want to publish diagnostics, syntax highlighting, etc.
2 3
3use ra_ide::FileId; 4use ra_ide::FileId;
4use rustc_hash::FxHashSet; 5use rustc_hash::FxHashSet;
diff --git a/crates/ra_lsp_server/src/markdown.rs b/crates/rust-analyzer/src/markdown.rs
index 76bef45cc..76bef45cc 100644
--- a/crates/ra_lsp_server/src/markdown.rs
+++ b/crates/rust-analyzer/src/markdown.rs
diff --git a/crates/ra_lsp_server/src/req.rs b/crates/rust-analyzer/src/req.rs
index 7ff7f60b3..7ff7f60b3 100644
--- a/crates/ra_lsp_server/src/req.rs
+++ b/crates/rust-analyzer/src/req.rs
diff --git a/crates/ra_lsp_server/src/vfs_glob.rs b/crates/rust-analyzer/src/vfs_glob.rs
index 12401d75a..91b33f94e 100644
--- a/crates/ra_lsp_server/src/vfs_glob.rs
+++ b/crates/rust-analyzer/src/vfs_glob.rs
@@ -1,4 +1,4 @@
1//! `ra_vfs_glob` crate implements exclusion rules for vfs. 1//! Exclusion rules for vfs.
2//! 2//!
3//! By default, we include only `.rs` files, and skip some know offenders like 3//! By default, we include only `.rs` files, and skip some know offenders like
4//! `/target` or `/node_modules` altogether. 4//! `/target` or `/node_modules` altogether.
diff --git a/crates/ra_lsp_server/src/world.rs b/crates/rust-analyzer/src/world.rs
index 71c95d4af..96efab844 100644
--- a/crates/ra_lsp_server/src/world.rs
+++ b/crates/rust-analyzer/src/world.rs
@@ -1,5 +1,5 @@
1//! The context or environment in which the language server functions. 1//! The context or environment in which the language server functions. In our
2//! In our server implementation this is know as the `WorldState`. 2//! server implementation this is know as the `WorldState`.
3//! 3//!
4//! Each tick provides an immutable snapshot of the state as `WorldSnapshot`. 4//! Each tick provides an immutable snapshot of the state as `WorldSnapshot`.
5 5
diff --git a/crates/ra_lsp_server/tests/heavy_tests/main.rs b/crates/rust-analyzer/tests/heavy_tests/main.rs
index 9ca31cbcc..3af63d9cf 100644
--- a/crates/ra_lsp_server/tests/heavy_tests/main.rs
+++ b/crates/rust-analyzer/tests/heavy_tests/main.rs
@@ -7,7 +7,7 @@ use lsp_types::{
7 PartialResultParams, Position, Range, TextDocumentItem, TextDocumentPositionParams, 7 PartialResultParams, Position, Range, TextDocumentItem, TextDocumentPositionParams,
8 WorkDoneProgressParams, 8 WorkDoneProgressParams,
9}; 9};
10use ra_lsp_server::req::{ 10use rust_analyzer::req::{
11 CodeActionParams, CodeActionRequest, Completion, CompletionParams, DidOpenTextDocument, 11 CodeActionParams, CodeActionRequest, Completion, CompletionParams, DidOpenTextDocument,
12 Formatting, OnEnter, Runnables, RunnablesParams, 12 Formatting, OnEnter, Runnables, RunnablesParams,
13}; 13};
diff --git a/crates/ra_lsp_server/tests/heavy_tests/support.rs b/crates/rust-analyzer/tests/heavy_tests/support.rs
index d5ea52fa9..5b90b3218 100644
--- a/crates/ra_lsp_server/tests/heavy_tests/support.rs
+++ b/crates/rust-analyzer/tests/heavy_tests/support.rs
@@ -19,7 +19,7 @@ use serde_json::{to_string_pretty, Value};
19use tempfile::TempDir; 19use tempfile::TempDir;
20use test_utils::{find_mismatch, parse_fixture}; 20use test_utils::{find_mismatch, parse_fixture};
21 21
22use ra_lsp_server::{main_loop, req, ServerConfig}; 22use rust_analyzer::{main_loop, req, ServerConfig};
23 23
24pub struct Project<'a> { 24pub struct Project<'a> {
25 fixture: &'a str, 25 fixture: &'a str,