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

Update proposed progress support #115

Merged
merged 1 commit into from
Aug 24, 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
95 changes: 87 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1328,10 +1328,10 @@ pub struct TextDocumentClientCapabilities {
#[serde(rename_all = "camelCase")]
pub struct WindowClientCapabilities {
/**
* Whether `window/progress` server notifications are supported.
* Whether client supports create a work done progress UI from the server side.
*/
#[cfg(feature = "proposed")]
pub progress: Option<bool>,
pub work_done_progress: Option<bool>,
}

/**
Expand Down Expand Up @@ -3306,20 +3306,83 @@ pub struct MarkupContent {
pub value: String,
}

#[cfg(feature = "proposed")]
pub type ProgressToken = NumberOrString;

#[cfg(feature = "proposed")]
/// The progress notification is sent from the server to the client to ask
/// the client to indicate progress.
#[derive(Debug, PartialEq, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ProgressParams {
/// A unique identifier to associate multiple progress notifications
/// with the same progress.
pub id: String,
/// The progress token provided by the client.
pub token: ProgressToken,

/// The progress data.
pub value: ProgressParamsValue,
}

#[cfg(feature = "proposed")]
#[derive(Debug, PartialEq, Deserialize, Serialize, Clone)]
#[serde(untagged)]
pub enum ProgressParamsValue {
WorkDone(WorkDoneProgress)
}

#[cfg(feature = "proposed")]
/// The `window/workDoneProgress/create` request is sent from the server
/// to the clientto ask the client to create a work done progress.
#[derive(Debug, PartialEq, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct WorkDoneProgressCreateParams {
/// The token to be used to report progress.
pub token: ProgressToken,
}

#[cfg(feature = "proposed")]
/// The `window/workDoneProgress/cancel` is sent from the client to the server
/// to indicate that the user has pressed cancel on a server initiated work done progress.
#[derive(Debug, PartialEq, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct WorkDoneProgressCancelParams {
/// The token to be used to report progress.
pub token: ProgressToken,
}

#[cfg(feature = "proposed")]
#[derive(Debug, PartialEq, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct WorkDoneProgressBegin {
/// Mandatory title of the progress operation. Used to briefly inform
/// about the kind of operation being performed.
/// Examples: "Indexing" or "Linking dependencies".
pub title: String,

/// Controls if a cancel button should show to allow the user to cancel the
/// long running operation. Clients that don't support cancellation are allowed
/// to ignore the setting.
pub cancellable: Option<bool>,

/// Optional, more detailed associated progress message. Contains
/// complementary information to the `title`.
/// Examples: "3/25 files", "project/src/module2", "node_modules/some_dep".
/// If unset, the previous progress message (if any) is still valid.
pub message: Option<String>,

/// Optional progress percentage to display (value 100 is considered 100%).
/// If unset, the previous progress percentage (if any) is still valid.
pub percentage: Option<f64>,
}

#[cfg(feature = "proposed")]
#[derive(Debug, PartialEq, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct WorkDoneProgressReport {
/// Controls if a cancel button should show to allow the user to cancel the
/// long running operation. Clients that don't support cancellation are allowed
/// to ignore the setting.
pub cancellable: Option<bool>,

/// Optional, more detailed associated progress message. Contains
/// complementary information to the `title`.
/// Examples: "3/25 files", "project/src/module2", "node_modules/some_dep".
Expand All @@ -3329,10 +3392,26 @@ pub struct ProgressParams {
/// Optional progress percentage to display (value 100 is considered 100%).
/// If unset, the previous progress percentage (if any) is still valid.
pub percentage: Option<f64>,
}

/// Set to true on the final progress update.
/// No more progress notifications with the same ID should be sent.
pub done: Option<bool>,
#[cfg(feature = "proposed")]
#[derive(Debug, PartialEq, Deserialize, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct WorkDoneProgressDone {
/// Optional, more detailed associated progress message. Contains
/// complementary information to the `title`.
/// Examples: "3/25 files", "project/src/module2", "node_modules/some_dep".
/// If unset, the previous progress message (if any) is still valid.
pub message: Option<String>,
}

#[cfg(feature = "proposed")]
#[derive(Debug, PartialEq, Deserialize, Serialize, Clone)]
#[serde(tag = "kind", rename_all = "lowercase")]
pub enum WorkDoneProgress {
Begin(WorkDoneProgressBegin),
Report(WorkDoneProgressReport),
Done(WorkDoneProgressDone),
}

#[cfg(test)]
Expand Down
29 changes: 25 additions & 4 deletions src/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,14 @@ macro_rules! lsp_notification {
};

// Requires #[cfg(feature = "proposed")]
("window/progress") => {
("$/progress") => {
$crate::notification::Progress
};

// Requires #[cfg(feature = "proposed")]
("window/workDoneProgress/cancel") => {
$crate::notification::WorkDoneProgressCancel
};
}

/// The base protocol now offers support for request cancellation. To cancel a request,
Expand Down Expand Up @@ -266,7 +271,19 @@ pub enum Progress {}
#[cfg(feature = "proposed")]
impl Notification for Progress {
type Params = ProgressParams;
const METHOD: &'static str = "window/progress";
const METHOD: &'static str = "$/progress";
}

#[cfg(feature = "proposed")]
/// The `window/workDoneProgress/cancel` is sent from the client to the server
/// to indicate that the user has pressed cancel on a server initiated work done progress.
#[derive(Debug)]
pub enum WorkDoneProgressCancel {}

#[cfg(feature = "proposed")]
impl Notification for WorkDoneProgressCancel {
type Params = WorkDoneProgressCancelParams;
const METHOD: &'static str = "window/workDoneProgress/cancel";
}

#[cfg(test)]
Expand Down Expand Up @@ -307,8 +324,12 @@ mod test {
check_macro!("workspace/didChangeConfiguration");
check_macro!("workspace/didChangeWatchedFiles");
check_macro!("workspace/didChangeWorkspaceFolders");
}

#[cfg(feature = "proposed")]
check_macro!("window/progress");
#[test]
#[cfg(feature = "proposed")]
fn check_proposed_macro_definitions() {
check_macro!("$/progress");
check_macro!("window/workDoneProgress/cancel");
}
}
19 changes: 19 additions & 0 deletions src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ macro_rules! lsp_request {
("workspace/configuration") => {
$crate::request::WorkspaceConfiguration
};

// Requires #[cfg(feature = "proposed")]
("window/workDoneProgress/create") => {
$crate::request::WorkDoneProgressCreate
};
}

/**
Expand Down Expand Up @@ -581,6 +586,19 @@ impl Request for WorkspaceFoldersRequest {
const METHOD: &'static str = "workspace/workspaceFolders";
}

/// The `window/workDoneProgress/create` request is sent from the server
/// to the clientto ask the client to create a work done progress.
#[cfg(feature = "proposed")]
#[derive(Debug)]
pub enum WorkDoneProgressCreate {}

#[cfg(feature = "proposed")]
impl Request for WorkDoneProgressCreate {
type Params = WorkDoneProgressCreateParams;
type Result = ();
const METHOD: &'static str = "window/workDoneProgress/create";
}

///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.
Expand Down Expand Up @@ -662,5 +680,6 @@ mod test {
#[cfg(feature = "proposed")]
fn check_proposed_macro_definitions() {
check_macro!("textDocument/selectionRange");
check_macro!("window/workDoneProgress/create");
}
}