1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
4pub struct SetTraceParams {
5 /// The new value that should be assigned to the trace setting.
6 pub value: TraceValue,
7}
8
9/// A TraceValue represents the level of verbosity with which the server systematically
10/// reports its execution trace using `LogTrace` notifications.
11///
12/// The initial trace value is set by the client at initialization and can be modified
13/// later using the `SetTrace` notification.
14#[derive(Debug, Eq, PartialEq, Clone, Copy, Deserialize, Serialize, Default)]
15#[serde(rename_all = "camelCase")]
16pub enum TraceValue {
17 /// The server should not send any `$/logTrace` notification
18 #[default]
19 Off,
20 /// The server should not add the 'verbose' field in the `LogTraceParams`
21 Messages,
22 Verbose,
23}
24
25#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
26#[serde(rename_all = "camelCase")]
27pub struct LogTraceParams {
28 /// The message to be logged.
29 pub message: String,
30 /// Additional information that can be computed if the `trace` configuration
31 /// is set to `'verbose'`
32 #[serde(skip_serializing_if = "Option::is_none")]
33 pub verbose: Option<String>,
34}
35
36#[cfg(test)]
37mod tests {
38 use super::*;
39 use crate::tests::test_serialization;
40
41 #[test]
42 fn test_set_trace_params() {
43 test_serialization(
44 &SetTraceParams {
45 value: TraceValue::Off,
46 },
47 r#"{"value":"off"}"#,
48 );
49 }
50
51 #[test]
52 fn test_log_trace_params() {
53 test_serialization(
54 &LogTraceParams {
55 message: "message".into(),
56 verbose: None,
57 },
58 r#"{"message":"message"}"#,
59 );
60
61 test_serialization(
62 &LogTraceParams {
63 message: "message".into(),
64 verbose: Some("verbose".into()),
65 },
66 r#"{"message":"message","verbose":"verbose"}"#,
67 );
68 }
69
70 #[test]
71 fn test_trace_value() {
72 test_serialization(
73 &vec![TraceValue::Off, TraceValue::Messages, TraceValue::Verbose],
74 r#"["off","messages","verbose"]"#,
75 );
76 }
77}
78