@@ -49,7 +49,9 @@ export class NotebookConcatDocument implements TextDocument, IDisposable {
4949 const { NotebookCellKind } = require ( 'vscode' ) ;
5050 // Return Python if we have python cells.
5151 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 ( ) )
5355 ) {
5456 return PYTHON_LANGUAGE ;
5557 }
@@ -58,7 +60,7 @@ export class NotebookConcatDocument implements TextDocument, IDisposable {
5860 // in which case the language server will never kick in.
5961 // eslint-disable-next-line @typescript-eslint/no-explicit-any
6062 return (
61- this . notebook . cells . find (
63+ this . notebook . getCells ( ) . find (
6264 // eslint-disable-next-line @typescript-eslint/no-explicit-any
6365 ( item ) => ( ( item as any ) . cellKind || item . kind ) === NotebookCellKind . Code ,
6466 ) ?. document ?. languageId || PYTHON_LANGUAGE
@@ -83,7 +85,10 @@ export class NotebookConcatDocument implements TextDocument, IDisposable {
8385 }
8486
8587 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 ) ;
8792 }
8893
8994 public get onCellsChanged ( ) : Event < TextDocumentChangeEvent > {
@@ -141,7 +146,7 @@ export class NotebookConcatDocument implements TextDocument, IDisposable {
141146 const location = this . concatDocument . locationAt ( position ) ;
142147
143148 // 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 ( ) ) ;
145150 return cell ! . document . lineAt ( location . range . start ) ;
146151 }
147152
@@ -163,7 +168,7 @@ export class NotebookConcatDocument implements TextDocument, IDisposable {
163168 const location = this . concatDocument . locationAt ( position ) ;
164169
165170 // 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 ( ) ) ;
167172 return cell ! . document . getWordRangeAtPosition ( location . range . start , regexp ) ;
168173 }
169174
@@ -177,12 +182,12 @@ export class NotebookConcatDocument implements TextDocument, IDisposable {
177182
178183 public getCellAtPosition ( position : Position ) : NotebookCell | undefined {
179184 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 ) ;
181186 }
182187
183188 private updateCellTracking ( ) {
184189 this . cellTracking = [ ] ;
185- this . notebook . cells . forEach ( ( c ) => {
190+ this . notebook . getCells ( ) . forEach ( ( c ) => {
186191 // Compute end position from number of lines in a cell
187192 const cellText = c . document . getText ( ) ;
188193 const lines = cellText . splitLines ( { trim : false } ) ;
@@ -197,13 +202,13 @@ export class NotebookConcatDocument implements TextDocument, IDisposable {
197202
198203 private onDidChange ( ) {
199204 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 ( ) ) ;
201206 const oldUris = this . cellTracking . map ( ( c ) => c . uri . toString ( ) ) ;
202207
203208 // 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 ) {
205210 this . raiseCellInsertions ( oldUris ) ;
206- } else if ( this . cellTracking . length > this . notebook . cells . length ) {
211+ } else if ( this . cellTracking . length > this . notebook . cellCount ) {
207212 this . raiseCellDeletions ( newUris , oldUris ) ;
208213 } else if ( ! isEqual ( oldUris , newUris ) ) {
209214 this . raiseCellMovement ( ) ;
@@ -216,8 +221,8 @@ export class NotebookConcatDocument implements TextDocument, IDisposable {
216221 }
217222
218223 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 ) ;
221226 const start = this . getPositionOfCell ( finalCell . document . uri ) ;
222227 const lines = finalCell . document . getText ( ) . splitLines ( { trim : false } ) ;
223228 return new Position ( start . line + lines . length , 0 ) ;
@@ -227,7 +232,7 @@ export class NotebookConcatDocument implements TextDocument, IDisposable {
227232
228233 private raiseCellInsertions ( oldUris : string [ ] ) {
229234 // 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 ( ) ) ) ;
231236
232237 const changes = insertions . map ( ( insertion ) => {
233238 // 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 {
265270 // Figure out the position of the item in the new list
266271 const position =
267272 index < newUris . length
268- ? this . getPositionOfCell ( this . notebook . cells [ index ] . document . uri )
273+ ? this . getPositionOfCell ( this . notebook . cellAt ( index ) . document . uri )
269274 : this . getEndPosition ( ) ;
270275
271276 // Length should be old length
0 commit comments