bsp_types/
bt_dependency_modules.rs

1use super::BuildTargetIdentifier;
2use serde::{Deserialize, Serialize};
3use serde_json::Value;
4
5/// The build target dependency modules request is sent from the client to the server to query
6/// for the libraries of build target dependencies that are external to the workspace including meta
7/// information about library and their sources. It's an extended version of buildTarget/sources.
8#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
9pub struct BuildTargetDependencyModules {
10    /// The build targets to clean.
11    targets: Vec<BuildTargetIdentifier>,
12}
13
14impl BuildTargetDependencyModules {
15    /// Get a reference to the bsp btclean cache params's targets.
16    pub fn targets(&self) -> &[BuildTargetIdentifier] {
17        self.targets.as_ref()
18    }
19
20    /// Get a mutable reference to the bsp btclean cache params's targets.
21    pub fn targets_mut(&mut self) -> &mut Vec<BuildTargetIdentifier> {
22        &mut self.targets
23    }
24
25    pub fn is_empty(&self) -> bool {
26        self.targets.is_empty()
27    }
28
29    /// Set the bsp btclean cache params's targets.
30    pub fn set_targets(&mut self, targets: Vec<BuildTargetIdentifier>) {
31        self.targets = targets;
32    }
33}
34
35#[derive(Default, Debug, Serialize, Deserialize, PartialEq, Eq)]
36pub struct BuildTargetDependencyModulesResult {
37    items: Vec<DependencyModulesItem>,
38}
39
40impl BuildTargetDependencyModulesResult {
41    pub fn new(items: Vec<DependencyModulesItem>) -> Self {
42        Self { items }
43    }
44
45    /// Get a reference to the bsp btdependency modules result's items.
46    pub fn items(&self) -> &[DependencyModulesItem] {
47        self.items.as_ref()
48    }
49
50    /// Get a mutable reference to the bsp btdependency modules result's items.
51    pub fn items_mut(&mut self) -> &mut Vec<DependencyModulesItem> {
52        &mut self.items
53    }
54}
55
56#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
57pub struct DependencyModulesItem {
58    target: BuildTargetIdentifier,
59    modules: Vec<DependencyModule>,
60}
61
62impl DependencyModulesItem {
63    pub fn new(target: BuildTargetIdentifier, modules: Vec<DependencyModule>) -> Self {
64        Self { target, modules }
65    }
66
67    /// Get a reference to the bsp btdependency modules item's target.
68    pub fn target(&self) -> &BuildTargetIdentifier {
69        &self.target
70    }
71
72    /// Set the bsp btdependency modules item's modules.
73    pub fn set_modules(&mut self, modules: Vec<DependencyModule>) {
74        self.modules = modules;
75    }
76
77    /// Get a reference to the bsp btdependency modules item's modules.
78    pub fn modules(&self) -> &[DependencyModule] {
79        self.modules.as_ref()
80    }
81}
82
83#[derive(Default, Debug, Serialize, Deserialize, PartialEq, Eq)]
84#[serde(rename_all = "camelCase")]
85pub struct DependencyModule {
86    /// Module name
87    name: String,
88
89    /// Module version
90    version: String,
91
92    /// Kind of data to expect in the `data` field. If this field is not set, the kind of data is not specified.
93    data_kind: Option<String>,
94
95    /// Language-specific metadata about this module.
96    ///    * See <https://github.com/build-server-protocol/build-server-protocol/blob/master/bsp4j/src/main/java/ch/epfl/scala/bsp4j/MavenExtension.xtend>
97    data: Option<Value>,
98}
99
100impl DependencyModule {
101    pub fn new(
102        name: String,
103        version: String,
104        data_kind: Option<String>,
105        data: Option<Value>,
106    ) -> Self {
107        Self {
108            name,
109            version,
110            data_kind,
111            data,
112        }
113    }
114    pub fn new_simple(name: String, version: String) -> Self {
115        Self {
116            name,
117            version,
118            data_kind: None,
119            data: None,
120        }
121    }
122
123    /// Get a reference to the bsp btdependency module's name.
124    pub fn name(&self) -> &str {
125        self.name.as_ref()
126    }
127
128    /// Set the bsp btdependency module's name.
129    pub fn set_name(&mut self, name: String) {
130        self.name = name;
131    }
132
133    /// Get a reference to the bsp btdependency module's version.
134    pub fn version(&self) -> &str {
135        self.version.as_ref()
136    }
137
138    /// Set the bsp btdependency module's version.
139    pub fn set_version(&mut self, version: String) {
140        self.version = version;
141    }
142
143    /// Get a reference to the bsp btdependency module's data kind.
144    pub fn data_kind(&self) -> Option<&String> {
145        self.data_kind.as_ref()
146    }
147
148    /// Set the bsp btdependency module's data kind.
149    pub fn set_data_kind(&mut self, data_kind: Option<String>) {
150        self.data_kind = data_kind;
151    }
152}