lsp_types/
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(rename_all = "camelCase", untagged)]
208pub enum NotebookDocumentFilter {
209    ByType {
210        /// The type of the enclosing notebook.
211        notebook_type: String,
212        /// A Uri [scheme](#Uri.scheme), like `file` or `untitled`.
213        #[serde(skip_serializing_if = "Option::is_none")]
214        scheme: Option<String>,
215        /// A glob pattern.
216        #[serde(skip_serializing_if = "Option::is_none")]
217        pattern: Option<String>,
218    },
219    ByScheme {
220        /// The type of the enclosing notebook.
221        #[serde(skip_serializing_if = "Option::is_none")]
222        notebook_type: Option<String>,
223        /// A Uri [scheme](#Uri.scheme), like `file` or `untitled`.
224        scheme: String,
225        /// A glob pattern.
226        #[serde(skip_serializing_if = "Option::is_none")]
227        pattern: Option<String>,
228    },
229    ByPattern {
230        /// The type of the enclosing notebook.
231        #[serde(skip_serializing_if = "Option::is_none")]
232        notebook_type: Option<String>,
233        /// A Uri [scheme](#Uri.scheme), like `file` or `untitled`.
234        #[serde(skip_serializing_if = "Option::is_none")]
235        scheme: Option<String>,
236        /// A glob pattern.
237        pattern: String,
238    },
239}
240
241mod notification_params {
242    use serde::{Deserialize, Serialize};
243
244    use crate::{
245        TextDocumentContentChangeEvent, TextDocumentIdentifier, TextDocumentItem,
246        VersionedTextDocumentIdentifier,
247    };
248
249    use super::*;
250
251    /// The params sent in an open notebook document notification.
252    ///
253    /// @since 3.17.0
254    #[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)]
255    #[serde(rename_all = "camelCase")]
256    pub struct DidOpenNotebookDocumentParams {
257        /// The notebook document that got opened.
258        pub notebook_document: NotebookDocument,
259        /// The text documents that represent the content
260        /// of a notebook cell.
261        pub cell_text_documents: Vec<TextDocumentItem>,
262    }
263
264    /// The params sent in a change notebook document notification.
265    ///
266    /// @since 3.17.0
267    #[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)]
268    #[serde(rename_all = "camelCase")]
269    pub struct DidChangeNotebookDocumentParams {
270        /// The notebook document that did change. The version number points
271        /// to the version after all provided changes have been applied.
272        pub notebook_document: VersionedNotebookDocumentIdentifier,
273
274        /// The actual changes to the notebook document.
275        ///
276        /// The change describes single state change to the notebook document.
277        /// So it moves a notebook document, its cells and its cell text document
278        /// contents from state S to S'.
279        ///
280        /// To mirror the content of a notebook using change events use the
281        /// following approach:
282        /// - start with the same initial content
283        /// - apply the 'notebookDocument/didChange' notifications in the order
284        ///   you receive them.
285        pub change: NotebookDocumentChangeEvent,
286    }
287
288    /// A versioned notebook document identifier.
289    ///
290    /// @since 3.17.0
291    #[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)]
292    #[serde(rename_all = "camelCase")]
293    pub struct VersionedNotebookDocumentIdentifier {
294        /// The version number of this notebook document.
295        pub version: i32,
296        /// The notebook document's URI.
297        pub uri: Uri,
298    }
299
300    /// A change event for a notebook document.
301    ///
302    /// @since 3.17.0
303    #[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)]
304    #[serde(rename_all = "camelCase")]
305    pub struct NotebookDocumentChangeEvent {
306        /// The changed meta data if any.
307        #[serde(skip_serializing_if = "Option::is_none")]
308        pub metadata: Option<LSPObject>,
309
310        /// Changes to cells
311        #[serde(skip_serializing_if = "Option::is_none")]
312        pub cells: Option<NotebookDocumentCellChange>,
313    }
314
315    #[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)]
316    #[serde(rename_all = "camelCase")]
317    pub struct NotebookDocumentCellChange {
318        /// Changes to the cell structure to add or
319        /// remove cells.
320        #[serde(skip_serializing_if = "Option::is_none")]
321        pub structure: Option<NotebookDocumentCellChangeStructure>,
322
323        /// Changes to notebook cells properties like its
324        /// kind, execution summary or metadata.
325        #[serde(skip_serializing_if = "Option::is_none")]
326        pub data: Option<Vec<NotebookCell>>,
327
328        /// Changes to the text content of notebook cells.
329        #[serde(skip_serializing_if = "Option::is_none")]
330        pub text_content: Option<Vec<NotebookDocumentChangeTextContent>>,
331    }
332
333    #[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)]
334    #[serde(rename_all = "camelCase")]
335    pub struct NotebookDocumentChangeTextContent {
336        pub document: VersionedTextDocumentIdentifier,
337        pub changes: Vec<TextDocumentContentChangeEvent>,
338    }
339
340    #[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)]
341    #[serde(rename_all = "camelCase")]
342    pub struct NotebookDocumentCellChangeStructure {
343        /// The change to the cell array.
344        pub array: NotebookCellArrayChange,
345        /// Additional opened cell text documents.
346        #[serde(skip_serializing_if = "Option::is_none")]
347        pub did_open: Option<Vec<TextDocumentItem>>,
348        /// Additional closed cell text documents.
349        #[serde(skip_serializing_if = "Option::is_none")]
350        pub did_close: Option<Vec<TextDocumentIdentifier>>,
351    }
352
353    /// A change describing how to move a `NotebookCell`
354    /// array from state S to S'.
355    ///
356    /// @since 3.17.0
357    #[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)]
358    #[serde(rename_all = "camelCase")]
359    pub struct NotebookCellArrayChange {
360        /// The start offset of the cell that changed.
361        pub start: u32,
362
363        /// The deleted cells
364        pub delete_count: u32,
365
366        /// The new cells, if any
367        #[serde(skip_serializing_if = "Option::is_none")]
368        pub cells: Option<Vec<NotebookCell>>,
369    }
370
371    /// The params sent in a save notebook document notification.
372    ///
373    /// @since 3.17.0
374    #[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)]
375    #[serde(rename_all = "camelCase")]
376    pub struct DidSaveNotebookDocumentParams {
377        /// The notebook document that got saved.
378        pub notebook_document: NotebookDocumentIdentifier,
379    }
380
381    /// A literal to identify a notebook document in the client.
382    ///
383    /// @since 3.17.0
384    #[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)]
385    #[serde(rename_all = "camelCase")]
386    pub struct NotebookDocumentIdentifier {
387        /// The notebook document's URI.
388        pub uri: Uri,
389    }
390
391    /// The params sent in a close notebook document notification.
392    ///
393    /// @since 3.17.0
394    #[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)]
395    #[serde(rename_all = "camelCase")]
396    pub struct DidCloseNotebookDocumentParams {
397        /// The notebook document that got closed.
398        pub notebook_document: NotebookDocumentIdentifier,
399
400        /// The text documents that represent the content
401        /// of a notebook cell that got closed.
402        pub cell_text_documents: Vec<TextDocumentIdentifier>,
403    }
404}