bsp_types/
bt_sources.rs

1use super::BuildTargetIdentifier;
2use lsp_types::Url;
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Default, Serialize, Deserialize)]
6/// The build target sources request is sent from the client to the server to
7/// query for the list of text documents and directories that are belong to a
8/// build target. The sources response must not include sources that are
9/// external to the workspace.
10pub struct BuildTargetSources {
11    targets: Vec<BuildTargetIdentifier>,
12}
13
14impl BuildTargetSources {
15    pub fn new(targets: Vec<BuildTargetIdentifier>) -> Self {
16        Self { targets }
17    }
18
19    /// Get a reference to the bsp sources params's targets.
20    pub fn targets(&self) -> &[BuildTargetIdentifier] {
21        self.targets.as_ref()
22    }
23
24    /// Set the bsp sources params's targets.
25    pub fn set_targets(&mut self, targets: Vec<BuildTargetIdentifier>) {
26        self.targets = targets;
27    }
28}
29
30#[derive(Debug, Default, Serialize, Deserialize)]
31pub struct BuildTargetSourcesResult {
32    items: Vec<SourcesCollection>,
33}
34
35impl BuildTargetSourcesResult {
36    pub fn new(items: Vec<SourcesCollection>) -> Self {
37        Self { items }
38    }
39
40    /// Get a reference to the bsp sources result's items.
41    pub fn items(&self) -> &[SourcesCollection] {
42        self.items.as_ref()
43    }
44
45    /// Set the bsp sources result's items.
46    pub fn set_items(&mut self, items: Vec<SourcesCollection>) {
47        self.items = items;
48    }
49}
50
51#[derive(Debug, Serialize, Deserialize)]
52pub struct SourcesCollection {
53    target: BuildTargetIdentifier,
54
55    /// The text documents and directories that belong to this build target.
56    sources: Vec<Sources>,
57}
58
59impl SourcesCollection {
60    pub fn new(target: BuildTargetIdentifier, sources: Vec<Sources>) -> Self {
61        Self { target, sources }
62    }
63
64    /// Get a reference to the bsp sources collection's target.
65    pub fn target(&self) -> &BuildTargetIdentifier {
66        &self.target
67    }
68
69    /// Set the bsp sources collection's target.
70    pub fn set_target(&mut self, target: BuildTargetIdentifier) {
71        self.target = target;
72    }
73
74    /// Get a reference to the bsp sources collection's sources.
75    pub fn sources(&self) -> &[Sources] {
76        self.sources.as_ref()
77    }
78
79    /// Set the bsp sources collection's sources.
80    pub fn set_sources(&mut self, sources: Vec<Sources>) {
81        self.sources = sources;
82    }
83}
84
85#[derive(Debug, Serialize, Deserialize)]
86pub struct Sources {
87    /// Either a text document or a directory. A directory entry must end with a
88    /// forward slash "/" and a directory entry implies that every nested text
89    /// document within the directory belongs to this source item.
90    uri: Url,
91
92    /// Type of file of the source item, such as whether it is file or directory.
93    kind: SourceKind,
94
95    /// Indicates if this source is automatically generated by the build and is
96    /// not intended to be manually edited by the user.
97    generated: bool,
98}
99
100impl Sources {
101    /// Either a text document or a directory. A directory entry must end with a
102    /// forward slash "/" and a directory entry implies that every nested text
103    /// document within the directory belongs to this source item.
104    pub fn new(uri: Url, kind: SourceKind, generated: bool) -> Self {
105        Self {
106            uri,
107            kind,
108            generated,
109        }
110    }
111
112    /// Get a reference to the bsp sources item's kind.
113    pub fn kind(&self) -> &SourceKind {
114        &self.kind
115    }
116
117    /// Set the bsp sources item's kind.
118    pub fn set_kind(&mut self, kind: SourceKind) {
119        self.kind = kind;
120    }
121
122    /// Get a reference to the bsp sources item's uri.
123    pub fn uri(&self) -> &Url {
124        &self.uri
125    }
126
127    /// Set the bsp sources item's uri.
128    pub fn set_uri(&mut self, uri: Url) {
129        self.uri = uri;
130    }
131
132    /// Get the bsp sources item's generated.
133    pub fn generated(&self) -> bool {
134        self.generated
135    }
136
137    /// Set the bsp sources item's generated.
138    pub fn set_generated(&mut self, generated: bool) {
139        self.generated = generated;
140    }
141}
142
143#[derive(Debug, serde_repr::Deserialize_repr, serde_repr::Serialize_repr)]
144#[repr(u16)]
145pub enum SourceKind {
146    /// The source item references a normal file.
147    File = 1,
148    /// The source item references a directory.
149    Directory = 2,
150}
151
152impl Default for SourceKind {
153    fn default() -> Self {
154        Self::File
155    }
156}