Skip to content

Commit

Permalink
Merge pull request #102 from matklad/selection-range
Browse files Browse the repository at this point in the history
add proposed selectionRange API
  • Loading branch information
Marwes authored Apr 21, 2019
2 parents 234646d + 6b8b717 commit df69032
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
27 changes: 27 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1635,6 +1635,11 @@ 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")]
#[cfg(feature = "proposed")]
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 +3314,28 @@ pub struct FoldingRange {
pub kind: Option<FoldingRangeKind>,
}

/// A parameter literal used in selection range requests.
#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[cfg(feature = "proposed")]
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")]
#[cfg(feature = "proposed")]
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
29 changes: 28 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,24 @@ 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.
#[cfg(feature = "proposed")]
pub enum SelectionRangeRequest {}

#[cfg(feature = "proposed")]
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 @@ -619,4 +640,10 @@ mod test {
check_macro!("textDocument/typeDefinition");
check_macro!("workspace/configuration");
}
}

#[test]
#[cfg(feature = "proposed")]
fn check_proposed_macro_definitions() {
check_macro!("textDocument/selectionRange");
}
}

0 comments on commit df69032

Please sign in to comment.