Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add proposed selectionRange API #102

Merged
merged 1 commit into from
Apr 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
}
}