aboutsummaryrefslogtreecommitdiff
path: root/crates/rust-analyzer/src/main_loop.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-06-03 11:22:01 +0100
committerAleksey Kladov <[email protected]>2020-06-03 11:22:01 +0100
commit8baa4c5d07690dc908b6299471c936c0d87ad871 (patch)
tree029cef7da188bf032c3aa1fff456a37cbf963a0f /crates/rust-analyzer/src/main_loop.rs
parent03a76191a18b450a8e4ae309296fd7c0614d14d2 (diff)
Groundwork for specifying the set of projects via config
Diffstat (limited to 'crates/rust-analyzer/src/main_loop.rs')
-rw-r--r--crates/rust-analyzer/src/main_loop.rs29
1 files changed, 13 insertions, 16 deletions
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index ea5b4c91c..d901f21d7 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -12,13 +12,11 @@ use std::{
12 fmt, 12 fmt,
13 ops::Range, 13 ops::Range,
14 panic, 14 panic,
15 path::PathBuf,
16 sync::Arc, 15 sync::Arc,
17 time::{Duration, Instant}, 16 time::{Duration, Instant},
18}; 17};
19 18
20use crossbeam_channel::{never, select, unbounded, RecvError, Sender}; 19use crossbeam_channel::{never, select, unbounded, RecvError, Sender};
21use itertools::Itertools;
22use lsp_server::{Connection, ErrorCode, Message, Notification, Request, RequestId, Response}; 20use lsp_server::{Connection, ErrorCode, Message, Notification, Request, RequestId, Response};
23use lsp_types::{ 21use lsp_types::{
24 DidChangeTextDocumentParams, NumberOrString, TextDocumentContentChangeEvent, WorkDoneProgress, 22 DidChangeTextDocumentParams, NumberOrString, TextDocumentContentChangeEvent, WorkDoneProgress,
@@ -28,7 +26,7 @@ use lsp_types::{
28use ra_flycheck::{CheckTask, Status}; 26use ra_flycheck::{CheckTask, Status};
29use ra_ide::{Canceled, FileId, LibraryData, LineIndex, SourceRootId}; 27use ra_ide::{Canceled, FileId, LibraryData, LineIndex, SourceRootId};
30use ra_prof::profile; 28use ra_prof::profile;
31use ra_project_model::{PackageRoot, ProjectManifest, ProjectWorkspace}; 29use ra_project_model::{PackageRoot, ProjectWorkspace};
32use ra_vfs::{VfsFile, VfsTask, Watch}; 30use ra_vfs::{VfsFile, VfsTask, Watch};
33use relative_path::RelativePathBuf; 31use relative_path::RelativePathBuf;
34use rustc_hash::FxHashSet; 32use rustc_hash::FxHashSet;
@@ -36,7 +34,7 @@ use serde::{de::DeserializeOwned, Serialize};
36use threadpool::ThreadPool; 34use threadpool::ThreadPool;
37 35
38use crate::{ 36use crate::{
39 config::{Config, FilesWatcher}, 37 config::{Config, FilesWatcher, LinkedProject},
40 diagnostics::{to_proto::url_from_path_with_drive_lowercasing, DiagnosticTask}, 38 diagnostics::{to_proto::url_from_path_with_drive_lowercasing, DiagnosticTask},
41 from_proto, 39 from_proto,
42 global_state::{GlobalState, GlobalStateSnapshot}, 40 global_state::{GlobalState, GlobalStateSnapshot},
@@ -70,7 +68,7 @@ impl fmt::Display for LspError {
70 68
71impl Error for LspError {} 69impl Error for LspError {}
72 70
73pub fn main_loop(ws_roots: Vec<PathBuf>, config: Config, connection: Connection) -> Result<()> { 71pub fn main_loop(config: Config, connection: Connection) -> Result<()> {
74 log::info!("initial config: {:#?}", config); 72 log::info!("initial config: {:#?}", config);
75 73
76 // Windows scheduler implements priority boosts: if thread waits for an 74 // Windows scheduler implements priority boosts: if thread waits for an
@@ -95,25 +93,24 @@ pub fn main_loop(ws_roots: Vec<PathBuf>, config: Config, connection: Connection)
95 let mut loop_state = LoopState::default(); 93 let mut loop_state = LoopState::default();
96 let mut global_state = { 94 let mut global_state = {
97 let workspaces = { 95 let workspaces = {
98 // FIXME: support dynamic workspace loading. 96 if config.linked_projects.is_empty() && config.notifications.cargo_toml_not_found {
99 let project_roots = ProjectManifest::discover_all(&ws_roots);
100
101 if project_roots.is_empty() && config.notifications.cargo_toml_not_found {
102 show_message( 97 show_message(
103 lsp_types::MessageType::Error, 98 lsp_types::MessageType::Error,
104 format!( 99 "rust-analyzer failed to discover workspace".to_string(),
105 "rust-analyzer failed to discover workspace, no Cargo.toml found, dirs searched: {}",
106 ws_roots.iter().format_with(", ", |it, f| f(&it.display()))
107 ),
108 &connection.sender, 100 &connection.sender,
109 ); 101 );
110 }; 102 };
111 103
112 project_roots 104 config
113 .into_iter() 105 .linked_projects
106 .iter()
107 .filter_map(|project| match project {
108 LinkedProject::ProjectManifest(it) => Some(it),
109 LinkedProject::JsonProject(_) => None,
110 })
114 .filter_map(|root| { 111 .filter_map(|root| {
115 ra_project_model::ProjectWorkspace::load( 112 ra_project_model::ProjectWorkspace::load(
116 root, 113 root.clone(),
117 &config.cargo, 114 &config.cargo,
118 config.with_sysroot, 115 config.with_sysroot,
119 ) 116 )