aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/src
diff options
context:
space:
mode:
authorEmil Lauridsen <[email protected]>2019-12-25 15:50:38 +0000
committerEmil Lauridsen <[email protected]>2019-12-25 16:37:40 +0000
commit6af4bf7a8d27e653d2e6316172fe140871054d27 (patch)
treeb1a3eed872b7659eb5400e5f2e117a0d008052f9 /crates/ra_lsp_server/src
parent41a1ec723ce2ea3fa78ae468830f0a77e5658307 (diff)
Configuration plumbing for cargo watcher
Diffstat (limited to 'crates/ra_lsp_server/src')
-rw-r--r--crates/ra_lsp_server/src/cargo_check.rs50
-rw-r--r--crates/ra_lsp_server/src/config.rs7
-rw-r--r--crates/ra_lsp_server/src/main_loop.rs3
-rw-r--r--crates/ra_lsp_server/src/world.rs5
4 files changed, 55 insertions, 10 deletions
diff --git a/crates/ra_lsp_server/src/cargo_check.rs b/crates/ra_lsp_server/src/cargo_check.rs
index d5ff02154..f98b4f69c 100644
--- a/crates/ra_lsp_server/src/cargo_check.rs
+++ b/crates/ra_lsp_server/src/cargo_check.rs
@@ -1,3 +1,4 @@
1use crate::world::Options;
1use cargo_metadata::{ 2use cargo_metadata::{
2 diagnostic::{ 3 diagnostic::{
3 Applicability, Diagnostic as RustDiagnostic, DiagnosticLevel, DiagnosticSpan, 4 Applicability, Diagnostic as RustDiagnostic, DiagnosticLevel, DiagnosticSpan,
@@ -30,14 +31,17 @@ pub struct CheckWatcher {
30} 31}
31 32
32impl CheckWatcher { 33impl CheckWatcher {
33 pub fn new(workspace_root: PathBuf) -> CheckWatcher { 34 pub fn new(options: &Options, workspace_root: PathBuf) -> CheckWatcher {
35 let check_command = options.cargo_check_command.clone();
36 let check_args = options.cargo_check_args.clone();
34 let shared = Arc::new(RwLock::new(CheckWatcherSharedState::new())); 37 let shared = Arc::new(RwLock::new(CheckWatcherSharedState::new()));
35 38
36 let (task_send, task_recv) = unbounded::<CheckTask>(); 39 let (task_send, task_recv) = unbounded::<CheckTask>();
37 let (cmd_send, cmd_recv) = unbounded::<CheckCommand>(); 40 let (cmd_send, cmd_recv) = unbounded::<CheckCommand>();
38 let shared_ = shared.clone(); 41 let shared_ = shared.clone();
39 let handle = std::thread::spawn(move || { 42 let handle = std::thread::spawn(move || {
40 let mut check = CheckWatcherState::new(shared_, workspace_root); 43 let mut check =
44 CheckWatcherState::new(check_command, check_args, workspace_root, shared_);
41 check.run(&task_send, &cmd_recv); 45 check.run(&task_send, &cmd_recv);
42 }); 46 });
43 47
@@ -50,6 +54,8 @@ impl CheckWatcher {
50} 54}
51 55
52pub struct CheckWatcherState { 56pub struct CheckWatcherState {
57 check_command: Option<String>,
58 check_args: Vec<String>,
53 workspace_root: PathBuf, 59 workspace_root: PathBuf,
54 running: bool, 60 running: bool,
55 watcher: WatchThread, 61 watcher: WatchThread,
@@ -134,11 +140,21 @@ pub enum CheckCommand {
134 140
135impl CheckWatcherState { 141impl CheckWatcherState {
136 pub fn new( 142 pub fn new(
137 shared: Arc<RwLock<CheckWatcherSharedState>>, 143 check_command: Option<String>,
144 check_args: Vec<String>,
138 workspace_root: PathBuf, 145 workspace_root: PathBuf,
146 shared: Arc<RwLock<CheckWatcherSharedState>>,
139 ) -> CheckWatcherState { 147 ) -> CheckWatcherState {
140 let watcher = WatchThread::new(&workspace_root); 148 let watcher = WatchThread::new(check_command.as_ref(), &check_args, &workspace_root);
141 CheckWatcherState { workspace_root, running: false, watcher, last_update_req: None, shared } 149 CheckWatcherState {
150 check_command,
151 check_args,
152 workspace_root,
153 running: false,
154 watcher,
155 last_update_req: None,
156 shared,
157 }
142 } 158 }
143 159
144 pub fn run(&mut self, task_send: &Sender<CheckTask>, cmd_recv: &Receiver<CheckCommand>) { 160 pub fn run(&mut self, task_send: &Sender<CheckTask>, cmd_recv: &Receiver<CheckCommand>) {
@@ -163,7 +179,11 @@ impl CheckWatcherState {
163 self.shared.write().clear(task_send); 179 self.shared.write().clear(task_send);
164 180
165 self.watcher.cancel(); 181 self.watcher.cancel();
166 self.watcher = WatchThread::new(&self.workspace_root); 182 self.watcher = WatchThread::new(
183 self.check_command.as_ref(),
184 &self.check_args,
185 &self.workspace_root,
186 );
167 } 187 }
168 } 188 }
169 } 189 }
@@ -229,13 +249,25 @@ struct WatchThread {
229} 249}
230 250
231impl WatchThread { 251impl WatchThread {
232 fn new(workspace_root: &PathBuf) -> WatchThread { 252 fn new(
233 let manifest_path = format!("{}/Cargo.toml", workspace_root.to_string_lossy()); 253 check_command: Option<&String>,
254 check_args: &[String],
255 workspace_root: &PathBuf,
256 ) -> WatchThread {
257 let check_command = check_command.cloned().unwrap_or("check".to_string());
258 let mut args: Vec<String> = vec![
259 check_command,
260 "--message-format=json".to_string(),
261 "--manifest-path".to_string(),
262 format!("{}/Cargo.toml", workspace_root.to_string_lossy()),
263 ];
264 args.extend(check_args.iter().cloned());
265
234 let (message_send, message_recv) = unbounded(); 266 let (message_send, message_recv) = unbounded();
235 let (cancel_send, cancel_recv) = unbounded(); 267 let (cancel_send, cancel_recv) = unbounded();
236 std::thread::spawn(move || { 268 std::thread::spawn(move || {
237 let mut command = Command::new("cargo") 269 let mut command = Command::new("cargo")
238 .args(&["check", "--message-format=json", "--manifest-path", &manifest_path]) 270 .args(&args)
239 .stdout(Stdio::piped()) 271 .stdout(Stdio::piped())
240 .stderr(Stdio::null()) 272 .stderr(Stdio::null())
241 .spawn() 273 .spawn()
diff --git a/crates/ra_lsp_server/src/config.rs b/crates/ra_lsp_server/src/config.rs
index 67942aa41..621f2238c 100644
--- a/crates/ra_lsp_server/src/config.rs
+++ b/crates/ra_lsp_server/src/config.rs
@@ -32,6 +32,10 @@ pub struct ServerConfig {
32 32
33 pub max_inlay_hint_length: Option<usize>, 33 pub max_inlay_hint_length: Option<usize>,
34 34
35 pub cargo_check_enable: bool,
36 pub cargo_check_command: Option<String>,
37 pub cargo_check_args: Vec<String>,
38
35 /// For internal usage to make integrated tests faster. 39 /// For internal usage to make integrated tests faster.
36 #[serde(deserialize_with = "nullable_bool_true")] 40 #[serde(deserialize_with = "nullable_bool_true")]
37 pub with_sysroot: bool, 41 pub with_sysroot: bool,
@@ -51,6 +55,9 @@ impl Default for ServerConfig {
51 use_client_watching: false, 55 use_client_watching: false,
52 lru_capacity: None, 56 lru_capacity: None,
53 max_inlay_hint_length: None, 57 max_inlay_hint_length: None,
58 cargo_check_enable: true,
59 cargo_check_command: None,
60 cargo_check_args: vec![],
54 with_sysroot: true, 61 with_sysroot: true,
55 feature_flags: FxHashMap::default(), 62 feature_flags: FxHashMap::default(),
56 cargo_features: Default::default(), 63 cargo_features: Default::default(),
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs
index 943d38943..1f6175699 100644
--- a/crates/ra_lsp_server/src/main_loop.rs
+++ b/crates/ra_lsp_server/src/main_loop.rs
@@ -127,6 +127,9 @@ pub fn main_loop(
127 .and_then(|it| it.line_folding_only) 127 .and_then(|it| it.line_folding_only)
128 .unwrap_or(false), 128 .unwrap_or(false),
129 max_inlay_hint_length: config.max_inlay_hint_length, 129 max_inlay_hint_length: config.max_inlay_hint_length,
130 cargo_check_enable: config.cargo_check_enable,
131 cargo_check_command: config.cargo_check_command,
132 cargo_check_args: config.cargo_check_args,
130 } 133 }
131 }; 134 };
132 135
diff --git a/crates/ra_lsp_server/src/world.rs b/crates/ra_lsp_server/src/world.rs
index 8e9380ca0..235eb199d 100644
--- a/crates/ra_lsp_server/src/world.rs
+++ b/crates/ra_lsp_server/src/world.rs
@@ -35,6 +35,9 @@ pub struct Options {
35 pub supports_location_link: bool, 35 pub supports_location_link: bool,
36 pub line_folding_only: bool, 36 pub line_folding_only: bool,
37 pub max_inlay_hint_length: Option<usize>, 37 pub max_inlay_hint_length: Option<usize>,
38 pub cargo_check_enable: bool,
39 pub cargo_check_command: Option<String>,
40 pub cargo_check_args: Vec<String>,
38} 41}
39 42
40/// `WorldState` is the primary mutable state of the language server 43/// `WorldState` is the primary mutable state of the language server
@@ -131,7 +134,7 @@ impl WorldState {
131 change.set_crate_graph(crate_graph); 134 change.set_crate_graph(crate_graph);
132 135
133 // FIXME: Figure out the multi-workspace situation 136 // FIXME: Figure out the multi-workspace situation
134 let check_watcher = CheckWatcher::new(folder_roots.first().cloned().unwrap()); 137 let check_watcher = CheckWatcher::new(&options, folder_roots.first().cloned().unwrap());
135 138
136 let mut analysis_host = AnalysisHost::new(lru_capacity, feature_flags); 139 let mut analysis_host = AnalysisHost::new(lru_capacity, feature_flags);
137 analysis_host.apply_change(change); 140 analysis_host.apply_change(change);