Support formatting in fake LSP capabilities

This commit is contained in:
Antonio Scandurra 2022-03-04 11:24:18 +01:00
parent 46da80d726
commit d8ef3a5d61
2 changed files with 10 additions and 2 deletions

View File

@ -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()
}
}

View File

@ -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::request::Formatting>(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())