diff options
author | Aleksey Kladov <[email protected]> | 2018-09-03 19:26:59 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-09-03 19:26:59 +0100 |
commit | 5ba645c0094c79d9aab527f0396fdad3e99bef3b (patch) | |
tree | a831263055a2f3843fa38919ff7b7b5aaf2c6e0c /crates/server/src | |
parent | 47cbaeba6f21e59ee8735bfe8bcbf06300767b57 (diff) |
index libraies off the main thread
Diffstat (limited to 'crates/server/src')
-rw-r--r-- | crates/server/src/main_loop/mod.rs | 15 | ||||
-rw-r--r-- | crates/server/src/server_world.rs | 13 |
2 files changed, 21 insertions, 7 deletions
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; | |||
10 | use serde::{Serialize, de::DeserializeOwned}; | 10 | use serde::{Serialize, de::DeserializeOwned}; |
11 | use crossbeam_channel::{bounded, Sender, Receiver}; | 11 | use crossbeam_channel::{bounded, Sender, Receiver}; |
12 | use languageserver_types::{NumberOrString}; | 12 | use languageserver_types::{NumberOrString}; |
13 | use libanalysis::{FileId, JobHandle, JobToken}; | 13 | use libanalysis::{FileId, JobHandle, JobToken, LibraryData}; |
14 | use gen_lsp_server::{ | 14 | use 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 | ||
8 | use languageserver_types::Url; | 8 | use languageserver_types::Url; |
9 | use libanalysis::{FileId, AnalysisHost, Analysis, CrateGraph, CrateId}; | 9 | use libanalysis::{FileId, AnalysisHost, Analysis, CrateGraph, CrateId, LibraryData}; |
10 | 10 | ||
11 | use { | 11 | use { |
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 { |