aboutsummaryrefslogtreecommitdiff
path: root/crates/rust-analyzer/src/main_loop.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/rust-analyzer/src/main_loop.rs')
-rw-r--r--crates/rust-analyzer/src/main_loop.rs15
1 files changed, 13 insertions, 2 deletions
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index d4d18a808..cfde55431 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -21,6 +21,7 @@ use crate::{
21 lsp_utils::{apply_document_changes, is_canceled, notification_is, Progress}, 21 lsp_utils::{apply_document_changes, is_canceled, notification_is, Progress},
22 Result, 22 Result,
23}; 23};
24use ra_project_model::ProjectWorkspace;
24 25
25pub fn main_loop(config: Config, connection: Connection) -> Result<()> { 26pub fn main_loop(config: Config, connection: Connection) -> Result<()> {
26 log::info!("initial config: {:#?}", config); 27 log::info!("initial config: {:#?}", config);
@@ -58,6 +59,7 @@ enum Event {
58pub(crate) enum Task { 59pub(crate) enum Task {
59 Response(Response), 60 Response(Response),
60 Diagnostics(Vec<(FileId, Vec<lsp_types::Diagnostic>)>), 61 Diagnostics(Vec<(FileId, Vec<lsp_types::Diagnostic>)>),
62 Workspaces(Vec<anyhow::Result<ProjectWorkspace>>),
61 Unit, 63 Unit,
62} 64}
63 65
@@ -111,6 +113,14 @@ impl GlobalState {
111 } 113 }
112 114
113 fn run(mut self, inbox: Receiver<lsp_server::Message>) -> Result<()> { 115 fn run(mut self, inbox: Receiver<lsp_server::Message>) -> Result<()> {
116 if self.config.linked_projects.is_empty() && self.config.notifications.cargo_toml_not_found
117 {
118 self.show_message(
119 lsp_types::MessageType::Error,
120 "rust-analyzer failed to discover workspace".to_string(),
121 );
122 };
123
114 let registration_options = lsp_types::TextDocumentRegistrationOptions { 124 let registration_options = lsp_types::TextDocumentRegistrationOptions {
115 document_selector: Some(vec![ 125 document_selector: Some(vec![
116 lsp_types::DocumentFilter { 126 lsp_types::DocumentFilter {
@@ -140,7 +150,7 @@ impl GlobalState {
140 |_, _| (), 150 |_, _| (),
141 ); 151 );
142 152
143 self.reload(); 153 self.fetch_workspaces();
144 154
145 while let Some(event) = self.next_event(&inbox) { 155 while let Some(event) = self.next_event(&inbox) {
146 if let Event::Lsp(lsp_server::Message::Notification(not)) = &event { 156 if let Event::Lsp(lsp_server::Message::Notification(not)) = &event {
@@ -182,6 +192,7 @@ impl GlobalState {
182 self.diagnostics.set_native_diagnostics(file_id, diagnostics) 192 self.diagnostics.set_native_diagnostics(file_id, diagnostics)
183 } 193 }
184 } 194 }
195 Task::Workspaces(workspaces) => self.switch_workspaces(workspaces),
185 Task::Unit => (), 196 Task::Unit => (),
186 } 197 }
187 self.analysis_host.maybe_collect_garbage(); 198 self.analysis_host.maybe_collect_garbage();
@@ -320,7 +331,7 @@ impl GlobalState {
320 self.register_request(&req, request_received); 331 self.register_request(&req, request_received);
321 332
322 RequestDispatcher { req: Some(req), global_state: self } 333 RequestDispatcher { req: Some(req), global_state: self }
323 .on_sync::<lsp_ext::ReloadWorkspace>(|s, ()| Ok(s.reload()))? 334 .on_sync::<lsp_ext::ReloadWorkspace>(|s, ()| Ok(s.fetch_workspaces()))?
324 .on_sync::<lsp_ext::JoinLines>(|s, p| handlers::handle_join_lines(s.snapshot(), p))? 335 .on_sync::<lsp_ext::JoinLines>(|s, p| handlers::handle_join_lines(s.snapshot(), p))?
325 .on_sync::<lsp_ext::OnEnter>(|s, p| handlers::handle_on_enter(s.snapshot(), p))? 336 .on_sync::<lsp_ext::OnEnter>(|s, p| handlers::handle_on_enter(s.snapshot(), p))?
326 .on_sync::<lsp_types::request::Shutdown>(|_, ()| Ok(()))? 337 .on_sync::<lsp_types::request::Shutdown>(|_, ()| Ok(()))?