diff options
-rw-r--r-- | crates/ra_lsp_server/src/cargo_check.rs | 52 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/config.rs | 14 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop.rs | 7 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/world.rs | 7 | ||||
-rw-r--r-- | editors/code/package.json | 34 | ||||
-rw-r--r-- | editors/code/src/config.ts | 31 | ||||
-rw-r--r-- | editors/code/src/extension.ts | 2 | ||||
-rw-r--r-- | editors/code/src/server.ts | 8 |
8 files changed, 71 insertions, 84 deletions
diff --git a/crates/ra_lsp_server/src/cargo_check.rs b/crates/ra_lsp_server/src/cargo_check.rs index fa0409ee0..70c723b19 100644 --- a/crates/ra_lsp_server/src/cargo_check.rs +++ b/crates/ra_lsp_server/src/cargo_check.rs | |||
@@ -39,22 +39,14 @@ pub struct CheckWatcher { | |||
39 | 39 | ||
40 | impl CheckWatcher { | 40 | impl CheckWatcher { |
41 | pub fn new(options: &Options, workspace_root: PathBuf) -> CheckWatcher { | 41 | pub fn new(options: &Options, workspace_root: PathBuf) -> CheckWatcher { |
42 | let check_enabled = options.cargo_check_enable; | 42 | let options = options.clone(); |
43 | let check_command = options.cargo_check_command.clone(); | ||
44 | let check_args = options.cargo_check_args.clone(); | ||
45 | let shared = Arc::new(RwLock::new(CheckWatcherSharedState::new())); | 43 | let shared = Arc::new(RwLock::new(CheckWatcherSharedState::new())); |
46 | 44 | ||
47 | let (task_send, task_recv) = unbounded::<CheckTask>(); | 45 | let (task_send, task_recv) = unbounded::<CheckTask>(); |
48 | let (cmd_send, cmd_recv) = unbounded::<CheckCommand>(); | 46 | let (cmd_send, cmd_recv) = unbounded::<CheckCommand>(); |
49 | let shared_ = shared.clone(); | 47 | let shared_ = shared.clone(); |
50 | let handle = std::thread::spawn(move || { | 48 | let handle = std::thread::spawn(move || { |
51 | let mut check = CheckWatcherState::new( | 49 | let mut check = CheckWatcherState::new(options, workspace_root, shared_); |
52 | check_enabled, | ||
53 | check_command, | ||
54 | check_args, | ||
55 | workspace_root, | ||
56 | shared_, | ||
57 | ); | ||
58 | check.run(&task_send, &cmd_recv); | 50 | check.run(&task_send, &cmd_recv); |
59 | }); | 51 | }); |
60 | 52 | ||
@@ -68,9 +60,7 @@ impl CheckWatcher { | |||
68 | } | 60 | } |
69 | 61 | ||
70 | pub struct CheckWatcherState { | 62 | pub struct CheckWatcherState { |
71 | check_enabled: bool, | 63 | options: Options, |
72 | check_command: Option<String>, | ||
73 | check_args: Vec<String>, | ||
74 | workspace_root: PathBuf, | 64 | workspace_root: PathBuf, |
75 | running: bool, | 65 | running: bool, |
76 | watcher: WatchThread, | 66 | watcher: WatchThread, |
@@ -162,18 +152,13 @@ pub enum CheckCommand { | |||
162 | 152 | ||
163 | impl CheckWatcherState { | 153 | impl CheckWatcherState { |
164 | pub fn new( | 154 | pub fn new( |
165 | check_enabled: bool, | 155 | options: Options, |
166 | check_command: Option<String>, | ||
167 | check_args: Vec<String>, | ||
168 | workspace_root: PathBuf, | 156 | workspace_root: PathBuf, |
169 | shared: Arc<RwLock<CheckWatcherSharedState>>, | 157 | shared: Arc<RwLock<CheckWatcherSharedState>>, |
170 | ) -> CheckWatcherState { | 158 | ) -> CheckWatcherState { |
171 | let watcher = | 159 | let watcher = WatchThread::new(&options, &workspace_root); |
172 | WatchThread::new(check_enabled, check_command.as_ref(), &check_args, &workspace_root); | ||
173 | CheckWatcherState { | 160 | CheckWatcherState { |
174 | check_enabled, | 161 | options, |
175 | check_command, | ||
176 | check_args, | ||
177 | workspace_root, | 162 | workspace_root, |
178 | running: false, | 163 | running: false, |
179 | watcher, | 164 | watcher, |
@@ -204,12 +189,7 @@ impl CheckWatcherState { | |||
204 | self.shared.write().clear(task_send); | 189 | self.shared.write().clear(task_send); |
205 | 190 | ||
206 | self.watcher.cancel(); | 191 | self.watcher.cancel(); |
207 | self.watcher = WatchThread::new( | 192 | self.watcher = WatchThread::new(&self.options, &self.workspace_root); |
208 | self.check_enabled, | ||
209 | self.check_command.as_ref(), | ||
210 | &self.check_args, | ||
211 | &self.workspace_root, | ||
212 | ); | ||
213 | } | 193 | } |
214 | } | 194 | } |
215 | } | 195 | } |
@@ -306,25 +286,23 @@ enum CheckEvent { | |||
306 | } | 286 | } |
307 | 287 | ||
308 | impl WatchThread { | 288 | impl WatchThread { |
309 | fn new( | 289 | fn new(options: &Options, workspace_root: &PathBuf) -> WatchThread { |
310 | check_enabled: bool, | ||
311 | check_command: Option<&String>, | ||
312 | check_args: &[String], | ||
313 | workspace_root: &PathBuf, | ||
314 | ) -> WatchThread { | ||
315 | let check_command = check_command.cloned().unwrap_or("check".to_string()); | ||
316 | let mut args: Vec<String> = vec![ | 290 | let mut args: Vec<String> = vec![ |
317 | check_command, | 291 | options.cargo_watch_command.clone(), |
318 | "--message-format=json".to_string(), | 292 | "--message-format=json".to_string(), |
319 | "--manifest-path".to_string(), | 293 | "--manifest-path".to_string(), |
320 | format!("{}/Cargo.toml", workspace_root.to_string_lossy()), | 294 | format!("{}/Cargo.toml", workspace_root.to_string_lossy()), |
321 | ]; | 295 | ]; |
322 | args.extend(check_args.iter().cloned()); | 296 | if options.cargo_watch_all_targets { |
297 | args.push("--all-targets".to_string()); | ||
298 | } | ||
299 | args.extend(options.cargo_watch_args.iter().cloned()); | ||
323 | 300 | ||
324 | let (message_send, message_recv) = unbounded(); | 301 | let (message_send, message_recv) = unbounded(); |
325 | let (cancel_send, cancel_recv) = unbounded(); | 302 | let (cancel_send, cancel_recv) = unbounded(); |
303 | let enabled = options.cargo_watch_enable; | ||
326 | std::thread::spawn(move || { | 304 | std::thread::spawn(move || { |
327 | if !check_enabled { | 305 | if !enabled { |
328 | return; | 306 | return; |
329 | } | 307 | } |
330 | 308 | ||
diff --git a/crates/ra_lsp_server/src/config.rs b/crates/ra_lsp_server/src/config.rs index 621f2238c..2d7948d74 100644 --- a/crates/ra_lsp_server/src/config.rs +++ b/crates/ra_lsp_server/src/config.rs | |||
@@ -32,9 +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, | 35 | pub cargo_watch_enable: bool, |
36 | pub cargo_check_command: Option<String>, | 36 | pub cargo_watch_args: Vec<String>, |
37 | pub cargo_check_args: Vec<String>, | 37 | pub cargo_watch_command: String, |
38 | pub cargo_watch_all_targets: bool, | ||
38 | 39 | ||
39 | /// For internal usage to make integrated tests faster. | 40 | /// For internal usage to make integrated tests faster. |
40 | #[serde(deserialize_with = "nullable_bool_true")] | 41 | #[serde(deserialize_with = "nullable_bool_true")] |
@@ -55,9 +56,10 @@ impl Default for ServerConfig { | |||
55 | use_client_watching: false, | 56 | use_client_watching: false, |
56 | lru_capacity: None, | 57 | lru_capacity: None, |
57 | max_inlay_hint_length: None, | 58 | max_inlay_hint_length: None, |
58 | cargo_check_enable: true, | 59 | cargo_watch_enable: true, |
59 | cargo_check_command: None, | 60 | cargo_watch_args: Vec::new(), |
60 | cargo_check_args: vec![], | 61 | cargo_watch_command: "check".to_string(), |
62 | cargo_watch_all_targets: true, | ||
61 | with_sysroot: true, | 63 | with_sysroot: true, |
62 | feature_flags: FxHashMap::default(), | 64 | feature_flags: FxHashMap::default(), |
63 | cargo_features: Default::default(), | 65 | 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 045e4660d..c58af7e47 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs | |||
@@ -127,9 +127,10 @@ 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, | 130 | cargo_watch_enable: config.cargo_watch_enable, |
131 | cargo_check_command: config.cargo_check_command, | 131 | cargo_watch_args: config.cargo_watch_args, |
132 | cargo_check_args: config.cargo_check_args, | 132 | cargo_watch_command: config.cargo_watch_command, |
133 | cargo_watch_all_targets: config.cargo_watch_all_targets, | ||
133 | } | 134 | } |
134 | }; | 135 | }; |
135 | 136 | ||
diff --git a/crates/ra_lsp_server/src/world.rs b/crates/ra_lsp_server/src/world.rs index 47c3823fb..39a07c01a 100644 --- a/crates/ra_lsp_server/src/world.rs +++ b/crates/ra_lsp_server/src/world.rs | |||
@@ -35,9 +35,10 @@ 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, | 38 | pub cargo_watch_enable: bool, |
39 | pub cargo_check_command: Option<String>, | 39 | pub cargo_watch_args: Vec<String>, |
40 | pub cargo_check_args: Vec<String>, | 40 | pub cargo_watch_command: String, |
41 | pub cargo_watch_all_targets: bool, | ||
41 | } | 42 | } |
42 | 43 | ||
43 | /// `WorldState` is the primary mutable state of the language server | 44 | /// `WorldState` is the primary mutable state of the language server |
diff --git a/editors/code/package.json b/editors/code/package.json index 5f4123397..69298e917 100644 --- a/editors/code/package.json +++ b/editors/code/package.json | |||
@@ -188,11 +188,6 @@ | |||
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.enableCargoCheck": { | ||
192 | "type": "boolean", | ||
193 | "default": true, | ||
194 | "description": "Run `cargo check` for diagnostics on save" | ||
195 | }, | ||
196 | "rust-analyzer.excludeGlobs": { | 191 | "rust-analyzer.excludeGlobs": { |
197 | "type": "array", | 192 | "type": "array", |
198 | "default": [], | 193 | "default": [], |
@@ -203,16 +198,26 @@ | |||
203 | "default": true, | 198 | "default": true, |
204 | "description": "client provided file watching instead of notify watching." | 199 | "description": "client provided file watching instead of notify watching." |
205 | }, | 200 | }, |
206 | "rust-analyzer.cargo-check.arguments": { | 201 | "rust-analyzer.cargo-watch.enable": { |
202 | "type": "boolean", | ||
203 | "default": true, | ||
204 | "description": "Run `cargo check` for diagnostics on save" | ||
205 | }, | ||
206 | "rust-analyzer.cargo-watch.arguments": { | ||
207 | "type": "array", | 207 | "type": "array", |
208 | "description": "`cargo-check` arguments. (e.g: `--features=\"shumway,pdf\"` will run as `cargo check --features=\"shumway,pdf\"` )", | 208 | "description": "`cargo-watch` arguments. (e.g: `--features=\"shumway,pdf\"` will run as `cargo watch -x \"check --features=\"shumway,pdf\"\"` )", |
209 | "default": [] | 209 | "default": [] |
210 | }, | 210 | }, |
211 | "rust-analyzer.cargo-check.command": { | 211 | "rust-analyzer.cargo-watch.command": { |
212 | "type": "string", | 212 | "type": "string", |
213 | "description": "`cargo-check` command. (e.g: `clippy` will run as `cargo clippy` )", | 213 | "description": "`cargo-watch` command. (e.g: `clippy` will run as `cargo watch -x clippy` )", |
214 | "default": "check" | 214 | "default": "check" |
215 | }, | 215 | }, |
216 | "rust-analyzer.cargo-watch.allTargets": { | ||
217 | "type": "boolean", | ||
218 | "description": "Check all targets and tests (will be passed as `--all-targets`)", | ||
219 | "default": true | ||
220 | }, | ||
216 | "rust-analyzer.trace.server": { | 221 | "rust-analyzer.trace.server": { |
217 | "type": "string", | 222 | "type": "string", |
218 | "scope": "window", | 223 | "scope": "window", |
@@ -229,17 +234,6 @@ | |||
229 | "default": "off", | 234 | "default": "off", |
230 | "description": "Trace requests to the ra_lsp_server" | 235 | "description": "Trace requests to the ra_lsp_server" |
231 | }, | 236 | }, |
232 | "rust-analyzer.trace.cargo-watch": { | ||
233 | "type": "string", | ||
234 | "scope": "window", | ||
235 | "enum": [ | ||
236 | "off", | ||
237 | "error", | ||
238 | "verbose" | ||
239 | ], | ||
240 | "default": "off", | ||
241 | "description": "Trace output of cargo-watch" | ||
242 | }, | ||
243 | "rust-analyzer.lruCapacity": { | 237 | "rust-analyzer.lruCapacity": { |
244 | "type": "number", | 238 | "type": "number", |
245 | "default": null, | 239 | "default": null, |
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index 96532e2c9..4b388b80c 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts | |||
@@ -4,10 +4,11 @@ import { Server } from './server'; | |||
4 | 4 | ||
5 | const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG; | 5 | const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG; |
6 | 6 | ||
7 | export interface CargoCheckOptions { | 7 | export interface CargoWatchOptions { |
8 | enabled: boolean; | 8 | enable: boolean; |
9 | arguments: string[]; | 9 | arguments: string[]; |
10 | command: null | string; | 10 | command: string; |
11 | allTargets: boolean; | ||
11 | } | 12 | } |
12 | 13 | ||
13 | export interface CargoFeatures { | 14 | export interface CargoFeatures { |
@@ -29,10 +30,11 @@ export class Config { | |||
29 | public featureFlags = {}; | 30 | public featureFlags = {}; |
30 | // for internal use | 31 | // for internal use |
31 | public withSysroot: null | boolean = null; | 32 | public withSysroot: null | boolean = null; |
32 | public cargoCheckOptions: CargoCheckOptions = { | 33 | public cargoWatchOptions: CargoWatchOptions = { |
33 | enabled: true, | 34 | enable: true, |
34 | arguments: [], | 35 | arguments: [], |
35 | command: null, | 36 | command: '', |
37 | allTargets: true, | ||
36 | }; | 38 | }; |
37 | public cargoFeatures: CargoFeatures = { | 39 | public cargoFeatures: CargoFeatures = { |
38 | noDefaultFeatures: false, | 40 | noDefaultFeatures: false, |
@@ -91,27 +93,34 @@ export class Config { | |||
91 | RA_LSP_DEBUG || (config.get('raLspServerPath') as string); | 93 | RA_LSP_DEBUG || (config.get('raLspServerPath') as string); |
92 | } | 94 | } |
93 | 95 | ||
94 | if (config.has('enableCargoCheck')) { | 96 | if (config.has('cargo-watch.enable')) { |
95 | this.cargoCheckOptions.enabled = config.get<boolean>( | 97 | this.cargoWatchOptions.enable = config.get<boolean>( |
96 | 'enableCargoCheck', | 98 | 'cargo-watch.enable', |
97 | true, | 99 | true, |
98 | ); | 100 | ); |
99 | } | 101 | } |
100 | 102 | ||
101 | if (config.has('cargo-watch.arguments')) { | 103 | if (config.has('cargo-watch.arguments')) { |
102 | this.cargoCheckOptions.arguments = config.get<string[]>( | 104 | this.cargoWatchOptions.arguments = config.get<string[]>( |
103 | 'cargo-watch.arguments', | 105 | 'cargo-watch.arguments', |
104 | [], | 106 | [], |
105 | ); | 107 | ); |
106 | } | 108 | } |
107 | 109 | ||
108 | if (config.has('cargo-watch.command')) { | 110 | if (config.has('cargo-watch.command')) { |
109 | this.cargoCheckOptions.command = config.get<string>( | 111 | this.cargoWatchOptions.command = config.get<string>( |
110 | 'cargo-watch.command', | 112 | 'cargo-watch.command', |
111 | '', | 113 | '', |
112 | ); | 114 | ); |
113 | } | 115 | } |
114 | 116 | ||
117 | if (config.has('cargo-watch.allTargets')) { | ||
118 | this.cargoWatchOptions.allTargets = config.get<boolean>( | ||
119 | 'cargo-watch.allTargets', | ||
120 | true, | ||
121 | ); | ||
122 | } | ||
123 | |||
115 | if (config.has('lruCapacity')) { | 124 | if (config.has('lruCapacity')) { |
116 | this.lruCapacity = config.get('lruCapacity') as number; | 125 | this.lruCapacity = config.get('lruCapacity') as number; |
117 | } | 126 | } |
diff --git a/editors/code/src/extension.ts b/editors/code/src/extension.ts index 36163b6bb..1da10ebd0 100644 --- a/editors/code/src/extension.ts +++ b/editors/code/src/extension.ts | |||
@@ -85,7 +85,7 @@ export async function activate(context: vscode.ExtensionContext) { | |||
85 | } | 85 | } |
86 | 86 | ||
87 | const watchStatus = new StatusDisplay( | 87 | const watchStatus = new StatusDisplay( |
88 | Server.config.cargoCheckOptions.command || 'check', | 88 | Server.config.cargoWatchOptions.command, |
89 | ); | 89 | ); |
90 | disposeOnDeactivation(watchStatus); | 90 | disposeOnDeactivation(watchStatus); |
91 | 91 | ||
diff --git a/editors/code/src/server.ts b/editors/code/src/server.ts index 409d3b4b7..ae81af848 100644 --- a/editors/code/src/server.ts +++ b/editors/code/src/server.ts | |||
@@ -55,9 +55,11 @@ 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, | 58 | cargoWatchEnable: Server.config.cargoWatchOptions.enable, |
59 | cargoCheckCommand: Server.config.cargoCheckOptions.command, | 59 | cargoWatchArgumets: Server.config.cargoWatchOptions.arguments, |
60 | cargoCheckArgs: Server.config.cargoCheckOptions.arguments, | 60 | cargoWatchCommand: Server.config.cargoWatchOptions.command, |
61 | cargoWatchAllTargets: | ||
62 | Server.config.cargoWatchOptions.allTargets, | ||
61 | excludeGlobs: Server.config.excludeGlobs, | 63 | excludeGlobs: Server.config.excludeGlobs, |
62 | useClientWatching: Server.config.useClientWatching, | 64 | useClientWatching: Server.config.useClientWatching, |
63 | featureFlags: Server.config.featureFlags, | 65 | featureFlags: Server.config.featureFlags, |