From 9878f009aa49030e9852e1acafc9050a33826509 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 27 Mar 2019 13:30:55 +0300 Subject: [PATCH] add proposed selectionRange API --- src/lib.rs | 24 ++++++++++++++++++++++++ src/request.rs | 22 +++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index ffb749f..05a1103 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1635,6 +1635,10 @@ pub struct ServerCapabilities { #[serde(skip_serializing_if = "Option::is_none")] pub text_document_sync: Option, + /// Capabilities specific to `textDocument/selectionRange` requests. + #[serde(skip_serializing_if = "Option::is_none")] + pub selection_range_provider: Option, + /// The server provides hover support. #[serde(skip_serializing_if = "Option::is_none")] pub hover_provider: Option, @@ -3309,6 +3313,26 @@ pub struct FoldingRange { pub kind: Option, } +/// A parameter literal used in selection range requests. +#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct SelectionRangeParams { + /// The text document. + pub text_document: TextDocumentIdentifier, + /// The positions inside the text document. + pub positions: Vec, +} + +/// Represents a selection range. +#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct SelectionRange { + /// Range of the selection. + pub range: Range, + /// The parent selection range containing this range. + pub parent: Option>, +} + /** * Enum of known range kinds */ diff --git a/src/request.rs b/src/request.rs index 2bf9173..2d864c5 100644 --- a/src/request.rs +++ b/src/request.rs @@ -108,6 +108,9 @@ macro_rules! lsp_request { ("textDocument/typeDefinition") => { $crate::request::GotoTypeDefinition }; + ("textDocument/selectionRange") => { + $crate::request::SelectionRangeRequest + }; ("workspace/workspaceFolders") => { $crate::request::WorkspaceFoldersRequest }; @@ -561,6 +564,22 @@ impl Request for WorkspaceFoldersRequest { const METHOD: &'static str = "workspace/workspaceFolders"; } +///The selection range request is sent from the client to the server to return +///suggested selection ranges at given positions. A selection range is a range +///around the cursor position which the user might be interested in selecting. +///Typically, but not necessary, selection ranges correspond to the nodes of the +///syntax tree. +/// Selection ranges should be computed independently for each position. Ranges +/// for a specific position should form hierarchy: each range has an optional, +/// strictly larger, parent range. +pub enum SelectionRangeRequest {} + +impl Request for SelectionRangeRequest { + type Params = SelectionRangeParams; + type Result = Vec; + const METHOD: &'static str = "textDocument/selectionRange"; +} + #[cfg(test)] mod test { use super::*; @@ -602,6 +621,7 @@ mod test { check_macro!("textDocument/documentSymbol"); check_macro!("textDocument/codeAction"); check_macro!("textDocument/codeLens"); + check_macro!("textDocument/selectionRange"); check_macro!("codeLens/resolve"); check_macro!("textDocument/documentLink"); check_macro!("documentLink/resolve"); @@ -619,4 +639,4 @@ mod test { check_macro!("textDocument/typeDefinition"); check_macro!("workspace/configuration"); } -} \ No newline at end of file +}