ls_types/
notebook.rs

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