bsp_types/
bt_run.rs

1use super::BuildTargetIdentifier;
2use serde::{Deserialize, Serialize};
3use serde_json::Value;
4
5/// The run request is sent from the client to the server to run a build target. The server
6/// communicates during the initialize handshake whether this method is supported or not.
7#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
8#[serde(rename_all = "camelCase")]
9pub struct BuildTargetRun {
10    /// The build target to run.
11    target: BuildTargetIdentifier,
12
13    /// A unique identifier generated by the client to identify this request.
14    ///  * The server may include this id in triggered notifications or responses.
15    #[serde(skip_serializing_if = "Option::is_none")]
16    origin_id: Option<String>,
17
18    /// Optional arguments to the executed application.
19    #[serde(skip_serializing_if = "Option::is_none")]
20    arguments: Option<String>,
21
22    /// Kind of data to expect in the data field. If this field is not set, the kind of data is not specified.
23    #[serde(skip_serializing_if = "Option::is_none")]
24    data_kind: Option<String>,
25
26    /// Language-specific metadata for this execution.
27    ///  * See <https://github.com/build-server-protocol/build-server-protocol/blob/master/bsp4j/src/main/xtend-gen/ch/epfl/scala/bsp4j/ScalaMainClass.java>
28    #[serde(skip_serializing_if = "Option::is_none")]
29    data: Option<Value>,
30}
31
32impl BuildTargetRun {
33    pub fn new(
34        target: BuildTargetIdentifier,
35        origin_id: Option<String>,
36        arguments: Option<String>,
37        data_kind: Option<String>,
38        data: Option<Value>,
39    ) -> Self {
40        Self {
41            target,
42            origin_id,
43            arguments,
44            data_kind,
45            data,
46        }
47    }
48    pub fn new_simple(target: BuildTargetIdentifier) -> Self {
49        Self {
50            target,
51            origin_id: None,
52            arguments: None,
53            data_kind: None,
54            data: None,
55        }
56    }
57
58    /// Get a reference to the bsp btrun params's target.
59    pub fn target(&self) -> &BuildTargetIdentifier {
60        &self.target
61    }
62
63    /// Set the bsp btrun params's target.
64    pub fn set_target(&mut self, target: BuildTargetIdentifier) {
65        self.target = target;
66    }
67
68    /// Get a reference to the bsp btrun params's origin id.
69    pub fn origin_id(&self) -> Option<&String> {
70        self.origin_id.as_ref()
71    }
72
73    /// Set the bsp btrun params's origin id.
74    pub fn set_origin_id(&mut self, origin_id: Option<String>) {
75        self.origin_id = origin_id;
76    }
77
78    /// Get a reference to the bsp btrun params's arguments.
79    pub fn arguments(&self) -> Option<&String> {
80        self.arguments.as_ref()
81    }
82
83    /// Set the bsp btrun params's arguments.
84    pub fn set_arguments(&mut self, arguments: Option<String>) {
85        self.arguments = arguments;
86    }
87
88    /// Get a reference to the bsp btrun params's data kind.
89    pub fn data_kind(&self) -> Option<&String> {
90        self.data_kind.as_ref()
91    }
92
93    /// Set the bsp btrun params's data kind.
94    pub fn set_data_kind(&mut self, data_kind: Option<String>) {
95        self.data_kind = data_kind;
96    }
97
98    /// Get a reference to the bsp btrun params's data.
99    pub fn data(&self) -> Option<&Value> {
100        self.data.as_ref()
101    }
102
103    /// Set the bsp btrun params's data.
104    pub fn set_data(&mut self, data: Option<Value>) {
105        self.data = data;
106    }
107}
108
109/// Note that an empty run request is valid. Run will be executed in the target as specified in the build tool.
110#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
111#[serde(rename_all = "camelCase")]
112pub struct BuildTargetRunResult {
113    /** An optional request id to know the origin of this report. */
114    #[serde(skip_serializing_if = "Option::is_none")]
115    origin_id: Option<String>,
116
117    /** A status code for the execution. */
118    status_code: usize,
119}
120
121impl BuildTargetRunResult {
122    pub fn new(origin_id: Option<String>, status_code: usize) -> Self {
123        Self {
124            origin_id,
125            status_code,
126        }
127    }
128
129    /// Get a reference to the bsp btrun result's origin id.
130    pub fn origin_id(&self) -> Option<&String> {
131        self.origin_id.as_ref()
132    }
133
134    /// Get the bsp btrun result's status code.
135    pub fn status_code(&self) -> usize {
136        self.status_code
137    }
138
139    /// Set the bsp btrun result's origin id.
140    pub fn set_origin_id(&mut self, origin_id: Option<String>) {
141        self.origin_id = origin_id;
142    }
143
144    /// Set the bsp btrun result's status code.
145    pub fn set_status_code(&mut self, status_code: usize) {
146        self.status_code = status_code;
147    }
148}