Skip to main content

lsp_types_max/
notebook.rs

1use serde::{Deserialize, Serialize};
2use serde_repr::{Deserialize_repr, Serialize_repr};
3
4use crate::{LSPObject, Uri};
5
6pub use notification_params::*;
7
8/// A notebook document.
9///
10/// @since 3.17.0
11#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
12#[serde(rename_all = "camelCase")]
13pub struct NotebookDocument {
14    /// The notebook document's URI.
15    pub uri: Uri,
16    /// The type of the notebook.
17    pub notebook_type: String,
18    /// The version number of this document (it will increase after each
19    /// change, including undo/redo).
20    pub version: i32,
21    /// Additional metadata stored with the notebook
22    /// document.
23    #[serde(skip_serializing_if = "Option::is_none")]
24    pub metadata: Option<LSPObject>,
25    /// The cells of a notebook.
26    pub cells: Vec<NotebookCell>,
27}
28
29/// A notebook cell.
30///
31/// A cell's document URI must be unique across ALL notebook
32/// cells and can therefore be used to uniquely identify a
33/// notebook cell or the cell's text document.
34///
35/// @since 3.17.0
36#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
37#[serde(rename_all = "camelCase")]
38pub struct NotebookCell {
39    /// The cell's kind
40    pub kind: NotebookCellKind,
41    /// The URI of the cell's text document content.
42    pub document: Uri,
43    /// Additional metadata stored with the cell.
44    #[serde(skip_serializing_if = "Option::is_none")]
45    pub metadata: Option<LSPObject>,
46    /// Additional execution summary information
47    /// if supported by the client.
48    #[serde(skip_serializing_if = "Option::is_none")]
49    pub execution_summary: Option<ExecutionSummary>,
50}
51
52#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
53#[serde(rename_all = "camelCase")]
54pub struct ExecutionSummary {
55    /// A strict monotonically increasing value
56    /// indicating the execution order of a cell
57    /// inside a notebook.
58    pub execution_order: u32,
59    /// Whether the execution was successful or
60    /// not if known by the client.
61    #[serde(skip_serializing_if = "Option::is_none")]
62    pub success: Option<bool>,
63}
64
65#[derive(Debug, Eq, PartialEq, Clone, Serialize_repr, Deserialize_repr)]
66#[repr(u8)]
67pub enum NotebookCellKind {
68    /// A markup-cell is formatted source that is used for display.
69    Markup = 1,
70    /// A code-cell is source code.
71    Code = 2,
72}
73
74/// Capabilities specific to the notebook document support.
75///
76/// @since 3.17.0
77#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
78#[serde(rename_all = "camelCase")]
79pub struct NotebookDocumentClientCapabilities {
80    /// Capabilities specific to notebook document synchronization
81    ///
82    /// @since 3.17.0
83    pub synchronization: NotebookDocumentSyncClientCapabilities,
84}
85
86/// Notebook specific client capabilities.
87///
88/// @since 3.17.0
89#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
90#[serde(rename_all = "camelCase")]
91pub struct NotebookDocumentSyncClientCapabilities {
92    /// Whether implementation supports dynamic registration. If this is
93    /// set to `true` the client supports the new
94    /// `(TextDocumentRegistrationOptions & StaticRegistrationOptions)`
95    /// return value for the corresponding server capability as well.
96    #[serde(skip_serializing_if = "Option::is_none")]
97    pub dynamic_registration: Option<bool>,
98
99    /// The client supports sending execution summary data per cell.
100    #[serde(skip_serializing_if = "Option::is_none")]
101    pub execution_summary_report: Option<bool>,
102}
103
104///  Options specific to a notebook plus its cells
105///  to be synced to the server.
106///
107///  If a selector provides a notebook document
108///  filter but no cell selector all cells of a
109///  matching notebook document will be synced.
110///
111///  If a selector provides no notebook document
112///  filter but only a cell selector all notebook
113///  documents that contain at least one matching
114///  cell will be synced.
115///
116///  @since 3.17.0
117#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
118#[serde(rename_all = "camelCase")]
119pub struct NotebookDocumentSyncOptions {
120    /// The notebooks to be synced
121    pub notebook_selector: Vec<NotebookSelector>,
122    /// Whether save notification should be forwarded to
123    /// the server. Will only be honored if mode === `notebook`.
124    #[serde(skip_serializing_if = "Option::is_none")]
125    pub save: Option<bool>,
126}
127
128/// Registration options specific to a notebook.
129///
130/// @since 3.17.0
131#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
132#[serde(rename_all = "camelCase")]
133pub struct NotebookDocumentSyncRegistrationOptions {
134    /// The notebooks to be synced
135    pub notebook_selector: Vec<NotebookSelector>,
136    /// Whether save notification should be forwarded to
137    /// the server. Will only be honored if mode === `notebook`.
138    #[serde(skip_serializing_if = "Option::is_none")]
139    pub save: Option<bool>,
140    /// The id used to register the request. The id can be used to deregister
141    /// the request again. See also Registration#id.
142    #[serde(skip_serializing_if = "Option::is_none")]
143    pub id: Option<String>,
144}
145
146/// A notebook cell text document filter denotes a cell text
147/// document by different properties.
148///
149/// @since 3.17.0
150#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
151#[serde(rename_all = "camelCase")]
152pub struct NotebookCellTextDocumentFilter {
153    /// A filter that matches against the notebook
154    /// containing the notebook cell. If a string
155    /// value is provided it matches against the
156    /// notebook type. '*' matches every notebook.
157    pub notebook: Notebook,
158    /// A language id like `python`.
159    ///
160    /// Will be matched against the language id of the
161    /// notebook cell document. '*' matches every language.
162    #[serde(skip_serializing_if = "Option::is_none")]
163    pub language: Option<String>,
164}
165
166#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
167#[serde(rename_all = "camelCase", untagged)]
168pub enum NotebookSelector {
169    ByNotebook {
170        /// The notebook to be synced. If a string
171        /// value is provided it matches against the
172        /// notebook type. '*' matches every notebook.
173        notebook: Notebook,
174        /// The cells of the matching notebook to be synced.
175        #[serde(skip_serializing_if = "Option::is_none")]
176        cells: Option<Vec<NotebookCellSelector>>,
177    },
178    ByCells {
179        /// The notebook to be synced. If a string
180        /// value is provided it matches against the
181        /// notebook type. '*' matches every notebook.
182        #[serde(skip_serializing_if = "Option::is_none")]
183        notebook: Option<Notebook>,
184        /// The cells of the matching notebook to be synced.
185        cells: Vec<NotebookCellSelector>,
186    },
187}
188
189#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
190#[serde(rename_all = "camelCase")]
191pub struct NotebookCellSelector {
192    pub language: String,
193}
194
195#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
196#[serde(untagged)]
197pub enum Notebook {
198    String(String),
199    NotebookDocumentFilter(NotebookDocumentFilter),
200}
201
202/// A notebook document filter denotes a notebook document by
203/// different properties.
204///
205/// @since 3.17.0
206#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
207#[serde(untagged)]
208pub enum NotebookDocumentFilter {
209    #[serde(rename_all = "camelCase")]
210    ByType {
211        /// The type of the enclosing notebook.
212        notebook_type: String,
213        /// A Uri [scheme](#Uri.scheme), like `file` or `untitled`.
214        #[serde(skip_serializing_if = "Option::is_none")]
215        scheme: Option<String>,
216        /// A glob pattern.
217        #[serde(skip_serializing_if = "Option::is_none")]
218        pattern: Option<String>,
219    },
220    #[serde(rename_all = "camelCase")]
221    ByScheme {
222        /// The type of the enclosing notebook.
223        #[serde(skip_serializing_if = "Option::is_none")]
224        notebook_type: Option<String>,
225        /// A Uri [scheme](#Uri.scheme), like `file` or `untitled`.
226        scheme: String,
227        /// A glob pattern.
228        #[serde(skip_serializing_if = "Option::is_none")]
229        pattern: Option<String>,
230    },
231    #[serde(rename_all = "camelCase")]
232    ByPattern {
233        /// The type of the enclosing notebook.
234        #[serde(skip_serializing_if = "Option::is_none")]
235        notebook_type: Option<String>,
236        /// A Uri [scheme](#Uri.scheme), like `file` or `untitled`.
237        #[serde(skip_serializing_if = "Option::is_none")]
238        scheme: Option<String>,
239        /// A glob pattern.
240        pattern: String,
241    },
242}
243
244mod notification_params {
245    use serde::{Deserialize, Serialize};
246
247    use crate::{
248        TextDocumentContentChangeEvent, TextDocumentIdentifier, TextDocumentItem,
249        VersionedTextDocumentIdentifier,
250    };
251
252    use super::*;
253
254    /// The params sent in an open notebook document notification.
255    ///
256    /// @since 3.17.0
257    #[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)]
258    #[serde(rename_all = "camelCase")]
259    pub struct DidOpenNotebookDocumentParams {
260        /// The notebook document that got opened.
261        pub notebook_document: NotebookDocument,
262        /// The text documents that represent the content
263        /// of a notebook cell.
264        pub cell_text_documents: Vec<TextDocumentItem>,
265    }
266
267    /// The params sent in a change notebook document notification.
268    ///
269    /// @since 3.17.0
270    #[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)]
271    #[serde(rename_all = "camelCase")]
272    pub struct DidChangeNotebookDocumentParams {
273        /// The notebook document that did change. The version number points
274        /// to the version after all provided changes have been applied.
275        pub notebook_document: VersionedNotebookDocumentIdentifier,
276
277        /// The actual changes to the notebook document.
278        ///
279        /// The change describes single state change to the notebook document.
280        /// So it moves a notebook document, its cells and its cell text document
281        /// contents from state S to S'.
282        ///
283        /// To mirror the content of a notebook using change events use the
284        /// following approach:
285        /// - start with the same initial content
286        /// - apply the 'notebookDocument/didChange' notifications in the order
287        ///   you receive them.
288        pub change: NotebookDocumentChangeEvent,
289    }
290
291    /// A versioned notebook document identifier.
292    ///
293    /// @since 3.17.0
294    #[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)]
295    #[serde(rename_all = "camelCase")]
296    pub struct VersionedNotebookDocumentIdentifier {
297        /// The version number of this notebook document.
298        pub version: i32,
299        /// The notebook document's URI.
300        pub uri: Uri,
301    }
302
303    /// A change event for a notebook document.
304    ///
305    /// @since 3.17.0
306    #[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)]
307    #[serde(rename_all = "camelCase")]
308    pub struct NotebookDocumentChangeEvent {
309        /// The changed meta data if any.
310        #[serde(skip_serializing_if = "Option::is_none")]
311        pub metadata: Option<LSPObject>,
312
313        /// Changes to cells
314        #[serde(skip_serializing_if = "Option::is_none")]
315        pub cells: Option<NotebookDocumentCellChange>,
316    }
317
318    #[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)]
319    #[serde(rename_all = "camelCase")]
320    pub struct NotebookDocumentCellChange {
321        /// Changes to the cell structure to add or
322        /// remove cells.
323        #[serde(skip_serializing_if = "Option::is_none")]
324        pub structure: Option<NotebookDocumentCellChangeStructure>,
325
326        /// Changes to notebook cells properties like its
327        /// kind, execution summary or metadata.
328        #[serde(skip_serializing_if = "Option::is_none")]
329        pub data: Option<Vec<NotebookCell>>,
330
331        /// Changes to the text content of notebook cells.
332        #[serde(skip_serializing_if = "Option::is_none")]
333        pub text_content: Option<Vec<NotebookDocumentChangeTextContent>>,
334    }
335
336    #[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)]
337    #[serde(rename_all = "camelCase")]
338    pub struct NotebookDocumentChangeTextContent {
339        pub document: VersionedTextDocumentIdentifier,
340        pub changes: Vec<TextDocumentContentChangeEvent>,
341    }
342
343    #[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)]
344    #[serde(rename_all = "camelCase")]
345    pub struct NotebookDocumentCellChangeStructure {
346        /// The change to the cell array.
347        pub array: NotebookCellArrayChange,
348        /// Additional opened cell text documents.
349        #[serde(skip_serializing_if = "Option::is_none")]
350        pub did_open: Option<Vec<TextDocumentItem>>,
351        /// Additional closed cell text documents.
352        #[serde(skip_serializing_if = "Option::is_none")]
353        pub did_close: Option<Vec<TextDocumentIdentifier>>,
354    }
355
356    /// A change describing how to move a `NotebookCell`
357    /// array from state S to S'.
358    ///
359    /// @since 3.17.0
360    #[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)]
361    #[serde(rename_all = "camelCase")]
362    pub struct NotebookCellArrayChange {
363        /// The start offset of the cell that changed.
364        pub start: u32,
365
366        /// The deleted cells
367        pub delete_count: u32,
368
369        /// The new cells, if any
370        #[serde(skip_serializing_if = "Option::is_none")]
371        pub cells: Option<Vec<NotebookCell>>,
372    }
373
374    /// The params sent in a save notebook document notification.
375    ///
376    /// @since 3.17.0
377    #[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)]
378    #[serde(rename_all = "camelCase")]
379    pub struct DidSaveNotebookDocumentParams {
380        /// The notebook document that got saved.
381        pub notebook_document: NotebookDocumentIdentifier,
382    }
383
384    /// A literal to identify a notebook document in the client.
385    ///
386    /// @since 3.17.0
387    #[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)]
388    #[serde(rename_all = "camelCase")]
389    pub struct NotebookDocumentIdentifier {
390        /// The notebook document's URI.
391        pub uri: Uri,
392    }
393
394    /// The params sent in a close notebook document notification.
395    ///
396    /// @since 3.17.0
397    #[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)]
398    #[serde(rename_all = "camelCase")]
399    pub struct DidCloseNotebookDocumentParams {
400        /// The notebook document that got closed.
401        pub notebook_document: NotebookDocumentIdentifier,
402
403        /// The text documents that represent the content
404        /// of a notebook cell that got closed.
405        pub cell_text_documents: Vec<TextDocumentIdentifier>,
406    }
407}