1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
use super::BuildTargetIdentifier;
use lsp_types::Url;
use serde::{Deserialize, Serialize};
use serde_json::Value;

/// The debug request is sent from the client to the server to debug build target(s). The server
/// launches a Microsoft DAP server and returns a connection URI for the client to interact with.
#[derive(Default, Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase", default)]
pub struct DebugSessionStart {
    /// A sequence of build targets affected by the debugging action.
    targets: Vec<BuildTargetIdentifier>,

    /// The kind of data to expect in the `data` field.
    /// TODO: Is DebugSessionStart dataKind == TaskDataKind?
    data_kind: String,

    /// Language-specific metadata for this execution.
    ///  * See <https://github.com/build-server-protocol/build-server-protocol/blob/master/bsp4j/src/main/xtend-gen/ch/epfl/scala/bsp4j/ScalaMainClass.java>
    #[serde(skip_serializing_if = "Value::is_null")]
    data: Value,
}

impl DebugSessionStart {
    pub fn new(targets: Vec<BuildTargetIdentifier>, data_kind: String, data: Value) -> Self {
        Self {
            targets,
            data_kind,
            data,
        }
    }

    /// Get a reference to the debug session params's targets.
    pub fn targets(&self) -> &[BuildTargetIdentifier] {
        self.targets.as_ref()
    }

    /// Get a reference to the debug session params's data kind.
    pub fn data_kind(&self) -> &str {
        self.data_kind.as_ref()
    }

    /// Get a reference to the debug session params's data.
    pub fn data(&self) -> &Value {
        &self.data
    }

    /// Set the debug session params's targets.
    pub fn set_targets(&mut self, targets: Vec<BuildTargetIdentifier>) {
        self.targets = targets;
    }

    /// Set the debug session params's data kind.
    pub fn set_data_kind(&mut self, data_kind: String) {
        self.data_kind = data_kind;
    }

    /// Set the debug session params's data.
    pub fn set_data(&mut self, data: Value) {
        self.data = data;
    }
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct DebugSessionStartResult {
    /** The Debug Adapter Protocol server's connection uri */
    uri: Url,
}

impl DebugSessionStartResult {
    pub fn new(uri: Url) -> Self {
        Self { uri }
    }
}