Skip to content

Commit

Permalink
add proposed selectionRange API
Browse files Browse the repository at this point in the history
  • Loading branch information
matklad committed Apr 21, 2019
1 parent 234646d commit 9878f00
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1635,6 +1635,10 @@ pub struct ServerCapabilities {
#[serde(skip_serializing_if = "Option::is_none")]
pub text_document_sync: Option<TextDocumentSyncCapability>,

/// Capabilities specific to `textDocument/selectionRange` requests.
#[serde(skip_serializing_if = "Option::is_none")]
pub selection_range_provider: Option<GenericCapability>,

/// The server provides hover support.
#[serde(skip_serializing_if = "Option::is_none")]
pub hover_provider: Option<bool>,
Expand Down Expand Up @@ -3309,6 +3313,26 @@ pub struct FoldingRange {
pub kind: Option<FoldingRangeKind>,
}

/// 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<Position>,
}

/// 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<Box<SelectionRange>>,
}

/**
* Enum of known range kinds
*/
Expand Down
22 changes: 21 additions & 1 deletion src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ macro_rules! lsp_request {
("textDocument/typeDefinition") => {
$crate::request::GotoTypeDefinition
};
("textDocument/selectionRange") => {
$crate::request::SelectionRangeRequest
};
("workspace/workspaceFolders") => {
$crate::request::WorkspaceFoldersRequest
};
Expand Down Expand Up @@ -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<SelectionRange>;
const METHOD: &'static str = "textDocument/selectionRange";
}

#[cfg(test)]
mod test {
use super::*;
Expand Down Expand Up @@ -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");
Expand All @@ -619,4 +639,4 @@ mod test {
check_macro!("textDocument/typeDefinition");
check_macro!("workspace/configuration");
}
}
}

0 comments on commit 9878f00

Please sign in to comment.