aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
-rw-r--r--editors/code/package.json40
-rw-r--r--editors/code/src/config.ts59
-rw-r--r--editors/code/src/server.ts3
7 files changed, 83 insertions, 84 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);
diff --git a/editors/code/package.json b/editors/code/package.json
index 6cb24a3ce..5f4123397 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -188,20 +188,10 @@
188 "default": "ra_lsp_server", 188 "default": "ra_lsp_server",
189 "description": "Path to ra_lsp_server executable" 189 "description": "Path to ra_lsp_server executable"
190 }, 190 },
191 "rust-analyzer.enableCargoWatchOnStartup": { 191 "rust-analyzer.enableCargoCheck": {
192 "type": "string", 192 "type": "boolean",
193 "default": "ask", 193 "default": true,
194 "enum": [ 194 "description": "Run `cargo check` for diagnostics on save"
195 "ask",
196 "enabled",
197 "disabled"
198 ],
199 "enumDescriptions": [
200 "Asks each time whether to run `cargo watch`",
201 "`cargo watch` is always started",
202 "Don't start `cargo watch`"
203 ],
204 "description": "Whether to run `cargo watch` on startup"
205 }, 195 },
206 "rust-analyzer.excludeGlobs": { 196 "rust-analyzer.excludeGlobs": {
207 "type": "array", 197 "type": "array",
@@ -213,25 +203,15 @@
213 "default": true, 203 "default": true,
214 "description": "client provided file watching instead of notify watching." 204 "description": "client provided file watching instead of notify watching."
215 }, 205 },
216 "rust-analyzer.cargo-watch.arguments": { 206 "rust-analyzer.cargo-check.arguments": {
217 "type": "string",
218 "description": "`cargo-watch` arguments. (e.g: `--features=\"shumway,pdf\"` will run as `cargo watch -x \"check --features=\"shumway,pdf\"\"` )",
219 "default": ""
220 },
221 "rust-analyzer.cargo-watch.command": {
222 "type": "string",
223 "description": "`cargo-watch` command. (e.g: `clippy` will run as `cargo watch -x clippy` )",
224 "default": "check"
225 },
226 "rust-analyzer.cargo-watch.ignore": {
227 "type": "array", 207 "type": "array",
228 "description": "A list of patterns for cargo-watch to ignore (will be passed as `--ignore`)", 208 "description": "`cargo-check` arguments. (e.g: `--features=\"shumway,pdf\"` will run as `cargo check --features=\"shumway,pdf\"` )",
229 "default": [] 209 "default": []
230 }, 210 },
231 "rust-analyzer.cargo-watch.allTargets": { 211 "rust-analyzer.cargo-check.command": {
232 "type": "boolean", 212 "type": "string",
233 "description": "Check all targets and tests (will be passed as `--all-targets`)", 213 "description": "`cargo-check` command. (e.g: `clippy` will run as `cargo clippy` )",
234 "default": true 214 "default": "check"
235 }, 215 },
236 "rust-analyzer.trace.server": { 216 "rust-analyzer.trace.server": {
237 "type": "string", 217 "type": "string",
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts
index e131f09df..96532e2c9 100644
--- a/editors/code/src/config.ts
+++ b/editors/code/src/config.ts
@@ -4,16 +4,10 @@ import { Server } from './server';
4 4
5const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG; 5const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG;
6 6
7export type CargoWatchStartupOptions = 'ask' | 'enabled' | 'disabled'; 7export interface CargoCheckOptions {
8export type CargoWatchTraceOptions = 'off' | 'error' | 'verbose'; 8 enabled: boolean;
9 9 arguments: string[];
10export interface CargoWatchOptions { 10 command: null | string;
11 enableOnStartup: CargoWatchStartupOptions;
12 arguments: string;
13 command: string;
14 trace: CargoWatchTraceOptions;
15 ignore: string[];
16 allTargets: boolean;
17} 11}
18 12
19export interface CargoFeatures { 13export interface CargoFeatures {
@@ -35,13 +29,10 @@ export class Config {
35 public featureFlags = {}; 29 public featureFlags = {};
36 // for internal use 30 // for internal use
37 public withSysroot: null | boolean = null; 31 public withSysroot: null | boolean = null;
38 public cargoWatchOptions: CargoWatchOptions = { 32 public cargoCheckOptions: CargoCheckOptions = {
39 enableOnStartup: 'ask', 33 enabled: true,
40 trace: 'off', 34 arguments: [],
41 arguments: '', 35 command: null,
42 command: '',
43 ignore: [],
44 allTargets: true,
45 }; 36 };
46 public cargoFeatures: CargoFeatures = { 37 public cargoFeatures: CargoFeatures = {
47 noDefaultFeatures: false, 38 noDefaultFeatures: false,
@@ -100,47 +91,27 @@ export class Config {
100 RA_LSP_DEBUG || (config.get('raLspServerPath') as string); 91 RA_LSP_DEBUG || (config.get('raLspServerPath') as string);
101 } 92 }
102 93
103 if (config.has('enableCargoWatchOnStartup')) { 94 if (config.has('enableCargoCheck')) {
104 this.cargoWatchOptions.enableOnStartup = config.get< 95 this.cargoCheckOptions.enabled = config.get<boolean>(
105 CargoWatchStartupOptions 96 'enableCargoCheck',
106 >('enableCargoWatchOnStartup', 'ask'); 97 true,
107 }
108
109 if (config.has('trace.cargo-watch')) {
110 this.cargoWatchOptions.trace = config.get<CargoWatchTraceOptions>(
111 'trace.cargo-watch',
112 'off',
113 ); 98 );
114 } 99 }
115 100
116 if (config.has('cargo-watch.arguments')) { 101 if (config.has('cargo-watch.arguments')) {
117 this.cargoWatchOptions.arguments = config.get<string>( 102 this.cargoCheckOptions.arguments = config.get<string[]>(
118 'cargo-watch.arguments', 103 'cargo-watch.arguments',
119 '', 104 [],
120 ); 105 );
121 } 106 }
122 107
123 if (config.has('cargo-watch.command')) { 108 if (config.has('cargo-watch.command')) {
124 this.cargoWatchOptions.command = config.get<string>( 109 this.cargoCheckOptions.command = config.get<string>(
125 'cargo-watch.command', 110 'cargo-watch.command',
126 '', 111 '',
127 ); 112 );
128 } 113 }
129 114
130 if (config.has('cargo-watch.ignore')) {
131 this.cargoWatchOptions.ignore = config.get<string[]>(
132 'cargo-watch.ignore',
133 [],
134 );
135 }
136
137 if (config.has('cargo-watch.allTargets')) {
138 this.cargoWatchOptions.allTargets = config.get<boolean>(
139 'cargo-watch.allTargets',
140 true,
141 );
142 }
143
144 if (config.has('lruCapacity')) { 115 if (config.has('lruCapacity')) {
145 this.lruCapacity = config.get('lruCapacity') as number; 116 this.lruCapacity = config.get('lruCapacity') as number;
146 } 117 }
diff --git a/editors/code/src/server.ts b/editors/code/src/server.ts
index 5ace1d0fa..409d3b4b7 100644
--- a/editors/code/src/server.ts
+++ b/editors/code/src/server.ts
@@ -55,6 +55,9 @@ export class Server {
55 publishDecorations: true, 55 publishDecorations: true,
56 lruCapacity: Server.config.lruCapacity, 56 lruCapacity: Server.config.lruCapacity,
57 maxInlayHintLength: Server.config.maxInlayHintLength, 57 maxInlayHintLength: Server.config.maxInlayHintLength,
58 cargoCheckEnable: Server.config.cargoCheckOptions.enabled,
59 cargoCheckCommand: Server.config.cargoCheckOptions.command,
60 cargoCheckArgs: Server.config.cargoCheckOptions.arguments,
58 excludeGlobs: Server.config.excludeGlobs, 61 excludeGlobs: Server.config.excludeGlobs,
59 useClientWatching: Server.config.useClientWatching, 62 useClientWatching: Server.config.useClientWatching,
60 featureFlags: Server.config.featureFlags, 63 featureFlags: Server.config.featureFlags,