From 0102a01f76c855da447e25eb81191047a3ca79b8 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 20 Oct 2018 22:59:54 +0300 Subject: Remove job handle --- crates/ra_lsp_server/src/main_loop/handlers.rs | 21 +------------- crates/ra_lsp_server/src/main_loop/mod.rs | 38 ++++++++++++-------------- 2 files changed, 18 insertions(+), 41 deletions(-) (limited to 'crates/ra_lsp_server/src/main_loop') 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::{ InsertTextFormat, Location, Position, SymbolInformation, TextDocumentIdentifier, TextEdit, RenameParams, WorkspaceEdit, PrepareRenameResponse }; -use ra_analysis::{FileId, FoldKind, JobToken, Query, RunnableKind}; +use ra_analysis::{FileId, FoldKind, Query, RunnableKind}; use ra_syntax::text_utils::contains_offset_nonstrict; use serde_json::to_value; @@ -22,7 +22,6 @@ use crate::{ pub fn handle_syntax_tree( world: ServerWorld, params: req::SyntaxTreeParams, - _token: JobToken, ) -> Result { let id = params.text_document.try_conv_with(&world)?; let res = world.analysis().syntax_tree(id); @@ -32,7 +31,6 @@ pub fn handle_syntax_tree( pub fn handle_extend_selection( world: ServerWorld, params: req::ExtendSelectionParams, - _token: JobToken, ) -> Result { let file_id = params.text_document.try_conv_with(&world)?; let file = world.analysis().file_syntax(file_id); @@ -50,7 +48,6 @@ pub fn handle_extend_selection( pub fn handle_find_matching_brace( world: ServerWorld, params: req::FindMatchingBraceParams, - _token: JobToken, ) -> Result> { let file_id = params.text_document.try_conv_with(&world)?; let file = world.analysis().file_syntax(file_id); @@ -73,7 +70,6 @@ pub fn handle_find_matching_brace( pub fn handle_join_lines( world: ServerWorld, params: req::JoinLinesParams, - _token: JobToken, ) -> Result { let file_id = params.text_document.try_conv_with(&world)?; let line_index = world.analysis().file_line_index(file_id); @@ -87,7 +83,6 @@ pub fn handle_join_lines( pub fn handle_on_enter( world: ServerWorld, params: req::TextDocumentPositionParams, - _token: JobToken, ) -> Result> { let file_id = params.text_document.try_conv_with(&world)?; let line_index = world.analysis().file_line_index(file_id); @@ -101,7 +96,6 @@ pub fn handle_on_enter( pub fn handle_on_type_formatting( world: ServerWorld, params: req::DocumentOnTypeFormattingParams, - _token: JobToken, ) -> Result>> { if params.ch != "=" { return Ok(None); @@ -121,7 +115,6 @@ pub fn handle_on_type_formatting( pub fn handle_document_symbol( world: ServerWorld, params: req::DocumentSymbolParams, - _token: JobToken, ) -> Result> { let file_id = params.text_document.try_conv_with(&world)?; let line_index = world.analysis().file_line_index(file_id); @@ -160,7 +153,6 @@ pub fn handle_document_symbol( pub fn handle_workspace_symbol( world: ServerWorld, params: req::WorkspaceSymbolParams, - _token: JobToken, ) -> Result>> { let all_symbols = params.query.contains("#"); let libs = params.query.contains("*"); @@ -212,7 +204,6 @@ pub fn handle_workspace_symbol( pub fn handle_goto_definition( world: ServerWorld, params: req::TextDocumentPositionParams, - _token: JobToken, ) -> Result> { let file_id = params.text_document.try_conv_with(&world)?; let line_index = world.analysis().file_line_index(file_id); @@ -232,7 +223,6 @@ pub fn handle_goto_definition( pub fn handle_parent_module( world: ServerWorld, params: TextDocumentIdentifier, - _token: JobToken, ) -> Result> { let file_id = params.try_conv_with(&world)?; let mut res = Vec::new(); @@ -247,7 +237,6 @@ pub fn handle_parent_module( pub fn handle_runnables( world: ServerWorld, params: req::RunnablesParams, - _token: JobToken, ) -> Result> { let file_id = params.text_document.try_conv_with(&world)?; let line_index = world.analysis().file_line_index(file_id); @@ -351,7 +340,6 @@ pub fn handle_runnables( pub fn handle_decorations( world: ServerWorld, params: TextDocumentIdentifier, - _token: JobToken, ) -> Result> { let file_id = params.try_conv_with(&world)?; highlight(&world, file_id) @@ -360,7 +348,6 @@ pub fn handle_decorations( pub fn handle_completion( world: ServerWorld, params: req::CompletionParams, - _token: JobToken, ) -> Result> { let file_id = params.text_document.try_conv_with(&world)?; let line_index = world.analysis().file_line_index(file_id); @@ -392,7 +379,6 @@ pub fn handle_completion( pub fn handle_folding_range( world: ServerWorld, params: FoldingRangeParams, - _token: JobToken, ) -> Result>> { let file_id = params.text_document.try_conv_with(&world)?; let line_index = world.analysis().file_line_index(file_id); @@ -425,7 +411,6 @@ pub fn handle_folding_range( pub fn handle_signature_help( world: ServerWorld, params: req::TextDocumentPositionParams, - _token: JobToken, ) -> Result> { use languageserver_types::{ParameterInformation, SignatureInformation}; @@ -464,7 +449,6 @@ pub fn handle_signature_help( pub fn handle_prepare_rename( world: ServerWorld, params: req::TextDocumentPositionParams, - _token: JobToken, ) -> Result> { let file_id = params.text_document.try_conv_with(&world)?; let line_index = world.analysis().file_line_index(file_id); @@ -486,7 +470,6 @@ pub fn handle_prepare_rename( pub fn handle_rename( world: ServerWorld, params: RenameParams, - _token: JobToken, ) -> Result> { let file_id = params.text_document.try_conv_with(&world)?; let line_index = world.analysis().file_line_index(file_id); @@ -523,7 +506,6 @@ pub fn handle_rename( pub fn handle_references( world: ServerWorld, params: req::ReferenceParams, - _token: JobToken, ) -> Result>> { let file_id = params.text_document.try_conv_with(&world)?; let line_index = world.analysis().file_line_index(file_id); @@ -539,7 +521,6 @@ pub fn handle_references( pub fn handle_code_action( world: ServerWorld, params: req::CodeActionParams, - _token: JobToken, ) -> Result> { let file_id = params.text_document.try_conv_with(&world)?; 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::{ handle_shutdown, ErrorCode, RawMessage, RawNotification, RawRequest, RawResponse, }; use languageserver_types::NumberOrString; -use ra_analysis::{FileId, JobHandle, JobToken, LibraryData}; +use ra_analysis::{FileId, LibraryData}; use rayon::{self, ThreadPool}; -use rustc_hash::FxHashMap; +use rustc_hash::FxHashSet; use serde::{de::DeserializeOwned, Serialize}; use crate::{ @@ -47,7 +47,7 @@ pub fn main_loop( info!("server initialized, serving requests"); let mut state = ServerWorldState::new(); - let mut pending_requests = FxHashMap::default(); + let mut pending_requests = FxHashSet::default(); let mut subs = Subscriptions::new(); let main_res = main_loop_inner( internal_mode, @@ -92,7 +92,7 @@ fn main_loop_inner( fs_worker: Worker)>, ws_worker: Worker>, state: &mut ServerWorldState, - pending_requests: &mut FxHashMap, + pending_requests: &mut FxHashSet, subs: &mut Subscriptions, ) -> Result<()> { let (libdata_sender, libdata_receiver) = unbounded(); @@ -204,14 +204,13 @@ fn main_loop_inner( fn on_task( task: Task, msg_sender: &Sender, - pending_requests: &mut FxHashMap, + pending_requests: &mut FxHashSet, ) { match task { Task::Respond(response) => { - if let Some(handle) = pending_requests.remove(&response.id) { - assert!(handle.has_completed()); + if pending_requests.remove(&response.id) { + msg_sender.send(RawMessage::Response(response)) } - msg_sender.send(RawMessage::Response(response)) } Task::Notify(n) => msg_sender.send(RawMessage::Notification(n)), } @@ -219,7 +218,7 @@ fn on_task( fn on_request( world: &mut ServerWorldState, - pending_requests: &mut FxHashMap, + pending_requests: &mut FxHashSet, pool: &ThreadPool, sender: &Sender, req: RawRequest, @@ -253,8 +252,8 @@ fn on_request( .on::(handlers::handle_references)? .finish(); match req { - Ok((id, handle)) => { - let inserted = pending_requests.insert(id, handle).is_none(); + Ok(id) => { + let inserted = pending_requests.insert(id); assert!(inserted, "duplicate request: {}", id); Ok(None) } @@ -265,7 +264,7 @@ fn on_request( fn on_notification( msg_sender: &Sender, state: &mut ServerWorldState, - pending_requests: &mut FxHashMap, + pending_requests: &mut FxHashSet, subs: &mut Subscriptions, not: RawNotification, ) -> Result<()> { @@ -277,9 +276,7 @@ fn on_notification( panic!("string id's not supported: {:?}", id); } }; - if let Some(handle) = pending_requests.remove(&id) { - handle.cancel(); - } + pending_requests.remove(&id); return Ok(()); } Err(not) => not, @@ -336,7 +333,7 @@ fn on_notification( struct PoolDispatcher<'a> { req: Option, - res: Option<(u64, JobHandle)>, + res: Option, pool: &'a ThreadPool, world: &'a ServerWorldState, sender: &'a Sender, @@ -345,7 +342,7 @@ struct PoolDispatcher<'a> { impl<'a> PoolDispatcher<'a> { fn on<'b, R>( &'b mut self, - f: fn(ServerWorld, R::Params, JobToken) -> Result, + f: fn(ServerWorld, R::Params) -> Result, ) -> Result<&'b mut Self> where R: req::Request, @@ -358,11 +355,10 @@ impl<'a> PoolDispatcher<'a> { }; match req.cast::() { Ok((id, params)) => { - let (handle, token) = JobHandle::new(); let world = self.world.snapshot(); let sender = self.sender.clone(); self.pool.spawn(move || { - let resp = match f(world, params, token) { + let resp = match f(world, params) { Ok(resp) => RawResponse::ok::(id, &resp), Err(e) => { RawResponse::err(id, ErrorCode::InternalError as i32, e.to_string()) @@ -371,14 +367,14 @@ impl<'a> PoolDispatcher<'a> { let task = Task::Respond(resp); sender.send(task); }); - self.res = Some((id, handle)); + self.res = Some(id); } Err(req) => self.req = Some(req), } Ok(self) } - fn finish(&mut self) -> ::std::result::Result<(u64, JobHandle), RawRequest> { + fn finish(&mut self) -> ::std::result::Result { match (self.res.take(), self.req.take()) { (Some(res), None) => Ok(res), (None, Some(req)) => Err(req), -- cgit v1.2.3