aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-09-03 19:26:59 +0100
committerAleksey Kladov <[email protected]>2018-09-03 19:26:59 +0100
commit5ba645c0094c79d9aab527f0396fdad3e99bef3b (patch)
treea831263055a2f3843fa38919ff7b7b5aaf2c6e0c /crates
parent47cbaeba6f21e59ee8735bfe8bcbf06300767b57 (diff)
index libraies off the main thread
Diffstat (limited to 'crates')
-rw-r--r--crates/libanalysis/src/imp.rs5
-rw-r--r--crates/libanalysis/src/lib.rs16
-rw-r--r--crates/libanalysis/src/roots.rs3
-rw-r--r--crates/server/src/main_loop/mod.rs15
-rw-r--r--crates/server/src/server_world.rs13
5 files changed, 39 insertions, 13 deletions
diff --git a/crates/libanalysis/src/imp.rs b/crates/libanalysis/src/imp.rs
index 3ea27947e..50855551e 100644
--- a/crates/libanalysis/src/imp.rs
+++ b/crates/libanalysis/src/imp.rs
@@ -57,9 +57,8 @@ impl AnalysisHostImpl {
57 } 57 }
58 self.data_mut().crate_graph = graph; 58 self.data_mut().crate_graph = graph;
59 } 59 }
60 pub fn add_library(&mut self, files: impl Iterator<Item=(FileId, String)>) { 60 pub fn add_library(&mut self, root: ReadonlySourceRoot) {
61 let libs = ReadonlySourceRoot::new(files); 61 self.data_mut().libs.push(Arc::new(root));
62 self.data_mut().libs.push(Arc::new(libs));
63 } 62 }
64 fn data_mut(&mut self) -> &mut WorldData { 63 fn data_mut(&mut self) -> &mut WorldData {
65 Arc::make_mut(&mut self.data) 64 Arc::make_mut(&mut self.data)
diff --git a/crates/libanalysis/src/lib.rs b/crates/libanalysis/src/lib.rs
index e9e0c51d5..a8152939b 100644
--- a/crates/libanalysis/src/lib.rs
+++ b/crates/libanalysis/src/lib.rs
@@ -68,8 +68,8 @@ impl AnalysisHost {
68 pub fn set_crate_graph(&mut self, graph: CrateGraph) { 68 pub fn set_crate_graph(&mut self, graph: CrateGraph) {
69 self.imp.set_crate_graph(graph) 69 self.imp.set_crate_graph(graph)
70 } 70 }
71 pub fn add_library(&mut self, files: impl Iterator<Item=(FileId, String)>) { 71 pub fn add_library(&mut self, data: LibraryData) {
72 self.imp.add_library(files) 72 self.imp.add_library(data.root)
73 } 73 }
74} 74}
75 75
@@ -216,3 +216,15 @@ impl Analysis {
216 self.imp.diagnostics(file_id) 216 self.imp.diagnostics(file_id)
217 } 217 }
218} 218}
219
220#[derive(Debug)]
221pub struct LibraryData {
222 root: roots::ReadonlySourceRoot
223}
224
225impl LibraryData {
226 pub fn prepare(files: Vec<(FileId, String)>) -> LibraryData {
227 let root = roots::ReadonlySourceRoot::new(files);
228 LibraryData { root }
229 }
230}
diff --git a/crates/libanalysis/src/roots.rs b/crates/libanalysis/src/roots.rs
index a65668c9b..f1bc72e33 100644
--- a/crates/libanalysis/src/roots.rs
+++ b/crates/libanalysis/src/roots.rs
@@ -136,9 +136,10 @@ pub(crate) struct ReadonlySourceRoot {
136} 136}
137 137
138impl ReadonlySourceRoot { 138impl ReadonlySourceRoot {
139 pub fn new(files: impl Iterator<Item=(FileId, String)>) -> ReadonlySourceRoot { 139 pub fn new(files: Vec<(FileId, String)>) -> ReadonlySourceRoot {
140 let mut module_map = ModuleMap::new(); 140 let mut module_map = ModuleMap::new();
141 let file_map: HashMap<FileId, FileData> = files 141 let file_map: HashMap<FileId, FileData> = files
142 .into_iter()
142 .map(|(id, text)| { 143 .map(|(id, text)| {
143 module_map.update_file(id, ChangeKind::Insert); 144 module_map.update_file(id, ChangeKind::Insert);
144 (id, FileData::new(text)) 145 (id, FileData::new(text))
diff --git a/crates/server/src/main_loop/mod.rs b/crates/server/src/main_loop/mod.rs
index ce61265a2..3d131274f 100644
--- a/crates/server/src/main_loop/mod.rs
+++ b/crates/server/src/main_loop/mod.rs
@@ -10,7 +10,7 @@ use threadpool::ThreadPool;
10use serde::{Serialize, de::DeserializeOwned}; 10use serde::{Serialize, de::DeserializeOwned};
11use crossbeam_channel::{bounded, Sender, Receiver}; 11use crossbeam_channel::{bounded, Sender, Receiver};
12use languageserver_types::{NumberOrString}; 12use languageserver_types::{NumberOrString};
13use libanalysis::{FileId, JobHandle, JobToken}; 13use libanalysis::{FileId, JobHandle, JobToken, LibraryData};
14use gen_lsp_server::{ 14use gen_lsp_server::{
15 RawRequest, RawNotification, RawMessage, RawResponse, ErrorCode, 15 RawRequest, RawNotification, RawMessage, RawResponse, ErrorCode,
16 handle_shutdown, 16 handle_shutdown,
@@ -94,6 +94,7 @@ fn main_loop_inner(
94 pending_requests: &mut HashMap<u64, JobHandle>, 94 pending_requests: &mut HashMap<u64, JobHandle>,
95 subs: &mut Subscriptions, 95 subs: &mut Subscriptions,
96) -> Result<()> { 96) -> Result<()> {
97 let (libdata_sender, libdata_receiver) = bounded(1024);
97 ws_sender.send(ws_root.clone()); 98 ws_sender.send(ws_root.clone());
98 fs_sender.send(ws_root.clone()); 99 fs_sender.send(ws_root.clone());
99 loop { 100 loop {
@@ -103,6 +104,7 @@ fn main_loop_inner(
103 Task(Task), 104 Task(Task),
104 Fs(PathBuf, Vec<FileEvent>), 105 Fs(PathBuf, Vec<FileEvent>),
105 Ws(Result<CargoWorkspace>), 106 Ws(Result<CargoWorkspace>),
107 Lib(LibraryData),
106 } 108 }
107 trace!("selecting"); 109 trace!("selecting");
108 let event = select! { 110 let event = select! {
@@ -119,6 +121,7 @@ fn main_loop_inner(
119 None => bail!("workspace watcher died"), 121 None => bail!("workspace watcher died"),
120 Some(ws) => Event::Ws(ws), 122 Some(ws) => Event::Ws(ws),
121 } 123 }
124 recv(libdata_receiver, data) => Event::Lib(data.unwrap())
122 }; 125 };
123 trace!("selected {:?}", event); 126 trace!("selected {:?}", event);
124 let mut state_changed = false; 127 let mut state_changed = false;
@@ -129,7 +132,12 @@ fn main_loop_inner(
129 if root == ws_root { 132 if root == ws_root {
130 state.apply_fs_changes(events); 133 state.apply_fs_changes(events);
131 } else { 134 } else {
132 state.add_library(events); 135 let files = state.events_to_files(events);
136 let sender = libdata_sender.clone();
137 pool.execute(move || {
138 let data = LibraryData::prepare(files);
139 sender.send(data);
140 });
133 } 141 }
134 state_changed = true; 142 state_changed = true;
135 } 143 }
@@ -152,6 +160,9 @@ fn main_loop_inner(
152 Err(e) => warn!("loading workspace failed: {}", e), 160 Err(e) => warn!("loading workspace failed: {}", e),
153 } 161 }
154 } 162 }
163 Event::Lib(lib) => {
164 state.add_lib(lib);
165 }
155 Event::Msg(msg) => { 166 Event::Msg(msg) => {
156 match msg { 167 match msg {
157 RawMessage::Request(req) => { 168 RawMessage::Request(req) => {
diff --git a/crates/server/src/server_world.rs b/crates/server/src/server_world.rs
index 95c109e10..729418eaa 100644
--- a/crates/server/src/server_world.rs
+++ b/crates/server/src/server_world.rs
@@ -6,7 +6,7 @@ use std::{
6}; 6};
7 7
8use languageserver_types::Url; 8use languageserver_types::Url;
9use libanalysis::{FileId, AnalysisHost, Analysis, CrateGraph, CrateId}; 9use libanalysis::{FileId, AnalysisHost, Analysis, CrateGraph, CrateId, LibraryData};
10 10
11use { 11use {
12 Result, 12 Result,
@@ -64,17 +64,20 @@ impl ServerWorldState {
64 64
65 self.analysis_host.change_files(changes); 65 self.analysis_host.change_files(changes);
66 } 66 }
67 pub fn add_library(&mut self, events: Vec<FileEvent>) { 67 pub fn events_to_files(&mut self, events: Vec<FileEvent>) -> Vec<(FileId, String)> {
68 let pm = &mut self.path_map; 68 let pm = &mut self.path_map;
69 let files = events.into_iter() 69 events.into_iter()
70 .map(|event| { 70 .map(|event| {
71 let text = match event.kind { 71 let text = match event.kind {
72 FileEventKind::Add(text) => text, 72 FileEventKind::Add(text) => text,
73 }; 73 };
74 (event.path, text) 74 (event.path, text)
75 }) 75 })
76 .map(|(path, text)| (pm.get_or_insert(path), text)); 76 .map(|(path, text)| (pm.get_or_insert(path), text))
77 self.analysis_host.add_library(files); 77 .collect()
78 }
79 pub fn add_lib(&mut self, data: LibraryData) {
80 self.analysis_host.add_library(data);
78 } 81 }
79 82
80 pub fn add_mem_file(&mut self, path: PathBuf, text: String) -> FileId { 83 pub fn add_mem_file(&mut self, path: PathBuf, text: String) -> FileId {