diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_ide/src/lib.rs | 5 | ||||
-rw-r--r-- | crates/ra_ide_db/src/lib.rs | 12 | ||||
-rw-r--r-- | crates/rust-analyzer/src/main_loop.rs | 121 | ||||
-rw-r--r-- | crates/rust-analyzer/src/world.rs | 11 |
4 files changed, 89 insertions, 60 deletions
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index e43414985..937c9caa5 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs | |||
@@ -138,6 +138,11 @@ impl AnalysisHost { | |||
138 | pub fn new(lru_capacity: Option<usize>) -> AnalysisHost { | 138 | pub fn new(lru_capacity: Option<usize>) -> AnalysisHost { |
139 | AnalysisHost { db: RootDatabase::new(lru_capacity) } | 139 | AnalysisHost { db: RootDatabase::new(lru_capacity) } |
140 | } | 140 | } |
141 | |||
142 | pub fn update_lru_capacity(&mut self, lru_capacity: Option<usize>) { | ||
143 | self.db.update_lru_capacity(lru_capacity); | ||
144 | } | ||
145 | |||
141 | /// Returns a snapshot of the current state, which you can query for | 146 | /// Returns a snapshot of the current state, which you can query for |
142 | /// semantic information. | 147 | /// semantic information. |
143 | pub fn analysis(&self) -> Analysis { | 148 | pub fn analysis(&self) -> Analysis { |
diff --git a/crates/ra_ide_db/src/lib.rs b/crates/ra_ide_db/src/lib.rs index 4faeefa8d..e6f2d36e9 100644 --- a/crates/ra_ide_db/src/lib.rs +++ b/crates/ra_ide_db/src/lib.rs | |||
@@ -115,12 +115,16 @@ impl RootDatabase { | |||
115 | db.set_crate_graph_with_durability(Default::default(), Durability::HIGH); | 115 | db.set_crate_graph_with_durability(Default::default(), Durability::HIGH); |
116 | db.set_local_roots_with_durability(Default::default(), Durability::HIGH); | 116 | db.set_local_roots_with_durability(Default::default(), Durability::HIGH); |
117 | db.set_library_roots_with_durability(Default::default(), Durability::HIGH); | 117 | db.set_library_roots_with_durability(Default::default(), Durability::HIGH); |
118 | let lru_capacity = lru_capacity.unwrap_or(ra_db::DEFAULT_LRU_CAP); | 118 | db.update_lru_capacity(lru_capacity); |
119 | db.query_mut(ra_db::ParseQuery).set_lru_capacity(lru_capacity); | ||
120 | db.query_mut(hir::db::ParseMacroQuery).set_lru_capacity(lru_capacity); | ||
121 | db.query_mut(hir::db::MacroExpandQuery).set_lru_capacity(lru_capacity); | ||
122 | db | 119 | db |
123 | } | 120 | } |
121 | |||
122 | pub fn update_lru_capacity(&mut self, lru_capacity: Option<usize>) { | ||
123 | let lru_capacity = lru_capacity.unwrap_or(ra_db::DEFAULT_LRU_CAP); | ||
124 | self.query_mut(ra_db::ParseQuery).set_lru_capacity(lru_capacity); | ||
125 | self.query_mut(hir::db::ParseMacroQuery).set_lru_capacity(lru_capacity); | ||
126 | self.query_mut(hir::db::MacroExpandQuery).set_lru_capacity(lru_capacity); | ||
127 | } | ||
124 | } | 128 | } |
125 | 129 | ||
126 | impl salsa::ParallelDatabase for RootDatabase { | 130 | impl salsa::ParallelDatabase for RootDatabase { |
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index a48368e30..85bde90bb 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs | |||
@@ -17,8 +17,9 @@ use std::{ | |||
17 | use crossbeam_channel::{never, select, unbounded, RecvError, Sender}; | 17 | use crossbeam_channel::{never, select, unbounded, RecvError, Sender}; |
18 | use lsp_server::{Connection, ErrorCode, Message, Notification, Request, RequestId, Response}; | 18 | use lsp_server::{Connection, ErrorCode, Message, Notification, Request, RequestId, Response}; |
19 | use lsp_types::{ | 19 | use lsp_types::{ |
20 | ClientCapabilities, NumberOrString, WorkDoneProgress, WorkDoneProgressBegin, | 20 | ClientCapabilities, NumberOrString, TextDocumentClientCapabilities, WorkDoneProgress, |
21 | WorkDoneProgressCreateParams, WorkDoneProgressEnd, WorkDoneProgressReport, | 21 | WorkDoneProgressBegin, WorkDoneProgressCreateParams, WorkDoneProgressEnd, |
22 | WorkDoneProgressReport, | ||
22 | }; | 23 | }; |
23 | use ra_cargo_watch::{url_from_path_with_drive_lowercasing, CheckOptions, CheckTask}; | 24 | use ra_cargo_watch::{url_from_path_with_drive_lowercasing, CheckOptions, CheckTask}; |
24 | use ra_ide::{Canceled, FileId, InlayHintsOptions, LibraryData, SourceRootId}; | 25 | use ra_ide::{Canceled, FileId, InlayHintsOptions, LibraryData, SourceRootId}; |
@@ -64,6 +65,53 @@ impl fmt::Display for LspError { | |||
64 | 65 | ||
65 | impl Error for LspError {} | 66 | impl Error for LspError {} |
66 | 67 | ||
68 | fn get_feature_flags(config: &ServerConfig, connection: &Connection) -> FeatureFlags { | ||
69 | let mut ff = FeatureFlags::default(); | ||
70 | for (flag, &value) in &config.feature_flags { | ||
71 | if ff.set(flag.as_str(), value).is_err() { | ||
72 | log::error!("unknown feature flag: {:?}", flag); | ||
73 | show_message( | ||
74 | req::MessageType::Error, | ||
75 | format!("unknown feature flag: {:?}", flag), | ||
76 | &connection.sender, | ||
77 | ); | ||
78 | } | ||
79 | } | ||
80 | log::info!("feature_flags: {:#?}", ff); | ||
81 | ff | ||
82 | } | ||
83 | |||
84 | fn get_options( | ||
85 | config: &ServerConfig, | ||
86 | text_document_caps: Option<&TextDocumentClientCapabilities>, | ||
87 | ) -> Options { | ||
88 | Options { | ||
89 | publish_decorations: config.publish_decorations, | ||
90 | supports_location_link: text_document_caps | ||
91 | .and_then(|it| it.definition) | ||
92 | .and_then(|it| it.link_support) | ||
93 | .unwrap_or(false), | ||
94 | line_folding_only: text_document_caps | ||
95 | .and_then(|it| it.folding_range.as_ref()) | ||
96 | .and_then(|it| it.line_folding_only) | ||
97 | .unwrap_or(false), | ||
98 | inlay_hints: InlayHintsOptions { | ||
99 | type_hints: config.inlay_hints_type, | ||
100 | parameter_hints: config.inlay_hints_parameter, | ||
101 | chaining_hints: config.inlay_hints_chaining, | ||
102 | max_length: config.inlay_hints_max_length, | ||
103 | }, | ||
104 | cargo_watch: CheckOptions { | ||
105 | enable: config.cargo_watch_enable, | ||
106 | args: config.cargo_watch_args.clone(), | ||
107 | command: config.cargo_watch_command.clone(), | ||
108 | all_targets: config.cargo_watch_all_targets, | ||
109 | }, | ||
110 | rustfmt_args: config.rustfmt_args.clone(), | ||
111 | vscode_lldb: config.vscode_lldb, | ||
112 | } | ||
113 | } | ||
114 | |||
67 | pub fn main_loop( | 115 | pub fn main_loop( |
68 | ws_roots: Vec<PathBuf>, | 116 | ws_roots: Vec<PathBuf>, |
69 | client_caps: ClientCapabilities, | 117 | client_caps: ClientCapabilities, |
@@ -91,23 +139,10 @@ pub fn main_loop( | |||
91 | SetThreadPriority(thread, thread_priority_above_normal); | 139 | SetThreadPriority(thread, thread_priority_above_normal); |
92 | } | 140 | } |
93 | 141 | ||
142 | let text_document_caps = client_caps.text_document.as_ref(); | ||
94 | let mut loop_state = LoopState::default(); | 143 | let mut loop_state = LoopState::default(); |
95 | let mut world_state = { | 144 | let mut world_state = { |
96 | let feature_flags = { | 145 | let feature_flags = get_feature_flags(&config, &connection); |
97 | let mut ff = FeatureFlags::default(); | ||
98 | for (flag, value) in config.feature_flags { | ||
99 | if ff.set(flag.as_str(), value).is_err() { | ||
100 | log::error!("unknown feature flag: {:?}", flag); | ||
101 | show_message( | ||
102 | req::MessageType::Error, | ||
103 | format!("unknown feature flag: {:?}", flag), | ||
104 | &connection.sender, | ||
105 | ); | ||
106 | } | ||
107 | } | ||
108 | ff | ||
109 | }; | ||
110 | log::info!("feature_flags: {:#?}", feature_flags); | ||
111 | 146 | ||
112 | // FIXME: support dynamic workspace loading. | 147 | // FIXME: support dynamic workspace loading. |
113 | let workspaces = { | 148 | let workspaces = { |
@@ -169,42 +204,13 @@ pub fn main_loop( | |||
169 | connection.sender.send(request.into()).unwrap(); | 204 | connection.sender.send(request.into()).unwrap(); |
170 | } | 205 | } |
171 | 206 | ||
172 | let options = { | ||
173 | let text_document_caps = client_caps.text_document.as_ref(); | ||
174 | Options { | ||
175 | publish_decorations: config.publish_decorations, | ||
176 | supports_location_link: text_document_caps | ||
177 | .and_then(|it| it.definition) | ||
178 | .and_then(|it| it.link_support) | ||
179 | .unwrap_or(false), | ||
180 | line_folding_only: text_document_caps | ||
181 | .and_then(|it| it.folding_range.as_ref()) | ||
182 | .and_then(|it| it.line_folding_only) | ||
183 | .unwrap_or(false), | ||
184 | inlay_hints: InlayHintsOptions { | ||
185 | type_hints: config.inlay_hints_type, | ||
186 | parameter_hints: config.inlay_hints_parameter, | ||
187 | chaining_hints: config.inlay_hints_chaining, | ||
188 | max_length: config.inlay_hints_max_length, | ||
189 | }, | ||
190 | cargo_watch: CheckOptions { | ||
191 | enable: config.cargo_watch_enable, | ||
192 | args: config.cargo_watch_args, | ||
193 | command: config.cargo_watch_command, | ||
194 | all_targets: config.cargo_watch_all_targets, | ||
195 | }, | ||
196 | rustfmt_args: config.rustfmt_args, | ||
197 | vscode_lldb: config.vscode_lldb, | ||
198 | } | ||
199 | }; | ||
200 | |||
201 | WorldState::new( | 207 | WorldState::new( |
202 | ws_roots, | 208 | ws_roots, |
203 | workspaces, | 209 | workspaces, |
204 | config.lru_capacity, | 210 | config.lru_capacity, |
205 | &globs, | 211 | &globs, |
206 | Watch(!config.use_client_watching), | 212 | Watch(!config.use_client_watching), |
207 | options, | 213 | get_options(&config, text_document_caps), |
208 | feature_flags, | 214 | feature_flags, |
209 | ) | 215 | ) |
210 | }; | 216 | }; |
@@ -243,17 +249,16 @@ pub fn main_loop( | |||
243 | break; | 249 | break; |
244 | }; | 250 | }; |
245 | } | 251 | } |
246 | if let Some(new_server_config) = loop_turn( | 252 | loop_turn( |
247 | &pool, | 253 | &pool, |
248 | &task_sender, | 254 | &task_sender, |
249 | &libdata_sender, | 255 | &libdata_sender, |
250 | &connection, | 256 | &connection, |
257 | text_document_caps, | ||
251 | &mut world_state, | 258 | &mut world_state, |
252 | &mut loop_state, | 259 | &mut loop_state, |
253 | event, | 260 | event, |
254 | )? { | 261 | )?; |
255 | dbg!(new_server_config); | ||
256 | } | ||
257 | } | 262 | } |
258 | } | 263 | } |
259 | world_state.analysis_host.request_cancellation(); | 264 | world_state.analysis_host.request_cancellation(); |
@@ -360,10 +365,11 @@ fn loop_turn( | |||
360 | task_sender: &Sender<Task>, | 365 | task_sender: &Sender<Task>, |
361 | libdata_sender: &Sender<LibraryData>, | 366 | libdata_sender: &Sender<LibraryData>, |
362 | connection: &Connection, | 367 | connection: &Connection, |
368 | text_document_caps: Option<&TextDocumentClientCapabilities>, | ||
363 | world_state: &mut WorldState, | 369 | world_state: &mut WorldState, |
364 | loop_state: &mut LoopState, | 370 | loop_state: &mut LoopState, |
365 | event: Event, | 371 | event: Event, |
366 | ) -> Result<Option<ServerConfig>> { | 372 | ) -> Result<()> { |
367 | let loop_start = Instant::now(); | 373 | let loop_start = Instant::now(); |
368 | 374 | ||
369 | // NOTE: don't count blocking select! call as a loop-turn time | 375 | // NOTE: don't count blocking select! call as a loop-turn time |
@@ -374,8 +380,6 @@ fn loop_turn( | |||
374 | log::info!("queued count = {}", queue_count); | 380 | log::info!("queued count = {}", queue_count); |
375 | } | 381 | } |
376 | 382 | ||
377 | let mut new_server_config = None; | ||
378 | |||
379 | match event { | 383 | match event { |
380 | Event::Task(task) => { | 384 | Event::Task(task) => { |
381 | on_task(task, &connection.sender, &mut loop_state.pending_requests, world_state); | 385 | on_task(task, &connection.sender, &mut loop_state.pending_requests, world_state); |
@@ -411,13 +415,18 @@ fn loop_turn( | |||
411 | } | 415 | } |
412 | if Some(&resp.id) == loop_state.configuration_request_id.as_ref() { | 416 | if Some(&resp.id) == loop_state.configuration_request_id.as_ref() { |
413 | loop_state.configuration_request_id.take(); | 417 | loop_state.configuration_request_id.take(); |
418 | // TODO kb unwrap-unwrap-unwrap | ||
414 | let new_config = | 419 | let new_config = |
415 | serde_json::from_value::<Vec<ServerConfig>>(resp.result.unwrap()) | 420 | serde_json::from_value::<Vec<ServerConfig>>(resp.result.unwrap()) |
416 | .unwrap() | 421 | .unwrap() |
417 | .first() | 422 | .first() |
418 | .unwrap() | 423 | .unwrap() |
419 | .to_owned(); | 424 | .to_owned(); |
420 | new_server_config = Some(new_config); | 425 | world_state.update_configuration( |
426 | new_config.lru_capacity, | ||
427 | get_options(&new_config, text_document_caps), | ||
428 | get_feature_flags(&new_config, connection), | ||
429 | ); | ||
421 | } | 430 | } |
422 | } | 431 | } |
423 | }, | 432 | }, |
@@ -488,7 +497,7 @@ fn loop_turn( | |||
488 | } | 497 | } |
489 | } | 498 | } |
490 | 499 | ||
491 | Ok(new_server_config) | 500 | Ok(()) |
492 | } | 501 | } |
493 | 502 | ||
494 | fn on_task( | 503 | fn on_task( |
diff --git a/crates/rust-analyzer/src/world.rs b/crates/rust-analyzer/src/world.rs index ca045f93c..d77844a36 100644 --- a/crates/rust-analyzer/src/world.rs +++ b/crates/rust-analyzer/src/world.rs | |||
@@ -199,6 +199,17 @@ impl WorldState { | |||
199 | } | 199 | } |
200 | } | 200 | } |
201 | 201 | ||
202 | pub fn update_configuration( | ||
203 | &mut self, | ||
204 | lru_capacity: Option<usize>, | ||
205 | options: Options, | ||
206 | feature_flags: FeatureFlags, | ||
207 | ) { | ||
208 | self.feature_flags = Arc::new(feature_flags); | ||
209 | self.analysis_host.update_lru_capacity(lru_capacity); | ||
210 | self.options = options; | ||
211 | } | ||
212 | |||
202 | /// Returns a vec of libraries | 213 | /// Returns a vec of libraries |
203 | /// FIXME: better API here | 214 | /// FIXME: better API here |
204 | pub fn process_changes( | 215 | pub fn process_changes( |