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 'window/progress' notification #103

Merged
merged 3 commits into from
Apr 15, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ serde_json = "1.0.0"
url = "1.1.0"
url_serde = "0.2.0"

[features]
default = []
# Enables proposed LSP extensions.
# NOTE: No semver compatibility is guaranteed for types enabled by this feature.
proposed = []
Xanewok marked this conversation as resolved.
Show resolved Hide resolved
53 changes: 53 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,19 @@ pub struct TextDocumentClientCapabilities {
pub folding_range: Option<FoldingRangeCapability>,
}

/**
* Window specific client capabilities.
*/
#[derive(Debug, PartialEq, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct WindowClientCapabilities {
/**
* Whether `window/progress` server notifications are supported.
*/
#[cfg(feature = "proposed")]
pub progress: Option<bool>,
}

/**
* Where ClientCapabilities are currently empty:
*/
Expand All @@ -1378,6 +1391,12 @@ pub struct ClientCapabilities {
#[serde(skip_serializing_if = "Option::is_none")]
pub text_document: Option<TextDocumentClientCapabilities>,

/**
* Window specific client capabilities.
*/
#[serde(skip_serializing_if = "Option::is_none")]
pub window: Option<WindowClientCapabilities>,

/**
* Experimental client capabilities.
*/
Expand Down Expand Up @@ -3350,6 +3369,40 @@ pub struct MarkupContent {
pub value: String,
}

#[cfg(feature = "proposed")]
pub use proposed::*;

#[cfg(feature = "proposed")]
mod 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)]
pub struct ProgressParams {
/// A unique identifier to associate multiple progress notifications
/// with the same progress.
pub id: String,

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

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

/// Set to true on the final progress update.
/// No more progress notifications with the same ID should be sent.
pub done: Option<bool>,
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
25 changes: 25 additions & 0 deletions src/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ macro_rules! lsp_notification {
("workspace/didChangeWorkspaceFolders") => {
$crate::notification::DidChangeWorkspaceFolders
};
// Proposed
// ("window/progress") => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially I wanted to warn the user if they're trying to use a feature that's proposed but since the macro has to return specifically a type, I wasn't sure what to return here, so I just commented it out

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fine to just return the type as normal, if proposed is not enabled then it will just be a compile error. (Add a comment on it so people can at least read to source to see why it does not work).

// $crate::notification::Progress
// };
}

/// The base protocol now offers support for request cancellation. To cancel a request,
Expand Down Expand Up @@ -252,6 +256,24 @@ impl Notification for PublishDiagnostics {
const METHOD: &'static str = "textDocument/publishDiagnostics";
}

#[cfg(feature = "proposed")]
pub use proposed::*;

#[cfg(feature = "proposed")]
pub mod proposed {
use super::*;

/// The progress notification is sent from the server to the client to ask
/// the client to indicate progress.
#[derive(Debug)]
pub enum Progress {}
Xanewok marked this conversation as resolved.
Show resolved Hide resolved

impl Notification for Progress {
type Params = ProgressParams;
const METHOD: &'static str = "window/progress";
}
}

#[cfg(test)]
mod test {
use super::*;
Expand Down Expand Up @@ -290,5 +312,8 @@ mod test {
check_macro!("workspace/didChangeConfiguration");
check_macro!("workspace/didChangeWatchedFiles");
check_macro!("workspace/didChangeWorkspaceFolders");

// Proposed
// check_macro!("window/progress");
Xanewok marked this conversation as resolved.
Show resolved Hide resolved
}
}