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.rs | 92 |
1 files changed, 20 insertions, 72 deletions
diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs index 22a8dd89..f2b78a11 100644 --- a/helix-lsp/src/client.rs +++ b/helix-lsp/src/client.rs @@ -10,7 +10,7 @@ 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; @@ -39,7 +39,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, @@ -176,29 +176,6 @@ impl Client { 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 - } - } - #[allow(clippy::type_complexity, clippy::too_many_arguments)] pub fn start( cmd: &str, @@ -224,7 +201,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 +348,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 +356,7 @@ 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(_) - ) - ), + LanguageServerFeature::DocumentColors => capabilities.color_provider.is_some(), } } @@ -603,9 +571,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 +648,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 { @@ -1199,7 +1160,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, @@ -1225,8 +1202,6 @@ impl Client { _ => return None, }; - let options = self.get_merged_formatting_options(options); - let params = lsp::DocumentRangeFormattingParams { text_document, range, @@ -1237,32 +1212,6 @@ impl Client { Some(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)) - } - pub fn text_document_document_highlight( &self, text_document: lsp::TextDocumentIdentifier, @@ -1503,7 +1452,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)) |