@@ -49,7 +49,9 @@ export class NotebookConcatDocument implements TextDocument, IDisposable {
49
49
const { NotebookCellKind } = require ( 'vscode' ) ;
50
50
// Return Python if we have python cells.
51
51
if (
52
- this . notebook . cells . some ( ( item ) => item . document . languageId . toLowerCase ( ) === PYTHON_LANGUAGE . toLowerCase ( ) )
52
+ this . notebook
53
+ . getCells ( )
54
+ . some ( ( item ) => item . document . languageId . toLowerCase ( ) === PYTHON_LANGUAGE . toLowerCase ( ) )
53
55
) {
54
56
return PYTHON_LANGUAGE ;
55
57
}
@@ -58,7 +60,7 @@ export class NotebookConcatDocument implements TextDocument, IDisposable {
58
60
// in which case the language server will never kick in.
59
61
// eslint-disable-next-line @typescript-eslint/no-explicit-any
60
62
return (
61
- this . notebook . cells . find (
63
+ this . notebook . getCells ( ) . find (
62
64
// eslint-disable-next-line @typescript-eslint/no-explicit-any
63
65
( item ) => ( ( item as any ) . cellKind || item . kind ) === NotebookCellKind . Code ,
64
66
) ?. document ?. languageId || PYTHON_LANGUAGE
@@ -83,7 +85,10 @@ export class NotebookConcatDocument implements TextDocument, IDisposable {
83
85
}
84
86
85
87
public get lineCount ( ) : number {
86
- return this . notebook . cells . map ( ( c ) => c . document . lineCount ) . reduce ( ( p , c ) => p + c ) ;
88
+ return this . notebook
89
+ . getCells ( )
90
+ . map ( ( c ) => c . document . lineCount )
91
+ . reduce ( ( p , c ) => p + c ) ;
87
92
}
88
93
89
94
public get onCellsChanged ( ) : Event < TextDocumentChangeEvent > {
@@ -141,7 +146,7 @@ export class NotebookConcatDocument implements TextDocument, IDisposable {
141
146
const location = this . concatDocument . locationAt ( position ) ;
142
147
143
148
// Get the cell at this location
144
- const cell = this . notebook . cells . find ( ( c ) => c . document . uri . toString ( ) === location . uri . toString ( ) ) ;
149
+ const cell = this . notebook . getCells ( ) . find ( ( c ) => c . document . uri . toString ( ) === location . uri . toString ( ) ) ;
145
150
return cell ! . document . lineAt ( location . range . start ) ;
146
151
}
147
152
@@ -163,7 +168,7 @@ export class NotebookConcatDocument implements TextDocument, IDisposable {
163
168
const location = this . concatDocument . locationAt ( position ) ;
164
169
165
170
// Get the cell at this location
166
- const cell = this . notebook . cells . find ( ( c ) => c . document . uri . toString ( ) === location . uri . toString ( ) ) ;
171
+ const cell = this . notebook . getCells ( ) . find ( ( c ) => c . document . uri . toString ( ) === location . uri . toString ( ) ) ;
167
172
return cell ! . document . getWordRangeAtPosition ( location . range . start , regexp ) ;
168
173
}
169
174
@@ -177,12 +182,12 @@ export class NotebookConcatDocument implements TextDocument, IDisposable {
177
182
178
183
public getCellAtPosition ( position : Position ) : NotebookCell | undefined {
179
184
const location = this . concatDocument . locationAt ( position ) ;
180
- return this . notebook . cells . find ( ( c ) => c . document . uri === location . uri ) ;
185
+ return this . notebook . getCells ( ) . find ( ( c ) => c . document . uri === location . uri ) ;
181
186
}
182
187
183
188
private updateCellTracking ( ) {
184
189
this . cellTracking = [ ] ;
185
- this . notebook . cells . forEach ( ( c ) => {
190
+ this . notebook . getCells ( ) . forEach ( ( c ) => {
186
191
// Compute end position from number of lines in a cell
187
192
const cellText = c . document . getText ( ) ;
188
193
const lines = cellText . splitLines ( { trim : false } ) ;
@@ -197,13 +202,13 @@ export class NotebookConcatDocument implements TextDocument, IDisposable {
197
202
198
203
private onDidChange ( ) {
199
204
this . _version += 1 ;
200
- const newUris = this . notebook . cells . map ( ( c ) => c . document . uri . toString ( ) ) ;
205
+ const newUris = this . notebook . getCells ( ) . map ( ( c ) => c . document . uri . toString ( ) ) ;
201
206
const oldUris = this . cellTracking . map ( ( c ) => c . uri . toString ( ) ) ;
202
207
203
208
// See if number of cells or cell positions changed
204
- if ( this . cellTracking . length < this . notebook . cells . length ) {
209
+ if ( this . cellTracking . length < this . notebook . cellCount ) {
205
210
this . raiseCellInsertions ( oldUris ) ;
206
- } else if ( this . cellTracking . length > this . notebook . cells . length ) {
211
+ } else if ( this . cellTracking . length > this . notebook . cellCount ) {
207
212
this . raiseCellDeletions ( newUris , oldUris ) ;
208
213
} else if ( ! isEqual ( oldUris , newUris ) ) {
209
214
this . raiseCellMovement ( ) ;
@@ -216,8 +221,8 @@ export class NotebookConcatDocument implements TextDocument, IDisposable {
216
221
}
217
222
218
223
public getEndPosition ( ) : Position {
219
- if ( this . notebook . cells . length > 0 ) {
220
- const finalCell = this . notebook . cells [ this . notebook . cells . length - 1 ] ;
224
+ if ( this . notebook . cellCount > 0 ) {
225
+ const finalCell = this . notebook . cellAt ( this . notebook . cellCount - 1 ) ;
221
226
const start = this . getPositionOfCell ( finalCell . document . uri ) ;
222
227
const lines = finalCell . document . getText ( ) . splitLines ( { trim : false } ) ;
223
228
return new Position ( start . line + lines . length , 0 ) ;
@@ -227,7 +232,7 @@ export class NotebookConcatDocument implements TextDocument, IDisposable {
227
232
228
233
private raiseCellInsertions ( oldUris : string [ ] ) {
229
234
// One or more cells were added. Add a change event for each
230
- const insertions = this . notebook . cells . filter ( ( c ) => ! oldUris . includes ( c . document . uri . toString ( ) ) ) ;
235
+ const insertions = this . notebook . getCells ( ) . filter ( ( c ) => ! oldUris . includes ( c . document . uri . toString ( ) ) ) ;
231
236
232
237
const changes = insertions . map ( ( insertion ) => {
233
238
// Figure out the position of the item. This is where we're inserting the cell
@@ -265,7 +270,7 @@ export class NotebookConcatDocument implements TextDocument, IDisposable {
265
270
// Figure out the position of the item in the new list
266
271
const position =
267
272
index < newUris . length
268
- ? this . getPositionOfCell ( this . notebook . cells [ index ] . document . uri )
273
+ ? this . getPositionOfCell ( this . notebook . cellAt ( index ) . document . uri )
269
274
: this . getEndPosition ( ) ;
270
275
271
276
// Length should be old length
0 commit comments