@@ -506,4 +506,71 @@ impl Client {
507 Ok(response)
507 Ok(response)
512+ pub async fn text_document_formatting(
514+ text_document: lsp::TextDocumentIdentifier,
515+ options: lsp::FormattingOptions,
516+ ) -> anyhow::Result<Vec<lsp::TextEdit>> {
517+ let capabilities = self.capabilities.as_ref().unwrap(); // TODO: needs post init
519+ // check if we're able to format
520+ let _capabilities = match capabilities.document_formatting_provider {
521+ Some(lsp::OneOf::Left(true)) => (),
522+ Some(lsp::OneOf::Right(_)) => (),
523+ // None | Some(false)
524+ _ => return Ok(Vec::new()),
526+ // TODO: return err::unavailable so we can fall back to tree sitter formatting
528+ let params = lsp::DocumentFormattingParams {
531+ // TODO: support these tokens
532+ work_done_progress_params: lsp::WorkDoneProgressParams {
533+ work_done_token: None,
537+ let response = self.request::<lsp::request::Formatting>(params).await?;
539+ Ok(response.unwrap_or_default())
542+ pub async fn text_document_range_formatting(
544+ text_document: lsp::TextDocumentIdentifier,
546+ options: lsp::FormattingOptions,
547+ ) -> anyhow::Result<Vec<lsp::TextEdit>> {
548+ let capabilities = self.capabilities.as_ref().unwrap(); // TODO: needs post init
550+ log::info!("{:?}", capabilities.document_range_formatting_provider);
551+ // check if we're able to format
552+ let _capabilities = match capabilities.document_range_formatting_provider {
553+ Some(lsp::OneOf::Left(true)) => (),
554+ Some(lsp::OneOf::Right(_)) => (),
555+ // None | Some(false)
556+ _ => return Ok(Vec::new()),
558+ // TODO: return err::unavailable so we can fall back to tree sitter formatting
560+ let params = lsp::DocumentRangeFormattingParams {
564+ // TODO: support these tokens
565+ work_done_progress_params: lsp::WorkDoneProgressParams {
566+ work_done_token: None,
571+ .request::<lsp::request::RangeFormatting>(params)
574+ Ok(response.unwrap_or_default())