Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-lsp/src/client.rs')
-rw-r--r--helix-lsp/src/client.rs380
1 files changed, 175 insertions, 205 deletions
diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs
index 22a8dd89..28a1bd09 100644
--- a/helix-lsp/src/client.rs
+++ b/helix-lsp/src/client.rs
@@ -10,20 +10,17 @@ use crate::lsp::{
DidChangeWorkspaceFoldersParams, OneOf, PositionEncodingKind, SignatureHelp, Url,
WorkspaceFolder, WorkspaceFoldersChangeEvent,
};
-use helix_core::{find_workspace, syntax::config::LanguageServerFeature, ChangeSet, Rope};
+use helix_core::{find_workspace, syntax::LanguageServerFeature, ChangeSet, Rope};
use helix_loader::VERSION_AND_GIT_HASH;
use helix_stdx::path;
use parking_lot::Mutex;
use serde::Deserialize;
use serde_json::Value;
-use std::{collections::HashMap, path::PathBuf};
-use std::{
- ffi::OsStr,
- sync::{
- atomic::{AtomicU64, Ordering},
- Arc,
- },
+use std::sync::{
+ atomic::{AtomicU64, Ordering},
+ Arc,
};
+use std::{collections::HashMap, path::PathBuf};
use std::{future::Future, sync::OnceLock};
use std::{path::Path, process::Stdio};
use tokio::{
@@ -39,7 +36,7 @@ fn workspace_for_uri(uri: lsp::Url) -> WorkspaceFolder {
lsp::WorkspaceFolder {
name: uri
.path_segments()
- .and_then(|mut segments| segments.next_back())
+ .and_then(|segments| segments.last())
.map(|basename| basename.to_string())
.unwrap_or_default(),
uri,
@@ -88,7 +85,7 @@ impl Client {
.and_then(|root| lsp::Url::from_file_path(root).ok());
if self.root_path == root.unwrap_or(workspace)
- || root_uri.as_ref().is_some_and(|root_uri| {
+ || root_uri.as_ref().map_or(false, |root_uri| {
self.workspace_folders
.lock()
.iter()
@@ -173,30 +170,7 @@ impl Client {
// and that we can therefore reuse the client (but are done now)
return;
}
- self.did_change_workspace(vec![workspace_for_uri(root_uri)], Vec::new())
- }
-
- /// Merge FormattingOptions with 'config.format' and return it
- fn get_merged_formatting_options(
- &self,
- options: lsp::FormattingOptions,
- ) -> lsp::FormattingOptions {
- let config_format = self
- .config
- .as_ref()
- .and_then(|cfg| cfg.get("format"))
- .and_then(|fmt| HashMap::<String, lsp::FormattingProperty>::deserialize(fmt).ok());
-
- if let Some(mut properties) = config_format {
- // passed in options take precedence over 'config.format'
- properties.extend(options.properties);
- lsp::FormattingOptions {
- properties,
- ..options
- }
- } else {
- options
- }
+ tokio::spawn(self.did_change_workspace(vec![workspace_for_uri(root_uri)], Vec::new()));
}
#[allow(clippy::type_complexity, clippy::too_many_arguments)]
@@ -204,7 +178,7 @@ impl Client {
cmd: &str,
args: &[String],
config: Option<Value>,
- server_environment: impl IntoIterator<Item = (impl AsRef<OsStr>, impl AsRef<OsStr>)>,
+ server_environment: HashMap<String, String>,
root_path: PathBuf,
root_uri: Option<lsp::Url>,
id: LanguageServerId,
@@ -224,7 +198,6 @@ impl Client {
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
- .current_dir(&root_path)
// make sure the process is reaped on drop
.kill_on_drop(true)
.spawn();
@@ -372,7 +345,6 @@ impl Client {
Some(OneOf::Left(true) | OneOf::Right(_))
),
LanguageServerFeature::Diagnostics => true, // there's no extra server capability
- LanguageServerFeature::PullDiagnostics => capabilities.diagnostic_provider.is_some(),
LanguageServerFeature::RenameSymbol => matches!(
capabilities.rename_provider,
Some(OneOf::Left(true)) | Some(OneOf::Right(_))
@@ -381,14 +353,6 @@ impl Client {
capabilities.inlay_hint_provider,
Some(OneOf::Left(true) | OneOf::Right(InlayHintServerCapabilities::Options(_)))
),
- LanguageServerFeature::DocumentColors => matches!(
- capabilities.color_provider,
- Some(
- ColorProviderCapability::Simple(true)
- | ColorProviderCapability::ColorProvider(_)
- | ColorProviderCapability::Options(_)
- )
- ),
}
}
@@ -419,10 +383,22 @@ impl Client {
}
/// Execute a RPC request on the language server.
+ async fn request<R: lsp::request::Request>(&self, params: R::Params) -> Result<R::Result>
+ where
+ R::Params: serde::Serialize,
+ R::Result: core::fmt::Debug, // TODO: temporary
+ {
+ // a future that resolves into the response
+ let json = self.call::<R>(params).await?;
+ let response = serde_json::from_value(json)?;
+ Ok(response)
+ }
+
+ /// Execute a RPC request on the language server.
fn call<R: lsp::request::Request>(
&self,
params: R::Params,
- ) -> impl Future<Output = Result<R::Result>>
+ ) -> impl Future<Output = Result<Value>>
where
R::Params: serde::Serialize,
{
@@ -432,7 +408,7 @@ impl Client {
fn call_with_ref<R: lsp::request::Request>(
&self,
params: &R::Params,
- ) -> impl Future<Output = Result<R::Result>>
+ ) -> impl Future<Output = Result<Value>>
where
R::Params: serde::Serialize,
{
@@ -443,15 +419,15 @@ impl Client {
&self,
params: &R::Params,
timeout_secs: u64,
- ) -> impl Future<Output = Result<R::Result>>
+ ) -> impl Future<Output = Result<Value>>
where
R::Params: serde::Serialize,
{
let server_tx = self.server_tx.clone();
let id = self.next_request_id();
- // It's important that this is not part of the future so that it gets executed right away
- // and the request order stays consistent.
+ // it' important this is not part of the future so that it gets
+ // executed right away so that the request order stays concisents
let rx = serde_json::to_value(params)
.map_err(Error::from)
.and_then(|params| {
@@ -479,42 +455,38 @@ impl Client {
.await
.map_err(|_| Error::Timeout(id))? // return Timeout
.ok_or(Error::StreamClosed)?
- .and_then(|value| serde_json::from_value(value).map_err(Into::into))
}
}
/// Send a RPC notification to the language server.
- pub fn notify<R: lsp::notification::Notification>(&self, params: R::Params)
+ pub fn notify<R: lsp::notification::Notification>(
+ &self,
+ params: R::Params,
+ ) -> impl Future<Output = Result<()>>
where
R::Params: serde::Serialize,
{
let server_tx = self.server_tx.clone();
- let params = match serde_json::to_value(params) {
- Ok(params) => params,
- Err(err) => {
- log::error!(
- "Failed to serialize params for notification '{}' for server '{}': {err}",
- R::METHOD,
- self.name,
- );
- return;
- }
- };
-
- let notification = jsonrpc::Notification {
- jsonrpc: Some(jsonrpc::Version::V2),
- method: R::METHOD.to_string(),
- params: Self::value_into_params(params),
- };
+ // it' important this is not part of the future so that it gets
+ // executed right away so that the request order stays consisents
+ let res = serde_json::to_value(params)
+ .map_err(Error::from)
+ .and_then(|params| {
+ let params = serde_json::to_value(params)?;
- if let Err(err) = server_tx.send(Payload::Notification(notification)) {
- log::error!(
- "Failed to send notification '{}' to server '{}': {err}",
- R::METHOD,
- self.name
- );
- }
+ let notification = jsonrpc::Notification {
+ jsonrpc: Some(jsonrpc::Version::V2),
+ method: R::METHOD.to_string(),
+ params: Self::value_into_params(params),
+ };
+ server_tx
+ .send(Payload::Notification(notification))
+ .map_err(|e| Error::Other(e.into()))
+ });
+ // TODO: this function is not async and never should have been
+ // but turning it into non-async function is a big refactor
+ async move { res }
}
/// Reply to a language server RPC call.
@@ -522,29 +494,32 @@ impl Client {
&self,
id: jsonrpc::Id,
result: core::result::Result<Value, jsonrpc::Error>,
- ) -> Result<()> {
+ ) -> impl Future<Output = Result<()>> {
use jsonrpc::{Failure, Output, Success, Version};
let server_tx = self.server_tx.clone();
let output = match result {
- Ok(result) => Output::Success(Success {
- jsonrpc: Some(Version::V2),
- id,
- result,
+ Ok(result) => serde_json::to_value(result).map(|result| {
+ Output::Success(Success {
+ jsonrpc: Some(Version::V2),
+ id,
+ result,
+ })
}),
- Err(error) => Output::Failure(Failure {
+ Err(error) => Ok(Output::Failure(Failure {
jsonrpc: Some(Version::V2),
id,
error,
- }),
+ })),
};
- server_tx
- .send(Payload::Response(output))
- .map_err(|e| Error::Other(e.into()))?;
-
- Ok(())
+ let res = output.map_err(Error::from).and_then(|output| {
+ server_tx
+ .send(Payload::Response(output))
+ .map_err(|e| Error::Other(e.into()))
+ });
+ async move { res }
}
// -------------------------------------------------------------------------------------------
@@ -603,9 +578,6 @@ impl Client {
did_rename: Some(true),
..Default::default()
}),
- diagnostic: Some(lsp::DiagnosticWorkspaceClientCapabilities {
- refresh_support: Some(true),
- }),
..Default::default()
}),
text_document: Some(lsp::TextDocumentClientCapabilities {
@@ -683,10 +655,6 @@ impl Client {
}),
..Default::default()
}),
- diagnostic: Some(lsp::DiagnosticClientCapabilities {
- dynamic_registration: Some(false),
- related_document_support: Some(true),
- }),
publish_diagnostics: Some(lsp::PublishDiagnosticsClientCapabilities {
version_support: Some(true),
tag_support: Some(lsp::TagSupport {
@@ -726,14 +694,14 @@ impl Client {
work_done_progress_params: lsp::WorkDoneProgressParams::default(),
};
- self.call::<lsp::request::Initialize>(params).await
+ self.request::<lsp::request::Initialize>(params).await
}
pub async fn shutdown(&self) -> Result<()> {
- self.call::<lsp::request::Shutdown>(()).await
+ self.request::<lsp::request::Shutdown>(()).await
}
- pub fn exit(&self) {
+ pub fn exit(&self) -> impl Future<Output = Result<()>> {
self.notify::<lsp::notification::Exit>(())
}
@@ -741,8 +709,7 @@ impl Client {
/// early if server responds with an error.
pub async fn shutdown_and_exit(&self) -> Result<()> {
self.shutdown().await?;
- self.exit();
- Ok(())
+ self.exit().await
}
/// Forcefully shuts down the language server ignoring any errors.
@@ -750,21 +717,24 @@ impl Client {
if let Err(e) = self.shutdown().await {
log::warn!("language server failed to terminate gracefully - {}", e);
}
- self.exit();
- Ok(())
+ self.exit().await
}
// -------------------------------------------------------------------------------------------
// Workspace
// -------------------------------------------------------------------------------------------
- pub fn did_change_configuration(&self, settings: Value) {
+ pub fn did_change_configuration(&self, settings: Value) -> impl Future<Output = Result<()>> {
self.notify::<lsp::notification::DidChangeConfiguration>(
lsp::DidChangeConfigurationParams { settings },
)
}
- pub fn did_change_workspace(&self, added: Vec<WorkspaceFolder>, removed: Vec<WorkspaceFolder>) {
+ pub fn did_change_workspace(
+ &self,
+ added: Vec<WorkspaceFolder>,
+ removed: Vec<WorkspaceFolder>,
+ ) -> impl Future<Output = Result<()>> {
self.notify::<DidChangeWorkspaceFolders>(DidChangeWorkspaceFoldersParams {
event: WorkspaceFoldersChangeEvent { added, removed },
})
@@ -775,7 +745,7 @@ impl Client {
old_path: &Path,
new_path: &Path,
is_dir: bool,
- ) -> Option<impl Future<Output = Result<Option<lsp::WorkspaceEdit>>>> {
+ ) -> Option<impl Future<Output = Result<lsp::WorkspaceEdit>>> {
let capabilities = self.file_operations_intests();
if !capabilities.will_rename.has_interest(old_path, is_dir) {
return None;
@@ -792,13 +762,24 @@ impl Client {
old_uri: url_from_path(old_path)?,
new_uri: url_from_path(new_path)?,
}];
- Some(self.call_with_timeout::<lsp::request::WillRenameFiles>(
+ let request = self.call_with_timeout::<lsp::request::WillRenameFiles>(
&lsp::RenameFilesParams { files },
5,
- ))
+ );
+
+ Some(async move {
+ let json = request.await?;
+ let response: Option<lsp::WorkspaceEdit> = serde_json::from_value(json)?;
+ Ok(response.unwrap_or_default())
+ })
}
- pub fn did_rename(&self, old_path: &Path, new_path: &Path, is_dir: bool) -> Option<()> {
+ pub fn did_rename(
+ &self,
+ old_path: &Path,
+ new_path: &Path,
+ is_dir: bool,
+ ) -> Option<impl Future<Output = std::result::Result<(), Error>>> {
let capabilities = self.file_operations_intests();
if !capabilities.did_rename.has_interest(new_path, is_dir) {
return None;
@@ -816,8 +797,7 @@ impl Client {
old_uri: url_from_path(old_path)?,
new_uri: url_from_path(new_path)?,
}];
- self.notify::<lsp::notification::DidRenameFiles>(lsp::RenameFilesParams { files });
- Some(())
+ Some(self.notify::<lsp::notification::DidRenameFiles>(lsp::RenameFilesParams { files }))
}
// -------------------------------------------------------------------------------------------
@@ -830,7 +810,7 @@ impl Client {
version: i32,
doc: &Rope,
language_id: String,
- ) {
+ ) -> impl Future<Output = Result<()>> {
self.notify::<lsp::notification::DidOpenTextDocument>(lsp::DidOpenTextDocumentParams {
text_document: lsp::TextDocumentItem {
uri,
@@ -957,7 +937,7 @@ impl Client {
old_text: &Rope,
new_text: &Rope,
changes: &ChangeSet,
- ) -> Option<()> {
+ ) -> Option<impl Future<Output = Result<()>>> {
let capabilities = self.capabilities.get().unwrap();
// Return early if the server does not support document sync.
@@ -989,14 +969,18 @@ impl Client {
kind => unimplemented!("{:?}", kind),
};
- self.notify::<lsp::notification::DidChangeTextDocument>(lsp::DidChangeTextDocumentParams {
- text_document,
- content_changes: changes,
- });
- Some(())
+ Some(self.notify::<lsp::notification::DidChangeTextDocument>(
+ lsp::DidChangeTextDocumentParams {
+ text_document,
+ content_changes: changes,
+ },
+ ))
}
- pub fn text_document_did_close(&self, text_document: lsp::TextDocumentIdentifier) {
+ pub fn text_document_did_close(
+ &self,
+ text_document: lsp::TextDocumentIdentifier,
+ ) -> impl Future<Output = Result<()>> {
self.notify::<lsp::notification::DidCloseTextDocument>(lsp::DidCloseTextDocumentParams {
text_document,
})
@@ -1008,7 +992,7 @@ impl Client {
&self,
text_document: lsp::TextDocumentIdentifier,
text: &Rope,
- ) -> Option<()> {
+ ) -> Option<impl Future<Output = Result<()>>> {
let capabilities = self.capabilities.get().unwrap();
let include_text = match &capabilities.text_document_sync.as_ref()? {
@@ -1026,11 +1010,12 @@ impl Client {
lsp::TextDocumentSyncCapability::Kind(..) => false,
};
- self.notify::<lsp::notification::DidSaveTextDocument>(lsp::DidSaveTextDocumentParams {
- text_document,
- text: include_text.then_some(text.into()),
- });
- Some(())
+ Some(self.notify::<lsp::notification::DidSaveTextDocument>(
+ lsp::DidSaveTextDocumentParams {
+ text_document,
+ text: include_text.then_some(text.into()),
+ },
+ ))
}
pub fn completion(
@@ -1039,7 +1024,7 @@ impl Client {
position: lsp::Position,
work_done_token: Option<lsp::ProgressToken>,
context: lsp::CompletionContext,
- ) -> Option<impl Future<Output = Result<Option<lsp::CompletionResponse>>>> {
+ ) -> Option<impl Future<Output = Result<Value>>> {
let capabilities = self.capabilities.get().unwrap();
// Return early if the server does not support completion.
@@ -1065,13 +1050,14 @@ impl Client {
&self,
completion_item: &lsp::CompletionItem,
) -> impl Future<Output = Result<lsp::CompletionItem>> {
- self.call_with_ref::<lsp::request::ResolveCompletionItem>(completion_item)
+ let res = self.call_with_ref::<lsp::request::ResolveCompletionItem>(completion_item);
+ async move { Ok(serde_json::from_value(res.await?)?) }
}
pub fn resolve_code_action(
&self,
- code_action: &lsp::CodeAction,
- ) -> Option<impl Future<Output = Result<lsp::CodeAction>>> {
+ code_action: lsp::CodeAction,
+ ) -> Option<impl Future<Output = Result<Value>>> {
let capabilities = self.capabilities.get().unwrap();
// Return early if the server does not support resolving code actions.
@@ -1083,7 +1069,7 @@ impl Client {
_ => return None,
}
- Some(self.call_with_ref::<lsp::request::CodeActionResolveRequest>(code_action))
+ Some(self.call::<lsp::request::CodeActionResolveRequest>(code_action))
}
pub fn text_document_signature_help(
@@ -1107,7 +1093,8 @@ impl Client {
// lsp::SignatureHelpContext
};
- Some(self.call::<lsp::request::SignatureHelpRequest>(params))
+ let res = self.call::<lsp::request::SignatureHelpRequest>(params);
+ Some(async move { Ok(serde_json::from_value(res.await?)?) })
}
pub fn text_document_range_inlay_hints(
@@ -1115,7 +1102,7 @@ impl Client {
text_document: lsp::TextDocumentIdentifier,
range: lsp::Range,
work_done_token: Option<lsp::ProgressToken>,
- ) -> Option<impl Future<Output = Result<Option<Vec<lsp::InlayHint>>>>> {
+ ) -> Option<impl Future<Output = Result<Value>>> {
let capabilities = self.capabilities.get().unwrap();
match capabilities.inlay_hint_provider {
@@ -1135,31 +1122,12 @@ impl Client {
Some(self.call::<lsp::request::InlayHintRequest>(params))
}
- pub fn text_document_document_color(
- &self,
- text_document: lsp::TextDocumentIdentifier,
- work_done_token: Option<lsp::ProgressToken>,
- ) -> Option<impl Future<Output = Result<Vec<lsp::ColorInformation>>>> {
- self.capabilities.get().unwrap().color_provider.as_ref()?;
- let params = lsp::DocumentColorParams {
- text_document,
- work_done_progress_params: lsp::WorkDoneProgressParams {
- work_done_token: work_done_token.clone(),
- },
- partial_result_params: helix_lsp_types::PartialResultParams {
- partial_result_token: work_done_token,
- },
- };
-
- Some(self.call::<lsp::request::DocumentColor>(params))
- }
-
pub fn text_document_hover(
&self,
text_document: lsp::TextDocumentIdentifier,
position: lsp::Position,
work_done_token: Option<lsp::ProgressToken>,
- ) -> Option<impl Future<Output = Result<Option<lsp::Hover>>>> {
+ ) -> Option<impl Future<Output = Result<Value>>> {
let capabilities = self.capabilities.get().unwrap();
// Return early if the server does not support hover.
@@ -1190,7 +1158,7 @@ impl Client {
text_document: lsp::TextDocumentIdentifier,
options: lsp::FormattingOptions,
work_done_token: Option<lsp::ProgressToken>,
- ) -> Option<impl Future<Output = Result<Option<Vec<lsp::TextEdit>>>>> {
+ ) -> Option<impl Future<Output = Result<Vec<lsp::TextEdit>>>> {
let capabilities = self.capabilities.get().unwrap();
// Return early if the server does not support formatting.
@@ -1199,7 +1167,23 @@ impl Client {
_ => return None,
};
- let options = self.get_merged_formatting_options(options);
+ // merge FormattingOptions with 'config.format'
+ let config_format = self
+ .config
+ .as_ref()
+ .and_then(|cfg| cfg.get("format"))
+ .and_then(|fmt| HashMap::<String, lsp::FormattingProperty>::deserialize(fmt).ok());
+
+ let options = if let Some(mut properties) = config_format {
+ // passed in options take precedence over 'config.format'
+ properties.extend(options.properties);
+ lsp::FormattingOptions {
+ properties,
+ ..options
+ }
+ } else {
+ options
+ };
let params = lsp::DocumentFormattingParams {
text_document,
@@ -1207,7 +1191,13 @@ impl Client {
work_done_progress_params: lsp::WorkDoneProgressParams { work_done_token },
};
- Some(self.call::<lsp::request::Formatting>(params))
+ let request = self.call::<lsp::request::Formatting>(params);
+
+ Some(async move {
+ let json = request.await?;
+ let response: Option<Vec<lsp::TextEdit>> = serde_json::from_value(json)?;
+ Ok(response.unwrap_or_default())
+ })
}
pub fn text_document_range_formatting(
@@ -1216,7 +1206,7 @@ impl Client {
range: lsp::Range,
options: lsp::FormattingOptions,
work_done_token: Option<lsp::ProgressToken>,
- ) -> Option<impl Future<Output = Result<Option<Vec<lsp::TextEdit>>>>> {
+ ) -> Option<impl Future<Output = Result<Vec<lsp::TextEdit>>>> {
let capabilities = self.capabilities.get().unwrap();
// Return early if the server does not support range formatting.
@@ -1225,8 +1215,6 @@ impl Client {
_ => return None,
};
- let options = self.get_merged_formatting_options(options);
-
let params = lsp::DocumentRangeFormattingParams {
text_document,
range,
@@ -1234,33 +1222,13 @@ impl Client {
work_done_progress_params: lsp::WorkDoneProgressParams { work_done_token },
};
- Some(self.call::<lsp::request::RangeFormatting>(params))
- }
+ let request = self.call::<lsp::request::RangeFormatting>(params);
- pub fn text_document_diagnostic(
- &self,
- text_document: lsp::TextDocumentIdentifier,
- previous_result_id: Option<String>,
- ) -> Option<impl Future<Output = Result<lsp::DocumentDiagnosticReportResult>>> {
- let capabilities = self.capabilities();
-
- // Return early if the server does not support pull diagnostic.
- let identifier = match capabilities.diagnostic_provider.as_ref()? {
- lsp::DiagnosticServerCapabilities::Options(cap) => cap.identifier.clone(),
- lsp::DiagnosticServerCapabilities::RegistrationOptions(cap) => {
- cap.diagnostic_options.identifier.clone()
- }
- };
-
- let params = lsp::DocumentDiagnosticParams {
- text_document,
- identifier,
- previous_result_id,
- work_done_progress_params: lsp::WorkDoneProgressParams::default(),
- partial_result_params: lsp::PartialResultParams::default(),
- };
-
- Some(self.call::<lsp::request::DocumentDiagnosticRequest>(params))
+ Some(async move {
+ let json = request.await?;
+ let response: Option<Vec<lsp::TextEdit>> = serde_json::from_value(json)?;
+ Ok(response.unwrap_or_default())
+ })
}
pub fn text_document_document_highlight(
@@ -1268,7 +1236,7 @@ impl Client {
text_document: lsp::TextDocumentIdentifier,
position: lsp::Position,
work_done_token: Option<lsp::ProgressToken>,
- ) -> Option<impl Future<Output = Result<Option<Vec<lsp::DocumentHighlight>>>>> {
+ ) -> Option<impl Future<Output = Result<Value>>> {
let capabilities = self.capabilities.get().unwrap();
// Return early if the server does not support document highlight.
@@ -1301,7 +1269,7 @@ impl Client {
text_document: lsp::TextDocumentIdentifier,
position: lsp::Position,
work_done_token: Option<lsp::ProgressToken>,
- ) -> impl Future<Output = Result<T::Result>> {
+ ) -> impl Future<Output = Result<Value>> {
let params = lsp::GotoDefinitionParams {
text_document_position_params: lsp::TextDocumentPositionParams {
text_document,
@@ -1321,7 +1289,7 @@ impl Client {
text_document: lsp::TextDocumentIdentifier,
position: lsp::Position,
work_done_token: Option<lsp::ProgressToken>,
- ) -> Option<impl Future<Output = Result<Option<lsp::GotoDefinitionResponse>>>> {
+ ) -> Option<impl Future<Output = Result<Value>>> {
let capabilities = self.capabilities.get().unwrap();
// Return early if the server does not support goto-definition.
@@ -1342,7 +1310,7 @@ impl Client {
text_document: lsp::TextDocumentIdentifier,
position: lsp::Position,
work_done_token: Option<lsp::ProgressToken>,
- ) -> Option<impl Future<Output = Result<Option<lsp::GotoDefinitionResponse>>>> {
+ ) -> Option<impl Future<Output = Result<Value>>> {
let capabilities = self.capabilities.get().unwrap();
// Return early if the server does not support goto-declaration.
@@ -1367,7 +1335,7 @@ impl Client {
text_document: lsp::TextDocumentIdentifier,
position: lsp::Position,
work_done_token: Option<lsp::ProgressToken>,
- ) -> Option<impl Future<Output = Result<Option<lsp::GotoDefinitionResponse>>>> {
+ ) -> Option<impl Future<Output = Result<Value>>> {
let capabilities = self.capabilities.get().unwrap();
// Return early if the server does not support goto-type-definition.
@@ -1391,7 +1359,7 @@ impl Client {
text_document: lsp::TextDocumentIdentifier,
position: lsp::Position,
work_done_token: Option<lsp::ProgressToken>,
- ) -> Option<impl Future<Output = Result<Option<lsp::GotoDefinitionResponse>>>> {
+ ) -> Option<impl Future<Output = Result<Value>>> {
let capabilities = self.capabilities.get().unwrap();
// Return early if the server does not support goto-definition.
@@ -1416,7 +1384,7 @@ impl Client {
position: lsp::Position,
include_declaration: bool,
work_done_token: Option<lsp::ProgressToken>,
- ) -> Option<impl Future<Output = Result<Option<Vec<lsp::Location>>>>> {
+ ) -> Option<impl Future<Output = Result<Value>>> {
let capabilities = self.capabilities.get().unwrap();
// Return early if the server does not support goto-reference.
@@ -1445,7 +1413,7 @@ impl Client {
pub fn document_symbols(
&self,
text_document: lsp::TextDocumentIdentifier,
- ) -> Option<impl Future<Output = Result<Option<lsp::DocumentSymbolResponse>>>> {
+ ) -> Option<impl Future<Output = Result<Value>>> {
let capabilities = self.capabilities.get().unwrap();
// Return early if the server does not support document symbols.
@@ -1467,7 +1435,7 @@ impl Client {
&self,
text_document: lsp::TextDocumentIdentifier,
position: lsp::Position,
- ) -> Option<impl Future<Output = Result<Option<lsp::PrepareRenameResponse>>>> {
+ ) -> Option<impl Future<Output = Result<Value>>> {
let capabilities = self.capabilities.get().unwrap();
match capabilities.rename_provider {
@@ -1487,10 +1455,7 @@ impl Client {
}
// empty string to get all symbols
- pub fn workspace_symbols(
- &self,
- query: String,
- ) -> Option<impl Future<Output = Result<Option<lsp::WorkspaceSymbolResponse>>>> {
+ pub fn workspace_symbols(&self, query: String) -> Option<impl Future<Output = Result<Value>>> {
let capabilities = self.capabilities.get().unwrap();
// Return early if the server does not support workspace symbols.
@@ -1503,7 +1468,6 @@ impl Client {
query,
work_done_progress_params: lsp::WorkDoneProgressParams::default(),
partial_result_params: lsp::PartialResultParams::default(),
- ..Default::default()
};
Some(self.call::<lsp::request::WorkspaceSymbolRequest>(params))
@@ -1514,7 +1478,7 @@ impl Client {
text_document: lsp::TextDocumentIdentifier,
range: lsp::Range,
context: lsp::CodeActionContext,
- ) -> Option<impl Future<Output = Result<Option<Vec<lsp::CodeActionOrCommand>>>>> {
+ ) -> Option<impl Future<Output = Result<Value>>> {
let capabilities = self.capabilities.get().unwrap();
// Return early if the server does not support code actions.
@@ -1542,7 +1506,7 @@ impl Client {
text_document: lsp::TextDocumentIdentifier,
position: lsp::Position,
new_name: String,
- ) -> Option<impl Future<Output = Result<Option<lsp::WorkspaceEdit>>>> {
+ ) -> Option<impl Future<Output = Result<lsp::WorkspaceEdit>>> {
if !self.supports_feature(LanguageServerFeature::RenameSymbol) {
return None;
}
@@ -1558,13 +1522,16 @@ impl Client {
},
};
- Some(self.call::<lsp::request::Rename>(params))
+ let request = self.call::<lsp::request::Rename>(params);
+
+ Some(async move {
+ let json = request.await?;
+ let response: Option<lsp::WorkspaceEdit> = serde_json::from_value(json)?;
+ Ok(response.unwrap_or_default())
+ })
}
- pub fn command(
- &self,
- command: lsp::Command,
- ) -> Option<impl Future<Output = Result<Option<Value>>>> {
+ pub fn command(&self, command: lsp::Command) -> Option<impl Future<Output = Result<Value>>> {
let capabilities = self.capabilities.get().unwrap();
// Return early if the language server does not support executing commands.
@@ -1581,7 +1548,10 @@ impl Client {
Some(self.call::<lsp::request::ExecuteCommand>(params))
}
- pub fn did_change_watched_files(&self, changes: Vec<lsp::FileEvent>) {
+ pub fn did_change_watched_files(
+ &self,
+ changes: Vec<lsp::FileEvent>,
+ ) -> impl Future<Output = std::result::Result<(), Error>> {
self.notify::<lsp::notification::DidChangeWatchedFiles>(lsp::DidChangeWatchedFilesParams {
changes,
})