From a6d39585d8a1cf260262e7f3e3c4741791582049 Mon Sep 17 00:00:00 2001 From: wojciechkepka Date: Fri, 18 Jun 2021 05:39:37 +0200 Subject: [PATCH] Add `work_done_token` as parameter to lsp methods --- helix-lsp/src/client.rs | 52 ++++++++++++++++++++------------------ helix-term/src/commands.rs | 14 +++++----- helix-view/src/document.rs | 9 ++++--- 3 files changed, 40 insertions(+), 35 deletions(-) diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs index 9ca708a75..0b52681cb 100644 --- a/helix-lsp/src/client.rs +++ b/helix-lsp/src/client.rs @@ -465,6 +465,7 @@ pub fn completion( &self, text_document: lsp::TextDocumentIdentifier, position: lsp::Position, + work_done_token: Option, ) -> impl Future> { // ) -> Result> { let params = lsp::CompletionParams { @@ -473,9 +474,7 @@ pub fn completion( position, }, // TODO: support these tokens by async receiving and updating the choice list - work_done_progress_params: lsp::WorkDoneProgressParams { - work_done_token: None, - }, + work_done_progress_params: lsp::WorkDoneProgressParams { work_done_token }, partial_result_params: lsp::PartialResultParams { partial_result_token: None, }, @@ -490,15 +489,14 @@ pub fn text_document_signature_help( &self, text_document: lsp::TextDocumentIdentifier, position: lsp::Position, + work_done_token: Option, ) -> impl Future> { let params = lsp::SignatureHelpParams { text_document_position_params: lsp::TextDocumentPositionParams { text_document, position, }, - work_done_progress_params: lsp::WorkDoneProgressParams { - work_done_token: None, - }, + work_done_progress_params: lsp::WorkDoneProgressParams { work_done_token }, context: None, // lsp::SignatureHelpContext }; @@ -510,15 +508,14 @@ pub fn text_document_hover( &self, text_document: lsp::TextDocumentIdentifier, position: lsp::Position, + work_done_token: Option, ) -> impl Future> { let params = lsp::HoverParams { text_document_position_params: lsp::TextDocumentPositionParams { text_document, position, }, - work_done_progress_params: lsp::WorkDoneProgressParams { - work_done_token: None, - }, + work_done_progress_params: lsp::WorkDoneProgressParams { work_done_token }, // lsp::SignatureHelpContext }; @@ -531,6 +528,7 @@ pub async fn text_document_formatting( &self, text_document: lsp::TextDocumentIdentifier, options: lsp::FormattingOptions, + work_done_token: Option, ) -> anyhow::Result> { let capabilities = self.capabilities.as_ref().unwrap(); @@ -545,9 +543,7 @@ pub async fn text_document_formatting( let params = lsp::DocumentFormattingParams { text_document, options, - work_done_progress_params: lsp::WorkDoneProgressParams { - work_done_token: None, - }, + work_done_progress_params: lsp::WorkDoneProgressParams { work_done_token }, }; let response = self.request::(params).await?; @@ -560,6 +556,7 @@ pub async fn text_document_range_formatting( text_document: lsp::TextDocumentIdentifier, range: lsp::Range, options: lsp::FormattingOptions, + work_done_token: Option, ) -> anyhow::Result> { let capabilities = self.capabilities.as_ref().unwrap(); @@ -575,9 +572,7 @@ pub async fn text_document_range_formatting( text_document, range, options, - work_done_progress_params: lsp::WorkDoneProgressParams { - work_done_token: None, - }, + work_done_progress_params: lsp::WorkDoneProgressParams { work_done_token }, }; let response = self @@ -596,15 +591,14 @@ fn goto_request< &self, text_document: lsp::TextDocumentIdentifier, position: lsp::Position, + work_done_token: Option, ) -> impl Future> { let params = lsp::GotoDefinitionParams { text_document_position_params: lsp::TextDocumentPositionParams { text_document, position, }, - work_done_progress_params: lsp::WorkDoneProgressParams { - work_done_token: None, - }, + work_done_progress_params: lsp::WorkDoneProgressParams { work_done_token }, partial_result_params: lsp::PartialResultParams { partial_result_token: None, }, @@ -617,30 +611,42 @@ pub fn goto_definition( &self, text_document: lsp::TextDocumentIdentifier, position: lsp::Position, + work_done_token: Option, ) -> impl Future> { - self.goto_request::(text_document, position) + self.goto_request::(text_document, position, work_done_token) } pub fn goto_type_definition( &self, text_document: lsp::TextDocumentIdentifier, position: lsp::Position, + work_done_token: Option, ) -> impl Future> { - self.goto_request::(text_document, position) + self.goto_request::( + text_document, + position, + work_done_token, + ) } pub fn goto_implementation( &self, text_document: lsp::TextDocumentIdentifier, position: lsp::Position, + work_done_token: Option, ) -> impl Future> { - self.goto_request::(text_document, position) + self.goto_request::( + text_document, + position, + work_done_token, + ) } pub fn goto_reference( &self, text_document: lsp::TextDocumentIdentifier, position: lsp::Position, + work_done_token: Option, ) -> impl Future> { let params = lsp::ReferenceParams { text_document_position: lsp::TextDocumentPositionParams { @@ -650,9 +656,7 @@ pub fn goto_reference( context: lsp::ReferenceContext { include_declaration: true, }, - work_done_progress_params: lsp::WorkDoneProgressParams { - work_done_token: None, - }, + work_done_progress_params: lsp::WorkDoneProgressParams { work_done_token }, partial_result_params: lsp::PartialResultParams { partial_result_token: None, }, diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index b2dd0d11e..9b916a5e7 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1852,7 +1852,7 @@ fn goto_definition(cx: &mut Context) { let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor(), offset_encoding); // TODO: handle fails - let future = language_server.goto_definition(doc.identifier(), pos); + let future = language_server.goto_definition(doc.identifier(), pos, None); cx.callback( future, @@ -1889,7 +1889,7 @@ fn goto_type_definition(cx: &mut Context) { let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor(), offset_encoding); // TODO: handle fails - let future = language_server.goto_type_definition(doc.identifier(), pos); + let future = language_server.goto_type_definition(doc.identifier(), pos, None); cx.callback( future, @@ -1926,7 +1926,7 @@ fn goto_implementation(cx: &mut Context) { let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor(), offset_encoding); // TODO: handle fails - let future = language_server.goto_implementation(doc.identifier(), pos); + let future = language_server.goto_implementation(doc.identifier(), pos, None); cx.callback( future, @@ -1963,7 +1963,7 @@ fn goto_reference(cx: &mut Context) { let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor(), offset_encoding); // TODO: handle fails - let future = language_server.goto_reference(doc.identifier(), pos); + let future = language_server.goto_reference(doc.identifier(), pos, None); cx.callback( future, @@ -2075,7 +2075,7 @@ fn signature_help(cx: &mut Context) { ); // TODO: handle fails - let future = language_server.text_document_signature_help(doc.identifier(), pos); + let future = language_server.text_document_signature_help(doc.identifier(), pos, None); cx.callback( future, @@ -2718,7 +2718,7 @@ fn completion(cx: &mut Context) { let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor(), offset_encoding); // TODO: handle fails - let future = language_server.completion(doc.identifier(), pos); + let future = language_server.completion(doc.identifier(), pos, None); let trigger_offset = doc.selection(view.id).cursor(); @@ -2776,7 +2776,7 @@ fn hover(cx: &mut Context) { ); // TODO: handle fails - let future = language_server.text_document_hover(doc.identifier(), pos); + let future = language_server.text_document_hover(doc.identifier(), pos, None); cx.callback( future, diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index fe9c87f74..e9a8097ca 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -263,10 +263,11 @@ pub fn load(path: PathBuf) -> Result { pub fn format(&mut self, view_id: ViewId) { if let Some(language_server) = self.language_server() { // TODO: await, no blocking - let transaction = helix_lsp::block_on( - language_server - .text_document_formatting(self.identifier(), lsp::FormattingOptions::default()), - ) + let transaction = helix_lsp::block_on(language_server.text_document_formatting( + self.identifier(), + lsp::FormattingOptions::default(), + None, + )) .map(|edits| { helix_lsp::util::generate_transaction_from_edits( self.text(),