Skip to content

Commit 1141faa

Browse files
committed
add proposed selectionRange API
1 parent b719f15 commit 1141faa

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

src/lib.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,6 +1616,10 @@ pub struct ServerCapabilities {
16161616
#[serde(skip_serializing_if = "Option::is_none")]
16171617
pub text_document_sync: Option<TextDocumentSyncCapability>,
16181618

1619+
/// Capabilities specific to `textDocument/selectionRange` requests.
1620+
#[serde(skip_serializing_if = "Option::is_none")]
1621+
pub selection_range_provider: Option<GenericCapability>,
1622+
16191623
/// The server provides hover support.
16201624
#[serde(skip_serializing_if = "Option::is_none")]
16211625
pub hover_provider: Option<bool>,
@@ -3290,6 +3294,26 @@ pub struct FoldingRange {
32903294
pub kind: Option<FoldingRangeKind>,
32913295
}
32923296

3297+
/// A parameter literal used in selection range requests.
3298+
#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize)]
3299+
#[serde(rename_all = "camelCase")]
3300+
pub struct SelectionRangeParams {
3301+
/// The text document.
3302+
pub text_document: TextDocumentIdentifier,
3303+
/// The positions inside the text document.
3304+
pub positions: Vec<Position>,
3305+
}
3306+
3307+
/// Represents a selection range.
3308+
#[derive(Debug, Eq, PartialEq, Default, Deserialize, Serialize)]
3309+
#[serde(rename_all = "camelCase")]
3310+
pub struct SelectionRange {
3311+
/// Range of the selection.
3312+
pub range: Range,
3313+
/// The parent selection range containing this range.
3314+
pub parent: Option<Box<SelectionRange>>,
3315+
}
3316+
32933317
/**
32943318
* Enum of known range kinds
32953319
*/

src/request.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ macro_rules! lsp_request {
108108
("textDocument/typeDefinition") => {
109109
$crate::request::GotoTypeDefinition
110110
};
111+
("textDocument/selectionRange") => {
112+
$crate::request::SelectionRangeRequest
113+
}
111114
("workspace/workspaceFolders") => {
112115
$crate::request::WorkspaceFoldersRequest
113116
};
@@ -561,6 +564,22 @@ impl Request for WorkspaceFoldersRequest {
561564
const METHOD: &'static str = "workspace/workspaceFolders";
562565
}
563566

567+
///The selection range request is sent from the client to the server to return
568+
///suggested selection ranges at given positions. A selection range is a range
569+
///around the cursor position which the user might be interested in selecting.
570+
///Typically, but not necessary, selection ranges correspond to the nodes of the
571+
///syntax tree.
572+
/// Selection ranges should be computed independently for each position. Ranges
573+
/// for a specific position should form hierarchy: each range has an optional,
574+
/// strictly larger, parent range.
575+
pub enum SelectionRangeRequest {}
576+
577+
impl Request for SelectionRangeRequest {
578+
type Params = SelectionRangeParams;
579+
type Result = Vec<SelectionRange>;
580+
const METHOD: &'static str = "textDocument/selectionRange";
581+
}
582+
564583
#[cfg(test)]
565584
mod test {
566585
use super::*;
@@ -602,6 +621,7 @@ mod test {
602621
check_macro!("textDocument/documentSymbol");
603622
check_macro!("textDocument/codeAction");
604623
check_macro!("textDocument/codeLens");
624+
check_macro!("textDocument/selectionRange");
605625
check_macro!("codeLens/resolve");
606626
check_macro!("textDocument/documentLink");
607627
check_macro!("documentLink/resolve");
@@ -619,4 +639,4 @@ mod test {
619639
check_macro!("textDocument/typeDefinition");
620640
check_macro!("workspace/configuration");
621641
}
622-
}
642+
}

0 commit comments

Comments
 (0)