From 94aa4a35237014f7e01f6867882ac0d5503193b5 Mon Sep 17 00:00:00 2001 From: Adrian Budau Date: Wed, 10 Apr 2024 18:40:06 +0300 Subject: [PATCH] Add registration options for formatting and rangeFormatting Also moved the options in the same file where onTypeFormatting was. --- src/formatting.rs | 35 ++++++++++++++++++++++++++++++++++- src/lib.rs | 18 +++--------------- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/src/formatting.rs b/src/formatting.rs index 4e5593c..e25ffe6 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -2,7 +2,8 @@ use serde::{Deserialize, Serialize}; use crate::{ DocumentSelector, DynamicRegistrationClientCapabilities, Range, TextDocumentIdentifier, - TextDocumentPositionParams, WorkDoneProgressParams, + TextDocumentPositionParams, TextDocumentRegistrationOptions, WorkDoneProgressOptions, + WorkDoneProgressParams, }; use std::collections::HashMap; @@ -11,6 +12,38 @@ pub type DocumentFormattingClientCapabilities = DynamicRegistrationClientCapabil pub type DocumentRangeFormattingClientCapabilities = DynamicRegistrationClientCapabilities; pub type DocumentOnTypeFormattingClientCapabilities = DynamicRegistrationClientCapabilities; +#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct DocumentFormattingOptions { + #[serde(flatten)] + pub work_done_progress_options: WorkDoneProgressOptions, +} + +#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct DocumentFormattingRegistrationOptions { + #[serde(flatten)] + pub text_document_registration_options: TextDocumentRegistrationOptions, + #[serde(flatten)] + pub document_formatting_options: DocumentFormattingOptions, +} + +#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct DocumentRangeFormattingOptions { + #[serde(flatten)] + pub work_done_progress_options: WorkDoneProgressOptions, +} + +#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct DocumentRangeFormattingRegistrationOptions { + #[serde(flatten)] + pub text_document_registration_options: TextDocumentRegistrationOptions, + #[serde(flatten)] + pub document_range_formatting_options: DocumentRangeFormattingOptions, +} + /// Format document on type options #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] diff --git a/src/lib.rs b/src/lib.rs index e38fae2..8498be5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -238,7 +238,9 @@ pub type LSPArray = Vec; /// Position in a text document expressed as zero-based line and character offset. /// A position is between two characters like an 'insert' cursor in a editor. -#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Copy, Clone, Default, Deserialize, Serialize, Hash)] +#[derive( + Debug, Eq, PartialEq, Ord, PartialOrd, Copy, Clone, Default, Deserialize, Serialize, Hash, +)] pub struct Position { /// Line position in a document (zero-based). pub line: u32, @@ -2150,20 +2152,6 @@ pub struct WorkDoneProgressOptions { pub work_done_progress: Option, } -#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] -#[serde(rename_all = "camelCase")] -pub struct DocumentFormattingOptions { - #[serde(flatten)] - pub work_done_progress_options: WorkDoneProgressOptions, -} - -#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] -#[serde(rename_all = "camelCase")] -pub struct DocumentRangeFormattingOptions { - #[serde(flatten)] - pub work_done_progress_options: WorkDoneProgressOptions, -} - #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct DefinitionOptions {