aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-07-02 14:32:56 +0100
committerAleksey Kladov <[email protected]>2020-07-02 14:34:12 +0100
commit4f26a3734ea3ca9da658c2c33c11ef4b87fddf89 (patch)
tree3aad3dd45b3e7f5c35d909b88e5a22b47e642c9c
parent3ef76760761d17cef4ea4e8462d9ee2ca8395467 (diff)
Indicate when project needs a reload
-rw-r--r--crates/rust-analyzer/src/global_state.rs1
-rw-r--r--crates/rust-analyzer/src/main_loop.rs38
-rw-r--r--crates/rust-analyzer/src/reload.rs2
-rw-r--r--crates/rust-analyzer/tests/heavy_tests/support.rs17
4 files changed, 51 insertions, 7 deletions
diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs
index 5e9cae3f8..640b3959d 100644
--- a/crates/rust-analyzer/src/global_state.rs
+++ b/crates/rust-analyzer/src/global_state.rs
@@ -32,6 +32,7 @@ pub(crate) enum Status {
32 Loading, 32 Loading,
33 Ready, 33 Ready,
34 Invalid, 34 Invalid,
35 NeedsReload,
35} 36}
36 37
37impl Default for Status { 38impl Default for Status {
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index a5a8c17a0..d4d18a808 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -111,6 +111,35 @@ impl GlobalState {
111 } 111 }
112 112
113 fn run(mut self, inbox: Receiver<lsp_server::Message>) -> Result<()> { 113 fn run(mut self, inbox: Receiver<lsp_server::Message>) -> Result<()> {
114 let registration_options = lsp_types::TextDocumentRegistrationOptions {
115 document_selector: Some(vec![
116 lsp_types::DocumentFilter {
117 language: None,
118 scheme: None,
119 pattern: Some("**/*.rs".into()),
120 },
121 lsp_types::DocumentFilter {
122 language: None,
123 scheme: None,
124 pattern: Some("**/Cargo.toml".into()),
125 },
126 lsp_types::DocumentFilter {
127 language: None,
128 scheme: None,
129 pattern: Some("**/Cargo.lock".into()),
130 },
131 ]),
132 };
133 let registration = lsp_types::Registration {
134 id: "textDocument/didSave".to_string(),
135 method: "textDocument/didSave".to_string(),
136 register_options: Some(serde_json::to_value(registration_options).unwrap()),
137 };
138 self.send_request::<lsp_types::request::RegisterCapability>(
139 lsp_types::RegistrationParams { registrations: vec![registration] },
140 |_, _| (),
141 );
142
114 self.reload(); 143 self.reload();
115 144
116 while let Some(event) = self.next_event(&inbox) { 145 while let Some(event) = self.next_event(&inbox) {
@@ -281,6 +310,7 @@ impl GlobalState {
281 Status::Loading => lsp_ext::Status::Loading, 310 Status::Loading => lsp_ext::Status::Loading,
282 Status::Ready => lsp_ext::Status::Ready, 311 Status::Ready => lsp_ext::Status::Ready,
283 Status::Invalid => lsp_ext::Status::Invalid, 312 Status::Invalid => lsp_ext::Status::Invalid,
313 Status::NeedsReload => lsp_ext::Status::NeedsReload,
284 }; 314 };
285 self.send_notification::<lsp_ext::StatusNotification>(lsp_status); 315 self.send_notification::<lsp_ext::StatusNotification>(lsp_status);
286 } 316 }
@@ -395,10 +425,16 @@ impl GlobalState {
395 ); 425 );
396 Ok(()) 426 Ok(())
397 })? 427 })?
398 .on::<lsp_types::notification::DidSaveTextDocument>(|this, _params| { 428 .on::<lsp_types::notification::DidSaveTextDocument>(|this, params| {
399 if let Some(flycheck) = &this.flycheck { 429 if let Some(flycheck) = &this.flycheck {
400 flycheck.handle.update(); 430 flycheck.handle.update();
401 } 431 }
432 let uri = params.text_document.uri.as_str();
433 if uri.ends_with("Cargo.toml") || uri.ends_with("Cargo.lock") {
434 if matches!(this.status, Status::Ready | Status::Invalid) {
435 this.transition(Status::NeedsReload);
436 }
437 }
402 Ok(()) 438 Ok(())
403 })? 439 })?
404 .on::<lsp_types::notification::DidChangeConfiguration>(|this, _params| { 440 .on::<lsp_types::notification::DidChangeConfiguration>(|this, _params| {
diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs
index 0c1fd1b8b..523b04b97 100644
--- a/crates/rust-analyzer/src/reload.rs
+++ b/crates/rust-analyzer/src/reload.rs
@@ -78,7 +78,7 @@ impl GlobalState {
78 .collect(), 78 .collect(),
79 }; 79 };
80 let registration = lsp_types::Registration { 80 let registration = lsp_types::Registration {
81 id: "file-watcher".to_string(), 81 id: "workspace/didChangeWatchedFiles".to_string(),
82 method: "workspace/didChangeWatchedFiles".to_string(), 82 method: "workspace/didChangeWatchedFiles".to_string(),
83 register_options: Some(serde_json::to_value(registration_options).unwrap()), 83 register_options: Some(serde_json::to_value(registration_options).unwrap()),
84 }; 84 };
diff --git a/crates/rust-analyzer/tests/heavy_tests/support.rs b/crates/rust-analyzer/tests/heavy_tests/support.rs
index 49f194f7e..7bf687794 100644
--- a/crates/rust-analyzer/tests/heavy_tests/support.rs
+++ b/crates/rust-analyzer/tests/heavy_tests/support.rs
@@ -176,12 +176,19 @@ impl Server {
176 while let Some(msg) = self.recv() { 176 while let Some(msg) = self.recv() {
177 match msg { 177 match msg {
178 Message::Request(req) => { 178 Message::Request(req) => {
179 if req.method != "window/workDoneProgress/create" 179 if req.method == "window/workDoneProgress/create" {
180 && !(req.method == "client/registerCapability" 180 continue;
181 && req.params.to_string().contains("workspace/didChangeWatchedFiles"))
182 {
183 panic!("unexpected request: {:?}", req)
184 } 181 }
182 if req.method == "client/registerCapability" {
183 let params = req.params.to_string();
184 if ["workspace/didChangeWatchedFiles", "textDocument/didSave"]
185 .iter()
186 .any(|&it| params.contains(it))
187 {
188 continue;
189 }
190 }
191 panic!("unexpected request: {:?}", req)
185 } 192 }
186 Message::Notification(_) => (), 193 Message::Notification(_) => (),
187 Message::Response(res) => { 194 Message::Response(res) => {