-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add missing $/setTrace and $/logTrace notifications
This adds types for the two missing notifications. See: * https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#setTrace * https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#logTrace It also renames the `TraceOption` type to `TraceValue`, which is the name use in the [LSP specification](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#traceValue).
- Loading branch information
1 parent
1caf44a
commit 300a9d6
Showing
3 changed files
with
117 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] | ||
pub struct SetTraceParams { | ||
/// The new value that should be assigned to the trace setting. | ||
pub value: TraceValue, | ||
} | ||
|
||
/// A TraceValue represents the level of verbosity with which the server systematically | ||
/// reports its execution trace using `LogTrace` notifications. | ||
/// | ||
/// The initial trace value is set by the client at initialization and can be modified | ||
/// later using the `SetTrace` notification. | ||
#[derive(Debug, Eq, PartialEq, Clone, Copy, Deserialize, Serialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub enum TraceValue { | ||
/// The server should not send any `$/logTrace` notification | ||
Off, | ||
/// The server should not add the 'verbose' field in the `LogTraceParams` | ||
Messages, | ||
Verbose, | ||
} | ||
|
||
impl Default for TraceValue { | ||
fn default() -> TraceValue { | ||
TraceValue::Off | ||
} | ||
} | ||
|
||
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct LogTraceParams { | ||
/// The message to be logged. | ||
pub message: String, | ||
/// Additional information that can be computed if the `trace` configuration | ||
/// is set to `'verbose'` | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub verbose: Option<String>, | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use crate::tests::test_serialization; | ||
|
||
#[test] | ||
fn test_set_trace_params() { | ||
test_serialization( | ||
&SetTraceParams { | ||
value: TraceValue::Off, | ||
}, | ||
r#"{"value":"off"}"#, | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_log_trace_params() { | ||
test_serialization( | ||
&LogTraceParams { | ||
message: "message".into(), | ||
verbose: None, | ||
}, | ||
r#"{"message":"message"}"#, | ||
); | ||
|
||
test_serialization( | ||
&LogTraceParams { | ||
message: "message".into(), | ||
verbose: Some("verbose".into()), | ||
}, | ||
r#"{"message":"message","verbose":"verbose"}"#, | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_trace_value() { | ||
test_serialization( | ||
&vec![TraceValue::Off, TraceValue::Messages, TraceValue::Verbose], | ||
r#"["off","messages","verbose"]"#, | ||
); | ||
} | ||
} |