aboutsummaryrefslogtreecommitdiff
path: root/crates/rust-analyzer/src/main_loop.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-04-16 21:19:38 +0100
committerAleksey Kladov <[email protected]>2020-04-16 21:35:50 +0100
commit422ae477ce2a52c8d004ce629318f0b7c1d89638 (patch)
tree50b9ce2048599e53d68936ba317aa28c6231b4b1 /crates/rust-analyzer/src/main_loop.rs
parentbe2654b0ed3e4eb51bc3745b2329d6264588549f (diff)
Unmix error handling when discovering workspaces
Hitting an io::Error is a legit problem. Finding more than one Cargo.toml is not.
Diffstat (limited to 'crates/rust-analyzer/src/main_loop.rs')
-rw-r--r--crates/rust-analyzer/src/main_loop.rs36
1 files changed, 17 insertions, 19 deletions
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index 9c345601c..fc4c77f8a 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -15,6 +15,7 @@ use std::{
15}; 15};
16 16
17use crossbeam_channel::{never, select, unbounded, RecvError, Sender}; 17use crossbeam_channel::{never, select, unbounded, RecvError, Sender};
18use itertools::Itertools;
18use lsp_server::{Connection, ErrorCode, Message, Notification, Request, RequestId, Response}; 19use lsp_server::{Connection, ErrorCode, Message, Notification, Request, RequestId, Response};
19use lsp_types::{ 20use lsp_types::{
20 NumberOrString, WorkDoneProgress, WorkDoneProgressBegin, WorkDoneProgressCreateParams, 21 NumberOrString, WorkDoneProgress, WorkDoneProgressBegin, WorkDoneProgressCreateParams,
@@ -93,27 +94,24 @@ pub fn main_loop(ws_roots: Vec<PathBuf>, config: Config, connection: Connection)
93 let mut visited = FxHashSet::default(); 94 let mut visited = FxHashSet::default();
94 let project_roots = ws_roots 95 let project_roots = ws_roots
95 .iter() 96 .iter()
96 .map(|it| ra_project_model::ProjectRoot::discover(it)) 97 .filter_map(|it| ra_project_model::ProjectRoot::discover(it).ok())
97 .filter_map(|dir| { 98 .flatten()
98 dir.map_err(|cargo_toml_not_found| { 99 .filter(|it| visited.insert(it.clone()))
99 log::error!("discovering workspace failed: {:?}", cargo_toml_not_found); 100 .collect::<Vec<_>>();
100 101
101 if config.notifications.cargo_toml_not_found { 102 if project_roots.is_empty() && config.notifications.cargo_toml_not_found {
102 show_message( 103 show_message(
103 req::MessageType::Error, 104 req::MessageType::Error,
104 format!( 105 format!(
105 "rust-analyzer failed to discover workspace: {:?}", 106 "rust-analyzer failed to discover workspace, no Cargo.toml found, dirs searched: {}",
106 cargo_toml_not_found 107 ws_roots.iter().format_with(", ", |it, f| f(&it.display()))
107 ), 108 ),
108 &connection.sender, 109 &connection.sender,
109 ); 110 );
110 } 111 };
111 })
112 .ok()
113 })
114 .filter(|it| visited.insert(it.clone()));
115 112
116 project_roots 113 project_roots
114 .into_iter()
117 .filter_map(|root| { 115 .filter_map(|root| {
118 ra_project_model::ProjectWorkspace::load( 116 ra_project_model::ProjectWorkspace::load(
119 root, 117 root,