diff options
-rw-r--r-- | Cargo.lock | 1 | ||||
-rw-r--r-- | crates/ra_analysis/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_analysis/src/job.rs | 53 | ||||
-rw-r--r-- | crates/ra_analysis/src/lib.rs | 4 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 21 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/mod.rs | 38 |
6 files changed, 18 insertions, 100 deletions
diff --git a/Cargo.lock b/Cargo.lock index bb0feec2e..f51914883 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -609,7 +609,6 @@ dependencies = [ | |||
609 | name = "ra_analysis" | 609 | name = "ra_analysis" |
610 | version = "0.1.0" | 610 | version = "0.1.0" |
611 | dependencies = [ | 611 | dependencies = [ |
612 | "crossbeam-channel 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", | ||
613 | "fst 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", | 612 | "fst 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", |
614 | "im 12.2.0 (registry+https://github.com/rust-lang/crates.io-index)", | 613 | "im 12.2.0 (registry+https://github.com/rust-lang/crates.io-index)", |
615 | "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", | 614 | "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", |
diff --git a/crates/ra_analysis/Cargo.toml b/crates/ra_analysis/Cargo.toml index dd4ec8375..d7ac69fe8 100644 --- a/crates/ra_analysis/Cargo.toml +++ b/crates/ra_analysis/Cargo.toml | |||
@@ -7,7 +7,6 @@ authors = ["Aleksey Kladov <[email protected]>"] | |||
7 | [dependencies] | 7 | [dependencies] |
8 | relative-path = "0.3.7" | 8 | relative-path = "0.3.7" |
9 | log = "0.4.2" | 9 | log = "0.4.2" |
10 | crossbeam-channel = "0.2.4" | ||
11 | parking_lot = "0.6.3" | 10 | parking_lot = "0.6.3" |
12 | once_cell = "0.1.5" | 11 | once_cell = "0.1.5" |
13 | rayon = "1.0.2" | 12 | rayon = "1.0.2" |
diff --git a/crates/ra_analysis/src/job.rs b/crates/ra_analysis/src/job.rs deleted file mode 100644 index 2871f9839..000000000 --- a/crates/ra_analysis/src/job.rs +++ /dev/null | |||
@@ -1,53 +0,0 @@ | |||
1 | use crossbeam_channel::{bounded, Receiver, Sender}; | ||
2 | |||
3 | pub struct JobHandle { | ||
4 | job_alive: Receiver<Never>, | ||
5 | _job_canceled: Sender<Never>, | ||
6 | } | ||
7 | |||
8 | pub struct JobToken { | ||
9 | _job_alive: Sender<Never>, | ||
10 | job_canceled: Receiver<Never>, | ||
11 | } | ||
12 | |||
13 | impl JobHandle { | ||
14 | pub fn new() -> (JobHandle, JobToken) { | ||
15 | let (sender_alive, receiver_alive) = bounded(0); | ||
16 | let (sender_canceled, receiver_canceled) = bounded(0); | ||
17 | let token = JobToken { | ||
18 | _job_alive: sender_alive, | ||
19 | job_canceled: receiver_canceled, | ||
20 | }; | ||
21 | let handle = JobHandle { | ||
22 | job_alive: receiver_alive, | ||
23 | _job_canceled: sender_canceled, | ||
24 | }; | ||
25 | (handle, token) | ||
26 | } | ||
27 | pub fn has_completed(&self) -> bool { | ||
28 | is_closed(&self.job_alive) | ||
29 | } | ||
30 | pub fn cancel(self) {} | ||
31 | } | ||
32 | |||
33 | impl JobToken { | ||
34 | pub fn is_canceled(&self) -> bool { | ||
35 | is_closed(&self.job_canceled) | ||
36 | } | ||
37 | } | ||
38 | |||
39 | // We don't actually send messages through the channels, | ||
40 | // and instead just check if the channel is closed, | ||
41 | // so we use uninhabited enum as a message type | ||
42 | enum Never {} | ||
43 | |||
44 | /// Nonblocking | ||
45 | fn is_closed(chan: &Receiver<Never>) -> bool { | ||
46 | select! { | ||
47 | recv(chan, msg) => match msg { | ||
48 | None => true, | ||
49 | Some(never) => match never {} | ||
50 | } | ||
51 | default => false, | ||
52 | } | ||
53 | } | ||
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index 750031093..28e0a12b2 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs | |||
@@ -7,8 +7,6 @@ extern crate ra_editor; | |||
7 | extern crate ra_syntax; | 7 | extern crate ra_syntax; |
8 | extern crate rayon; | 8 | extern crate rayon; |
9 | extern crate relative_path; | 9 | extern crate relative_path; |
10 | #[macro_use] | ||
11 | extern crate crossbeam_channel; | ||
12 | extern crate im; | 10 | extern crate im; |
13 | extern crate rustc_hash; | 11 | extern crate rustc_hash; |
14 | extern crate salsa; | 12 | extern crate salsa; |
@@ -16,7 +14,6 @@ extern crate salsa; | |||
16 | mod db; | 14 | mod db; |
17 | mod descriptors; | 15 | mod descriptors; |
18 | mod imp; | 16 | mod imp; |
19 | mod job; | ||
20 | mod module_map; | 17 | mod module_map; |
21 | mod roots; | 18 | mod roots; |
22 | mod symbol_index; | 19 | mod symbol_index; |
@@ -31,7 +28,6 @@ use crate::imp::{AnalysisHostImpl, AnalysisImpl, FileResolverImp}; | |||
31 | 28 | ||
32 | pub use crate::{ | 29 | pub use crate::{ |
33 | descriptors::FnDescriptor, | 30 | descriptors::FnDescriptor, |
34 | job::{JobHandle, JobToken}, | ||
35 | }; | 31 | }; |
36 | pub use ra_editor::{ | 32 | pub use ra_editor::{ |
37 | CompletionItem, FileSymbol, Fold, FoldKind, HighlightedRange, LineIndex, Runnable, | 33 | CompletionItem, FileSymbol, Fold, FoldKind, HighlightedRange, LineIndex, Runnable, |
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 673f1bf7d..f5dff4c80 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -7,7 +7,7 @@ use languageserver_types::{ | |||
7 | InsertTextFormat, Location, Position, SymbolInformation, TextDocumentIdentifier, TextEdit, | 7 | InsertTextFormat, Location, Position, SymbolInformation, TextDocumentIdentifier, TextEdit, |
8 | RenameParams, WorkspaceEdit, PrepareRenameResponse | 8 | RenameParams, WorkspaceEdit, PrepareRenameResponse |
9 | }; | 9 | }; |
10 | use ra_analysis::{FileId, FoldKind, JobToken, Query, RunnableKind}; | 10 | use ra_analysis::{FileId, FoldKind, Query, RunnableKind}; |
11 | use ra_syntax::text_utils::contains_offset_nonstrict; | 11 | use ra_syntax::text_utils::contains_offset_nonstrict; |
12 | use serde_json::to_value; | 12 | use serde_json::to_value; |
13 | 13 | ||
@@ -22,7 +22,6 @@ use crate::{ | |||
22 | pub fn handle_syntax_tree( | 22 | pub fn handle_syntax_tree( |
23 | world: ServerWorld, | 23 | world: ServerWorld, |
24 | params: req::SyntaxTreeParams, | 24 | params: req::SyntaxTreeParams, |
25 | _token: JobToken, | ||
26 | ) -> Result<String> { | 25 | ) -> Result<String> { |
27 | let id = params.text_document.try_conv_with(&world)?; | 26 | let id = params.text_document.try_conv_with(&world)?; |
28 | let res = world.analysis().syntax_tree(id); | 27 | let res = world.analysis().syntax_tree(id); |
@@ -32,7 +31,6 @@ pub fn handle_syntax_tree( | |||
32 | pub fn handle_extend_selection( | 31 | pub fn handle_extend_selection( |
33 | world: ServerWorld, | 32 | world: ServerWorld, |
34 | params: req::ExtendSelectionParams, | 33 | params: req::ExtendSelectionParams, |
35 | _token: JobToken, | ||
36 | ) -> Result<req::ExtendSelectionResult> { | 34 | ) -> Result<req::ExtendSelectionResult> { |
37 | let file_id = params.text_document.try_conv_with(&world)?; | 35 | let file_id = params.text_document.try_conv_with(&world)?; |
38 | let file = world.analysis().file_syntax(file_id); | 36 | let file = world.analysis().file_syntax(file_id); |
@@ -50,7 +48,6 @@ pub fn handle_extend_selection( | |||
50 | pub fn handle_find_matching_brace( | 48 | pub fn handle_find_matching_brace( |
51 | world: ServerWorld, | 49 | world: ServerWorld, |
52 | params: req::FindMatchingBraceParams, | 50 | params: req::FindMatchingBraceParams, |
53 | _token: JobToken, | ||
54 | ) -> Result<Vec<Position>> { | 51 | ) -> Result<Vec<Position>> { |
55 | let file_id = params.text_document.try_conv_with(&world)?; | 52 | let file_id = params.text_document.try_conv_with(&world)?; |
56 | let file = world.analysis().file_syntax(file_id); | 53 | let file = world.analysis().file_syntax(file_id); |
@@ -73,7 +70,6 @@ pub fn handle_find_matching_brace( | |||
73 | pub fn handle_join_lines( | 70 | pub fn handle_join_lines( |
74 | world: ServerWorld, | 71 | world: ServerWorld, |
75 | params: req::JoinLinesParams, | 72 | params: req::JoinLinesParams, |
76 | _token: JobToken, | ||
77 | ) -> Result<req::SourceChange> { | 73 | ) -> Result<req::SourceChange> { |
78 | let file_id = params.text_document.try_conv_with(&world)?; | 74 | let file_id = params.text_document.try_conv_with(&world)?; |
79 | let line_index = world.analysis().file_line_index(file_id); | 75 | let line_index = world.analysis().file_line_index(file_id); |
@@ -87,7 +83,6 @@ pub fn handle_join_lines( | |||
87 | pub fn handle_on_enter( | 83 | pub fn handle_on_enter( |
88 | world: ServerWorld, | 84 | world: ServerWorld, |
89 | params: req::TextDocumentPositionParams, | 85 | params: req::TextDocumentPositionParams, |
90 | _token: JobToken, | ||
91 | ) -> Result<Option<req::SourceChange>> { | 86 | ) -> Result<Option<req::SourceChange>> { |
92 | let file_id = params.text_document.try_conv_with(&world)?; | 87 | let file_id = params.text_document.try_conv_with(&world)?; |
93 | let line_index = world.analysis().file_line_index(file_id); | 88 | let line_index = world.analysis().file_line_index(file_id); |
@@ -101,7 +96,6 @@ pub fn handle_on_enter( | |||
101 | pub fn handle_on_type_formatting( | 96 | pub fn handle_on_type_formatting( |
102 | world: ServerWorld, | 97 | world: ServerWorld, |
103 | params: req::DocumentOnTypeFormattingParams, | 98 | params: req::DocumentOnTypeFormattingParams, |
104 | _token: JobToken, | ||
105 | ) -> Result<Option<Vec<TextEdit>>> { | 99 | ) -> Result<Option<Vec<TextEdit>>> { |
106 | if params.ch != "=" { | 100 | if params.ch != "=" { |
107 | return Ok(None); | 101 | return Ok(None); |
@@ -121,7 +115,6 @@ pub fn handle_on_type_formatting( | |||
121 | pub fn handle_document_symbol( | 115 | pub fn handle_document_symbol( |
122 | world: ServerWorld, | 116 | world: ServerWorld, |
123 | params: req::DocumentSymbolParams, | 117 | params: req::DocumentSymbolParams, |
124 | _token: JobToken, | ||
125 | ) -> Result<Option<req::DocumentSymbolResponse>> { | 118 | ) -> Result<Option<req::DocumentSymbolResponse>> { |
126 | let file_id = params.text_document.try_conv_with(&world)?; | 119 | let file_id = params.text_document.try_conv_with(&world)?; |
127 | let line_index = world.analysis().file_line_index(file_id); | 120 | let line_index = world.analysis().file_line_index(file_id); |
@@ -160,7 +153,6 @@ pub fn handle_document_symbol( | |||
160 | pub fn handle_workspace_symbol( | 153 | pub fn handle_workspace_symbol( |
161 | world: ServerWorld, | 154 | world: ServerWorld, |
162 | params: req::WorkspaceSymbolParams, | 155 | params: req::WorkspaceSymbolParams, |
163 | _token: JobToken, | ||
164 | ) -> Result<Option<Vec<SymbolInformation>>> { | 156 | ) -> Result<Option<Vec<SymbolInformation>>> { |
165 | let all_symbols = params.query.contains("#"); | 157 | let all_symbols = params.query.contains("#"); |
166 | let libs = params.query.contains("*"); | 158 | let libs = params.query.contains("*"); |
@@ -212,7 +204,6 @@ pub fn handle_workspace_symbol( | |||
212 | pub fn handle_goto_definition( | 204 | pub fn handle_goto_definition( |
213 | world: ServerWorld, | 205 | world: ServerWorld, |
214 | params: req::TextDocumentPositionParams, | 206 | params: req::TextDocumentPositionParams, |
215 | _token: JobToken, | ||
216 | ) -> Result<Option<req::GotoDefinitionResponse>> { | 207 | ) -> Result<Option<req::GotoDefinitionResponse>> { |
217 | let file_id = params.text_document.try_conv_with(&world)?; | 208 | let file_id = params.text_document.try_conv_with(&world)?; |
218 | let line_index = world.analysis().file_line_index(file_id); | 209 | let line_index = world.analysis().file_line_index(file_id); |
@@ -232,7 +223,6 @@ pub fn handle_goto_definition( | |||
232 | pub fn handle_parent_module( | 223 | pub fn handle_parent_module( |
233 | world: ServerWorld, | 224 | world: ServerWorld, |
234 | params: TextDocumentIdentifier, | 225 | params: TextDocumentIdentifier, |
235 | _token: JobToken, | ||
236 | ) -> Result<Vec<Location>> { | 226 | ) -> Result<Vec<Location>> { |
237 | let file_id = params.try_conv_with(&world)?; | 227 | let file_id = params.try_conv_with(&world)?; |
238 | let mut res = Vec::new(); | 228 | let mut res = Vec::new(); |
@@ -247,7 +237,6 @@ pub fn handle_parent_module( | |||
247 | pub fn handle_runnables( | 237 | pub fn handle_runnables( |
248 | world: ServerWorld, | 238 | world: ServerWorld, |
249 | params: req::RunnablesParams, | 239 | params: req::RunnablesParams, |
250 | _token: JobToken, | ||
251 | ) -> Result<Vec<req::Runnable>> { | 240 | ) -> Result<Vec<req::Runnable>> { |
252 | let file_id = params.text_document.try_conv_with(&world)?; | 241 | let file_id = params.text_document.try_conv_with(&world)?; |
253 | let line_index = world.analysis().file_line_index(file_id); | 242 | let line_index = world.analysis().file_line_index(file_id); |
@@ -351,7 +340,6 @@ pub fn handle_runnables( | |||
351 | pub fn handle_decorations( | 340 | pub fn handle_decorations( |
352 | world: ServerWorld, | 341 | world: ServerWorld, |
353 | params: TextDocumentIdentifier, | 342 | params: TextDocumentIdentifier, |
354 | _token: JobToken, | ||
355 | ) -> Result<Vec<Decoration>> { | 343 | ) -> Result<Vec<Decoration>> { |
356 | let file_id = params.try_conv_with(&world)?; | 344 | let file_id = params.try_conv_with(&world)?; |
357 | highlight(&world, file_id) | 345 | highlight(&world, file_id) |
@@ -360,7 +348,6 @@ pub fn handle_decorations( | |||
360 | pub fn handle_completion( | 348 | pub fn handle_completion( |
361 | world: ServerWorld, | 349 | world: ServerWorld, |
362 | params: req::CompletionParams, | 350 | params: req::CompletionParams, |
363 | _token: JobToken, | ||
364 | ) -> Result<Option<req::CompletionResponse>> { | 351 | ) -> Result<Option<req::CompletionResponse>> { |
365 | let file_id = params.text_document.try_conv_with(&world)?; | 352 | let file_id = params.text_document.try_conv_with(&world)?; |
366 | let line_index = world.analysis().file_line_index(file_id); | 353 | let line_index = world.analysis().file_line_index(file_id); |
@@ -392,7 +379,6 @@ pub fn handle_completion( | |||
392 | pub fn handle_folding_range( | 379 | pub fn handle_folding_range( |
393 | world: ServerWorld, | 380 | world: ServerWorld, |
394 | params: FoldingRangeParams, | 381 | params: FoldingRangeParams, |
395 | _token: JobToken, | ||
396 | ) -> Result<Option<Vec<FoldingRange>>> { | 382 | ) -> Result<Option<Vec<FoldingRange>>> { |
397 | let file_id = params.text_document.try_conv_with(&world)?; | 383 | let file_id = params.text_document.try_conv_with(&world)?; |
398 | let line_index = world.analysis().file_line_index(file_id); | 384 | let line_index = world.analysis().file_line_index(file_id); |
@@ -425,7 +411,6 @@ pub fn handle_folding_range( | |||
425 | pub fn handle_signature_help( | 411 | pub fn handle_signature_help( |
426 | world: ServerWorld, | 412 | world: ServerWorld, |
427 | params: req::TextDocumentPositionParams, | 413 | params: req::TextDocumentPositionParams, |
428 | _token: JobToken, | ||
429 | ) -> Result<Option<req::SignatureHelp>> { | 414 | ) -> Result<Option<req::SignatureHelp>> { |
430 | use languageserver_types::{ParameterInformation, SignatureInformation}; | 415 | use languageserver_types::{ParameterInformation, SignatureInformation}; |
431 | 416 | ||
@@ -464,7 +449,6 @@ pub fn handle_signature_help( | |||
464 | pub fn handle_prepare_rename( | 449 | pub fn handle_prepare_rename( |
465 | world: ServerWorld, | 450 | world: ServerWorld, |
466 | params: req::TextDocumentPositionParams, | 451 | params: req::TextDocumentPositionParams, |
467 | _token: JobToken, | ||
468 | ) -> Result<Option<PrepareRenameResponse>> { | 452 | ) -> Result<Option<PrepareRenameResponse>> { |
469 | let file_id = params.text_document.try_conv_with(&world)?; | 453 | let file_id = params.text_document.try_conv_with(&world)?; |
470 | let line_index = world.analysis().file_line_index(file_id); | 454 | let line_index = world.analysis().file_line_index(file_id); |
@@ -486,7 +470,6 @@ pub fn handle_prepare_rename( | |||
486 | pub fn handle_rename( | 470 | pub fn handle_rename( |
487 | world: ServerWorld, | 471 | world: ServerWorld, |
488 | params: RenameParams, | 472 | params: RenameParams, |
489 | _token: JobToken, | ||
490 | ) -> Result<Option<WorkspaceEdit>> { | 473 | ) -> Result<Option<WorkspaceEdit>> { |
491 | let file_id = params.text_document.try_conv_with(&world)?; | 474 | let file_id = params.text_document.try_conv_with(&world)?; |
492 | let line_index = world.analysis().file_line_index(file_id); | 475 | let line_index = world.analysis().file_line_index(file_id); |
@@ -523,7 +506,6 @@ pub fn handle_rename( | |||
523 | pub fn handle_references( | 506 | pub fn handle_references( |
524 | world: ServerWorld, | 507 | world: ServerWorld, |
525 | params: req::ReferenceParams, | 508 | params: req::ReferenceParams, |
526 | _token: JobToken, | ||
527 | ) -> Result<Option<Vec<Location>>> { | 509 | ) -> Result<Option<Vec<Location>>> { |
528 | let file_id = params.text_document.try_conv_with(&world)?; | 510 | let file_id = params.text_document.try_conv_with(&world)?; |
529 | let line_index = world.analysis().file_line_index(file_id); | 511 | let line_index = world.analysis().file_line_index(file_id); |
@@ -539,7 +521,6 @@ pub fn handle_references( | |||
539 | pub fn handle_code_action( | 521 | pub fn handle_code_action( |
540 | world: ServerWorld, | 522 | world: ServerWorld, |
541 | params: req::CodeActionParams, | 523 | params: req::CodeActionParams, |
542 | _token: JobToken, | ||
543 | ) -> Result<Option<CodeActionResponse>> { | 524 | ) -> Result<Option<CodeActionResponse>> { |
544 | let file_id = params.text_document.try_conv_with(&world)?; | 525 | let file_id = params.text_document.try_conv_with(&world)?; |
545 | let line_index = world.analysis().file_line_index(file_id); | 526 | let line_index = world.analysis().file_line_index(file_id); |
diff --git a/crates/ra_lsp_server/src/main_loop/mod.rs b/crates/ra_lsp_server/src/main_loop/mod.rs index 165f2e78f..b35ebd38b 100644 --- a/crates/ra_lsp_server/src/main_loop/mod.rs +++ b/crates/ra_lsp_server/src/main_loop/mod.rs | |||
@@ -8,9 +8,9 @@ use gen_lsp_server::{ | |||
8 | handle_shutdown, ErrorCode, RawMessage, RawNotification, RawRequest, RawResponse, | 8 | handle_shutdown, ErrorCode, RawMessage, RawNotification, RawRequest, RawResponse, |
9 | }; | 9 | }; |
10 | use languageserver_types::NumberOrString; | 10 | use languageserver_types::NumberOrString; |
11 | use ra_analysis::{FileId, JobHandle, JobToken, LibraryData}; | 11 | use ra_analysis::{FileId, LibraryData}; |
12 | use rayon::{self, ThreadPool}; | 12 | use rayon::{self, ThreadPool}; |
13 | use rustc_hash::FxHashMap; | 13 | use rustc_hash::FxHashSet; |
14 | use serde::{de::DeserializeOwned, Serialize}; | 14 | use serde::{de::DeserializeOwned, Serialize}; |
15 | 15 | ||
16 | use crate::{ | 16 | use crate::{ |
@@ -47,7 +47,7 @@ pub fn main_loop( | |||
47 | info!("server initialized, serving requests"); | 47 | info!("server initialized, serving requests"); |
48 | let mut state = ServerWorldState::new(); | 48 | let mut state = ServerWorldState::new(); |
49 | 49 | ||
50 | let mut pending_requests = FxHashMap::default(); | 50 | let mut pending_requests = FxHashSet::default(); |
51 | let mut subs = Subscriptions::new(); | 51 | let mut subs = Subscriptions::new(); |
52 | let main_res = main_loop_inner( | 52 | let main_res = main_loop_inner( |
53 | internal_mode, | 53 | internal_mode, |
@@ -92,7 +92,7 @@ fn main_loop_inner( | |||
92 | fs_worker: Worker<PathBuf, (PathBuf, Vec<FileEvent>)>, | 92 | fs_worker: Worker<PathBuf, (PathBuf, Vec<FileEvent>)>, |
93 | ws_worker: Worker<PathBuf, Result<CargoWorkspace>>, | 93 | ws_worker: Worker<PathBuf, Result<CargoWorkspace>>, |
94 | state: &mut ServerWorldState, | 94 | state: &mut ServerWorldState, |
95 | pending_requests: &mut FxHashMap<u64, JobHandle>, | 95 | pending_requests: &mut FxHashSet<u64>, |
96 | subs: &mut Subscriptions, | 96 | subs: &mut Subscriptions, |
97 | ) -> Result<()> { | 97 | ) -> Result<()> { |
98 | let (libdata_sender, libdata_receiver) = unbounded(); | 98 | let (libdata_sender, libdata_receiver) = unbounded(); |
@@ -204,14 +204,13 @@ fn main_loop_inner( | |||
204 | fn on_task( | 204 | fn on_task( |
205 | task: Task, | 205 | task: Task, |
206 | msg_sender: &Sender<RawMessage>, | 206 | msg_sender: &Sender<RawMessage>, |
207 | pending_requests: &mut FxHashMap<u64, JobHandle>, | 207 | pending_requests: &mut FxHashSet<u64>, |
208 | ) { | 208 | ) { |
209 | match task { | 209 | match task { |
210 | Task::Respond(response) => { | 210 | Task::Respond(response) => { |
211 | if let Some(handle) = pending_requests.remove(&response.id) { | 211 | if pending_requests.remove(&response.id) { |
212 | assert!(handle.has_completed()); | 212 | msg_sender.send(RawMessage::Response(response)) |
213 | } | 213 | } |
214 | msg_sender.send(RawMessage::Response(response)) | ||
215 | } | 214 | } |
216 | Task::Notify(n) => msg_sender.send(RawMessage::Notification(n)), | 215 | Task::Notify(n) => msg_sender.send(RawMessage::Notification(n)), |
217 | } | 216 | } |
@@ -219,7 +218,7 @@ fn on_task( | |||
219 | 218 | ||
220 | fn on_request( | 219 | fn on_request( |
221 | world: &mut ServerWorldState, | 220 | world: &mut ServerWorldState, |
222 | pending_requests: &mut FxHashMap<u64, JobHandle>, | 221 | pending_requests: &mut FxHashSet<u64>, |
223 | pool: &ThreadPool, | 222 | pool: &ThreadPool, |
224 | sender: &Sender<Task>, | 223 | sender: &Sender<Task>, |
225 | req: RawRequest, | 224 | req: RawRequest, |
@@ -253,8 +252,8 @@ fn on_request( | |||
253 | .on::<req::References>(handlers::handle_references)? | 252 | .on::<req::References>(handlers::handle_references)? |
254 | .finish(); | 253 | .finish(); |
255 | match req { | 254 | match req { |
256 | Ok((id, handle)) => { | 255 | Ok(id) => { |
257 | let inserted = pending_requests.insert(id, handle).is_none(); | 256 | let inserted = pending_requests.insert(id); |
258 | assert!(inserted, "duplicate request: {}", id); | 257 | assert!(inserted, "duplicate request: {}", id); |
259 | Ok(None) | 258 | Ok(None) |
260 | } | 259 | } |
@@ -265,7 +264,7 @@ fn on_request( | |||
265 | fn on_notification( | 264 | fn on_notification( |
266 | msg_sender: &Sender<RawMessage>, | 265 | msg_sender: &Sender<RawMessage>, |
267 | state: &mut ServerWorldState, | 266 | state: &mut ServerWorldState, |
268 | pending_requests: &mut FxHashMap<u64, JobHandle>, | 267 | pending_requests: &mut FxHashSet<u64>, |
269 | subs: &mut Subscriptions, | 268 | subs: &mut Subscriptions, |
270 | not: RawNotification, | 269 | not: RawNotification, |
271 | ) -> Result<()> { | 270 | ) -> Result<()> { |
@@ -277,9 +276,7 @@ fn on_notification( | |||
277 | panic!("string id's not supported: {:?}", id); | 276 | panic!("string id's not supported: {:?}", id); |
278 | } | 277 | } |
279 | }; | 278 | }; |
280 | if let Some(handle) = pending_requests.remove(&id) { | 279 | pending_requests.remove(&id); |
281 | handle.cancel(); | ||
282 | } | ||
283 | return Ok(()); | 280 | return Ok(()); |
284 | } | 281 | } |
285 | Err(not) => not, | 282 | Err(not) => not, |
@@ -336,7 +333,7 @@ fn on_notification( | |||
336 | 333 | ||
337 | struct PoolDispatcher<'a> { | 334 | struct PoolDispatcher<'a> { |
338 | req: Option<RawRequest>, | 335 | req: Option<RawRequest>, |
339 | res: Option<(u64, JobHandle)>, | 336 | res: Option<u64>, |
340 | pool: &'a ThreadPool, | 337 | pool: &'a ThreadPool, |
341 | world: &'a ServerWorldState, | 338 | world: &'a ServerWorldState, |
342 | sender: &'a Sender<Task>, | 339 | sender: &'a Sender<Task>, |
@@ -345,7 +342,7 @@ struct PoolDispatcher<'a> { | |||
345 | impl<'a> PoolDispatcher<'a> { | 342 | impl<'a> PoolDispatcher<'a> { |
346 | fn on<'b, R>( | 343 | fn on<'b, R>( |
347 | &'b mut self, | 344 | &'b mut self, |
348 | f: fn(ServerWorld, R::Params, JobToken) -> Result<R::Result>, | 345 | f: fn(ServerWorld, R::Params) -> Result<R::Result>, |
349 | ) -> Result<&'b mut Self> | 346 | ) -> Result<&'b mut Self> |
350 | where | 347 | where |
351 | R: req::Request, | 348 | R: req::Request, |
@@ -358,11 +355,10 @@ impl<'a> PoolDispatcher<'a> { | |||
358 | }; | 355 | }; |
359 | match req.cast::<R>() { | 356 | match req.cast::<R>() { |
360 | Ok((id, params)) => { | 357 | Ok((id, params)) => { |
361 | let (handle, token) = JobHandle::new(); | ||
362 | let world = self.world.snapshot(); | 358 | let world = self.world.snapshot(); |
363 | let sender = self.sender.clone(); | 359 | let sender = self.sender.clone(); |
364 | self.pool.spawn(move || { | 360 | self.pool.spawn(move || { |
365 | let resp = match f(world, params, token) { | 361 | let resp = match f(world, params) { |
366 | Ok(resp) => RawResponse::ok::<R>(id, &resp), | 362 | Ok(resp) => RawResponse::ok::<R>(id, &resp), |
367 | Err(e) => { | 363 | Err(e) => { |
368 | RawResponse::err(id, ErrorCode::InternalError as i32, e.to_string()) | 364 | RawResponse::err(id, ErrorCode::InternalError as i32, e.to_string()) |
@@ -371,14 +367,14 @@ impl<'a> PoolDispatcher<'a> { | |||
371 | let task = Task::Respond(resp); | 367 | let task = Task::Respond(resp); |
372 | sender.send(task); | 368 | sender.send(task); |
373 | }); | 369 | }); |
374 | self.res = Some((id, handle)); | 370 | self.res = Some(id); |
375 | } | 371 | } |
376 | Err(req) => self.req = Some(req), | 372 | Err(req) => self.req = Some(req), |
377 | } | 373 | } |
378 | Ok(self) | 374 | Ok(self) |
379 | } | 375 | } |
380 | 376 | ||
381 | fn finish(&mut self) -> ::std::result::Result<(u64, JobHandle), RawRequest> { | 377 | fn finish(&mut self) -> ::std::result::Result<u64, RawRequest> { |
382 | match (self.res.take(), self.req.take()) { | 378 | match (self.res.take(), self.req.take()) { |
383 | (Some(res), None) => Ok(res), | 379 | (Some(res), None) => Ok(res), |
384 | (None, Some(req)) => Err(req), | 380 | (None, Some(req)) => Err(req), |