@@ -12,45 +12,32 @@ import { PrefixSumComputer } from 'vs/editor/common/viewModel/prefixSumComputer'
1212import { DisposableStore } from 'vs/base/common/lifecycle' ;
1313import { score } from 'vs/editor/common/modes/languageSelector' ;
1414import { CellKind } from 'vs/workbench/contrib/notebook/common/notebookCommon' ;
15- import { basename } from 'vs/base/common/resources' ;
16- import { ResourceMap } from 'vs/base/common/map' ;
17- import { ExtHostDocumentLine } from 'vs/workbench/api/common/extHostDocumentData' ;
15+ import { isEqual } from 'vs/base/common/resources' ;
1816
19- export class ExtHostNotebookConcatDocument implements vscode . NotebookConcatTextDocument , vscode . TextDocument {
17+ export class ExtHostNotebookConcatDocument implements vscode . NotebookConcatTextDocument {
2018
2119 private _disposables = new DisposableStore ( ) ;
2220 private _isClosed = false ;
2321
2422 private _cells ! : ExtHostCell [ ] ;
25- private _cellByUri ! : ResourceMap < number > ;
2623 private _cellLengths ! : PrefixSumComputer ;
2724 private _cellLines ! : PrefixSumComputer ;
2825 private _versionId = 0 ;
2926
3027 private readonly _onDidChange = new Emitter < void > ( ) ;
3128 readonly onDidChange : Event < void > = this . _onDidChange . event ;
3229
33- readonly uri : vscode . Uri ;
34- readonly fileName : string ;
35- readonly languageId : string ;
36- readonly isUntitled : boolean = false ;
37- readonly isDirty : boolean = false ;
38-
3930 constructor (
4031 extHostNotebooks : ExtHostNotebookController ,
4132 extHostDocuments : ExtHostDocuments ,
4233 private readonly _notebook : vscode . NotebookDocument ,
4334 private readonly _selector : vscode . DocumentSelector | undefined ,
4435 ) {
45- this . uri = _notebook . uri . with ( { scheme : 'vscode-notebook-concat-doc' } ) ;
46- this . fileName = basename ( this . uri ) ;
47- this . languageId = this . _createLanguageId ( ) ;
48-
4936 this . _init ( ) ;
5037
5138 this . _disposables . add ( extHostDocuments . onDidChangeDocument ( e => {
52- const cellIdx = this . _cellByUri . get ( e . document . uri ) ;
53- if ( typeof cellIdx === 'number' ) {
39+ let cellIdx = this . _cells . findIndex ( cell => isEqual ( cell . uri , e . document . uri ) ) ;
40+ if ( cellIdx >= 0 ) {
5441 this . _cellLengths . changeValue ( cellIdx , this . _cells [ cellIdx ] . document . getText ( ) . length + 1 ) ;
5542 this . _cellLines . changeValue ( cellIdx , this . _cells [ cellIdx ] . document . lineCount ) ;
5643 this . _versionId += 1 ;
@@ -81,12 +68,10 @@ export class ExtHostNotebookConcatDocument implements vscode.NotebookConcatTextD
8168
8269 private _init ( ) {
8370 this . _cells = [ ] ;
84- this . _cellByUri = new ResourceMap ( ) ;
8571 const cellLengths : number [ ] = [ ] ;
8672 const cellLineCounts : number [ ] = [ ] ;
8773 for ( let cell of this . _notebook . cells ) {
8874 if ( cell . cellKind === CellKind . Code && ( ! this . _selector || score ( this . _selector , cell . uri , cell . language , true ) ) ) {
89- this . _cellByUri . set ( cell . uri , this . _cells . length ) ;
9075 this . _cells . push ( < ExtHostCell > cell ) ;
9176 cellLengths . push ( cell . document . getText ( ) . length + 1 ) ;
9277 cellLineCounts . push ( cell . document . lineCount ) ;
@@ -96,67 +81,6 @@ export class ExtHostNotebookConcatDocument implements vscode.NotebookConcatTextD
9681 this . _cellLines = new PrefixSumComputer ( new Uint32Array ( cellLineCounts ) ) ;
9782 }
9883
99- private _createLanguageId ( ) : string {
100- const languageIds = new Set < string > ( ) ;
101- ( function fillInLanguageIds ( selector : vscode . DocumentSelector | undefined ) {
102- if ( Array . isArray ( selector ) ) {
103- selector . forEach ( fillInLanguageIds ) ;
104- } else if ( typeof selector === 'string' ) {
105- languageIds . add ( selector ) ;
106- } else if ( selector ?. language ) {
107- languageIds . add ( selector . language ) ;
108- }
109- } ) ( this . _selector ) ;
110-
111- if ( languageIds . size === 0 ) {
112- return 'unknown' ;
113- }
114- return [ ...languageIds . values ( ) ] . sort ( ) . join ( ';' ) ;
115- }
116-
117- save ( ) : Thenable < boolean > {
118- // todo@jrieken throw error instead?
119- return Promise . resolve ( false ) ;
120- }
121-
122- get eol ( ) : vscode . EndOfLine {
123- return types . EndOfLine . LF ;
124- }
125-
126- get lineCount ( ) : number {
127- let total = 0 ;
128- for ( let cell of this . _cells ) {
129- total += cell . document . lineCount ;
130- }
131- return total ;
132- }
133-
134- lineAt ( lineOrPosition : number | vscode . Position ) : vscode . TextLine {
135- const line = typeof lineOrPosition === 'number' ? lineOrPosition : lineOrPosition . line ;
136- const cellIdx = this . _cellLines . getIndexOf ( line ) ;
137- return new ExtHostDocumentLine (
138- line ,
139- this . _cells [ cellIdx . index ] . document . lineAt ( cellIdx . remainder ) . text ,
140- line >= this . lineCount
141- ) ;
142- }
143-
144- getWordRangeAtPosition ( position : vscode . Position , regex ?: RegExp | undefined ) : vscode . Range | undefined {
145- const cellIdx = this . _cellLines . getIndexOf ( position . line ) ;
146- return this . _cells [ cellIdx . index ] . document . getWordRangeAtPosition ( position . with ( { line : cellIdx . remainder } ) , regex ) ;
147- }
148-
149- validateRange ( range : vscode . Range ) : vscode . Range {
150- const start = this . validatePosition ( range . start ) ;
151- const end = this . validatePosition ( range . end ) ;
152- return range . with ( { start, end } ) ;
153- }
154-
155- validatePosition ( position : vscode . Position ) : vscode . Position {
156- const cellIdx = this . _cellLines . getIndexOf ( position . line ) ;
157- return this . _cells [ cellIdx . index ] . document . validatePosition ( position . with ( { line : cellIdx . remainder } ) ) ;
158- }
159-
16084 get version ( ) : number {
16185 return this . _versionId ;
16286 }
@@ -179,8 +103,8 @@ export class ExtHostNotebookConcatDocument implements vscode.NotebookConcatTextD
179103 // get start and end locations and create substrings
180104 const start = this . locationAt ( range . start ) ;
181105 const end = this . locationAt ( range . end ) ;
182- const startCell = this . _cells [ this . _cellByUri . get ( start . uri ) ?? - 1 ] ;
183- const endCell = this . _cells [ this . _cellByUri . get ( end . uri ) ?? - 1 ] ;
106+ const startCell = this . _cells . find ( cell => isEqual ( cell . uri , start . uri ) ) ;
107+ const endCell = this . _cells . find ( cell => isEqual ( cell . uri , end . uri ) ) ;
184108
185109 if ( ! startCell || ! endCell ) {
186110 return '' ;
@@ -207,8 +131,8 @@ export class ExtHostNotebookConcatDocument implements vscode.NotebookConcatTextD
207131 return this . _cells [ idx . index ] . document . positionAt ( idx . remainder ) . translate ( lineCount ) ;
208132 }
209133
210- const idx = this . _cellByUri . get ( locationOrOffset . uri ) ;
211- if ( typeof idx === 'number' ) {
134+ const idx = this . _cells . findIndex ( cell => isEqual ( cell . uri , locationOrOffset . uri ) ) ;
135+ if ( idx >= 0 ) {
212136 let line = this . _cellLines . getAccumulatedValue ( idx - 1 ) ;
213137 return new types . Position ( line + locationOrOffset . range . start . line , locationOrOffset . range . start . character ) ;
214138 }
0 commit comments