@@ -4,8 +4,7 @@ import type {
4
4
IVirtualPosition ,
5
5
IRootPosition ,
6
6
Document ,
7
- ForeignDocumentsMap ,
8
- IForeignCodeExtractor
7
+ ForeignDocumentsMap
9
8
} from '@jupyterlab/lsp' ;
10
9
import { VirtualDocument as VirtualDocumentBase } from '@jupyterlab/lsp' ;
11
10
@@ -34,11 +33,6 @@ export class VirtualDocument extends VirtualDocumentBase {
34
33
this . lineMagicsOverrides = new ReversibleOverridesMap (
35
34
overrides ? overrides . line : [ ]
36
35
) ;
37
- // override private `chooseForeignDocument` as a workaround for
38
- // https://github.com/jupyter-lsp/jupyterlab-lsp/issues/959
39
- const anyThis = this as any ;
40
- anyThis . _chooseForeignDocument = anyThis . chooseForeignDocument =
41
- this . __chooseForeignDocument ;
42
36
}
43
37
44
38
// TODO: this could be moved out
@@ -147,44 +141,6 @@ export class VirtualDocument extends VirtualDocumentBase {
147
141
this . lastSourceLine += sourceCellLines . length ;
148
142
}
149
143
150
- /**
151
- * Close all expired documents.
152
- */
153
- closeExpiredDocuments ( ) : void {
154
- // TODO: remove once https://github.com/jupyterlab/jupyterlab/pull/15105 is in
155
- const usedDocuments = new Set < VirtualDocument > ( ) ;
156
- for ( const line of this . sourceLines . values ( ) ) {
157
- for ( const block of line . foreignDocumentsMap . values ( ) ) {
158
- usedDocuments . add ( block . virtualDocument as any as VirtualDocument ) ;
159
- }
160
- }
161
-
162
- const documentIDs = new Map < VirtualDocument , string [ ] > ( ) ;
163
- const vDocs : Map < string , VirtualDocument > = this . foreignDocuments as any ;
164
- for ( const [ id , document ] of vDocs . entries ( ) ) {
165
- const ids = documentIDs . get ( document ) ;
166
- if ( typeof ids !== 'undefined' ) {
167
- documentIDs . set ( document , [ ...ids , id ] ) ;
168
- }
169
- documentIDs . set ( document , [ id ] ) ;
170
- }
171
- const allDocuments = new Set < VirtualDocument > ( documentIDs . keys ( ) ) ;
172
- const unusedVirtualDocuments = new Set (
173
- [ ...allDocuments ] . filter ( x => ! usedDocuments . has ( x ) )
174
- ) ;
175
-
176
- for ( let document of unusedVirtualDocuments . values ( ) ) {
177
- document . remainingLifetime -= 1 ;
178
- if ( document . remainingLifetime <= 0 ) {
179
- document . dispose ( ) ;
180
- const ids = documentIDs . get ( document ) ! ;
181
- for ( const id of ids ) {
182
- this . foreignDocuments . delete ( id ) ;
183
- }
184
- }
185
- }
186
- }
187
-
188
144
/**
189
145
* @experimental
190
146
*/
@@ -207,37 +163,4 @@ export class VirtualDocument extends VirtualDocumentBase {
207
163
}
208
164
return [ ...maps . values ( ) ] ;
209
165
}
210
-
211
- /**
212
- * Get the foreign document that can be opened with the input extractor.
213
- */
214
- private __chooseForeignDocument (
215
- extractor : IForeignCodeExtractor
216
- ) : VirtualDocumentBase {
217
- let foreignDocument : VirtualDocumentBase ;
218
- // if not standalone, try to append to existing document
219
- let foreignExists = this . foreignDocuments . has ( extractor . language ) ;
220
- if ( ! extractor . standalone && foreignExists ) {
221
- foreignDocument = this . foreignDocuments . get ( extractor . language ) ! ;
222
- } else {
223
- // if standalone, try to re-use existing connection to the server
224
- let unusedStandalone = this . unusedStandaloneDocuments . get (
225
- extractor . language
226
- ) ;
227
- if ( extractor . standalone && unusedStandalone . length > 0 ) {
228
- foreignDocument = unusedStandalone . pop ( ) ! ;
229
- } else {
230
- // if (previous document does not exists) or (extractor produces standalone documents
231
- // and no old standalone document could be reused): create a new document
232
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
233
- // @ts -ignore
234
- foreignDocument = this . openForeign (
235
- extractor . language ,
236
- extractor . standalone ,
237
- extractor . fileExtension
238
- ) ;
239
- }
240
- }
241
- return foreignDocument ;
242
- }
243
166
}
0 commit comments