From d8ef3a5d61ad581bcbe7f1d15db2fa4dd6c6688f Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 4 Mar 2022 11:24:18 +0100 Subject: [PATCH] Support formatting in fake LSP capabilities --- crates/lsp/src/lsp.rs | 2 ++ crates/project/src/project.rs | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/lsp/src/lsp.rs b/crates/lsp/src/lsp.rs index fce2068302..5f3eb2caaf 100644 --- a/crates/lsp/src/lsp.rs +++ b/crates/lsp/src/lsp.rs @@ -524,6 +524,8 @@ impl LanguageServer { ServerCapabilities { document_highlight_provider: Some(OneOf::Left(true)), code_action_provider: Some(CodeActionProviderCapability::Simple(true)), + document_formatting_provider: Some(OneOf::Left(true)), + document_range_formatting_provider: Some(OneOf::Left(true)), ..Default::default() } } diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index f207430d7a..53ca4bf332 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -1323,7 +1323,10 @@ impl Project { let text_document = lsp::TextDocumentIdentifier::new( lsp::Url::from_file_path(&buffer_abs_path).unwrap(), ); - let lsp_edits = if capabilities.document_formatting_provider.is_some() { + let lsp_edits = if capabilities + .document_formatting_provider + .map_or(false, |provider| provider != lsp::OneOf::Left(false)) + { lang_server .request::(lsp::DocumentFormattingParams { text_document, @@ -1331,7 +1334,10 @@ impl Project { work_done_progress_params: Default::default(), }) .await? - } else if capabilities.document_range_formatting_provider.is_some() { + } else if capabilities + .document_range_formatting_provider + .map_or(false, |provider| provider != lsp::OneOf::Left(false)) + { let buffer_start = lsp::Position::new(0, 0); let buffer_end = buffer .read_with(&cx, |buffer, _| buffer.max_point_utf16())