diff options
author | Benjamin Coenen <[email protected]> | 2020-04-17 09:30:39 +0100 |
---|---|---|
committer | Benjamin Coenen <[email protected]> | 2020-04-17 09:30:39 +0100 |
commit | 0a1585075c65dd6049fc11c641309c89210e222d (patch) | |
tree | ceda5ef63d2179f25a7d5abaa16fa1dc30c9867b /crates/rust-analyzer/src/main_loop.rs | |
parent | 071ef268b5c8fb9afec1db912ebcc5d6577f5e73 (diff) | |
parent | 8d296be1090b21b60e509c831864ae85feec2490 (diff) |
Merge branch 'master' of github.com:rust-analyzer/rust-analyzer
Diffstat (limited to 'crates/rust-analyzer/src/main_loop.rs')
-rw-r--r-- | crates/rust-analyzer/src/main_loop.rs | 60 |
1 files changed, 35 insertions, 25 deletions
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 8d1429196..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 | ||
17 | use crossbeam_channel::{never, select, unbounded, RecvError, Sender}; | 17 | use crossbeam_channel::{never, select, unbounded, RecvError, Sender}; |
18 | use itertools::Itertools; | ||
18 | use lsp_server::{Connection, ErrorCode, Message, Notification, Request, RequestId, Response}; | 19 | use lsp_server::{Connection, ErrorCode, Message, Notification, Request, RequestId, Response}; |
19 | use lsp_types::{ | 20 | use lsp_types::{ |
20 | NumberOrString, WorkDoneProgress, WorkDoneProgressBegin, WorkDoneProgressCreateParams, | 21 | NumberOrString, WorkDoneProgress, WorkDoneProgressBegin, WorkDoneProgressCreateParams, |
@@ -88,37 +89,46 @@ pub fn main_loop(ws_roots: Vec<PathBuf>, config: Config, connection: Connection) | |||
88 | 89 | ||
89 | let mut loop_state = LoopState::default(); | 90 | let mut loop_state = LoopState::default(); |
90 | let mut world_state = { | 91 | let mut world_state = { |
91 | // FIXME: support dynamic workspace loading. | ||
92 | let workspaces = { | 92 | let workspaces = { |
93 | let mut loaded_workspaces = Vec::new(); | 93 | // FIXME: support dynamic workspace loading. |
94 | for ws_root in &ws_roots { | 94 | let mut visited = FxHashSet::default(); |
95 | let workspace = ra_project_model::ProjectWorkspace::discover_with_sysroot( | 95 | let project_roots = ws_roots |
96 | ws_root.as_path(), | 96 | .iter() |
97 | config.with_sysroot, | 97 | .filter_map(|it| ra_project_model::ProjectRoot::discover(it).ok()) |
98 | &config.cargo, | 98 | .flatten() |
99 | ); | 99 | .filter(|it| visited.insert(it.clone())) |
100 | match workspace { | 100 | .collect::<Vec<_>>(); |
101 | Ok(workspace) => loaded_workspaces.push(workspace), | 101 | |
102 | Err(e) => { | 102 | if project_roots.is_empty() && config.notifications.cargo_toml_not_found { |
103 | log::error!("loading workspace failed: {:?}", e); | 103 | show_message( |
104 | 104 | req::MessageType::Error, | |
105 | if let Some(ra_project_model::CargoTomlNotFoundError { .. }) = | 105 | format!( |
106 | e.downcast_ref() | 106 | "rust-analyzer failed to discover workspace, no Cargo.toml found, dirs searched: {}", |
107 | { | 107 | ws_roots.iter().format_with(", ", |it, f| f(&it.display())) |
108 | if !config.notifications.cargo_toml_not_found { | 108 | ), |
109 | continue; | 109 | &connection.sender, |
110 | } | 110 | ); |
111 | } | 111 | }; |
112 | 112 | ||
113 | project_roots | ||
114 | .into_iter() | ||
115 | .filter_map(|root| { | ||
116 | ra_project_model::ProjectWorkspace::load( | ||
117 | root, | ||
118 | &config.cargo, | ||
119 | config.with_sysroot, | ||
120 | ) | ||
121 | .map_err(|err| { | ||
122 | log::error!("failed to load workspace: {:#}", err); | ||
113 | show_message( | 123 | show_message( |
114 | req::MessageType::Error, | 124 | req::MessageType::Error, |
115 | format!("rust-analyzer failed to load workspace: {:?}", e), | 125 | format!("rust-analyzer failed to load workspace: {:#}", err), |
116 | &connection.sender, | 126 | &connection.sender, |
117 | ); | 127 | ); |
118 | } | 128 | }) |
119 | } | 129 | .ok() |
120 | } | 130 | }) |
121 | loaded_workspaces | 131 | .collect::<Vec<_>>() |
122 | }; | 132 | }; |
123 | 133 | ||
124 | let globs = config | 134 | let globs = config |