@@ -8,7 +8,7 @@ import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
8
8
import { Disposable , IDisposable } from 'vs/base/common/lifecycle' ;
9
9
import { parse } from 'vs/base/common/marshalling' ;
10
10
import { Schemas } from 'vs/base/common/network' ;
11
- import { extname } from 'vs/base/common/resources' ;
11
+ import { extname , isEqual } from 'vs/base/common/resources' ;
12
12
import { isFalsyOrWhitespace } from 'vs/base/common/strings' ;
13
13
import { assertType } from 'vs/base/common/types' ;
14
14
import { URI , UriComponents } from 'vs/base/common/uri' ;
@@ -54,14 +54,17 @@ import { INotebookEditorOptions } from 'vs/workbench/contrib/notebook/browser/no
54
54
import { NotebookEditorWidget } from 'vs/workbench/contrib/notebook/browser/notebookEditorWidget' ;
55
55
import * as icons from 'vs/workbench/contrib/notebook/browser/notebookIcons' ;
56
56
import { INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/services/notebookEditorService' ;
57
- import { CellEditType , CellKind , CellUri , INTERACTIVE_WINDOW_EDITOR_ID } from 'vs/workbench/contrib/notebook/common/notebookCommon' ;
57
+ import { CellEditType , CellKind , CellUri , INTERACTIVE_WINDOW_EDITOR_ID , NotebookWorkingCopyTypeIdentifier } from 'vs/workbench/contrib/notebook/common/notebookCommon' ;
58
58
import { INotebookKernelService } from 'vs/workbench/contrib/notebook/common/notebookKernelService' ;
59
59
import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService' ;
60
60
import { columnToEditorGroup } from 'vs/workbench/services/editor/common/editorGroupColumn' ;
61
61
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService' ;
62
62
import { IEditorResolverService , RegisteredEditorPriority } from 'vs/workbench/services/editor/common/editorResolverService' ;
63
63
import { IEditorService } from 'vs/workbench/services/editor/common/editorService' ;
64
+ import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions' ;
64
65
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle' ;
66
+ import { IWorkingCopyIdentifier } from 'vs/workbench/services/workingCopy/common/workingCopy' ;
67
+ import { IWorkingCopyEditorHandler , IWorkingCopyEditorService } from 'vs/workbench/services/workingCopy/common/workingCopyEditorService' ;
65
68
66
69
const interactiveWindowCategory : ILocalizedString = { value : localize ( 'interactiveWindow' , 'Interactive Window' ) , original : 'Interactive Window' } ;
67
70
@@ -181,10 +184,58 @@ class InteractiveInputContentProvider implements ITextModelContentProvider {
181
184
}
182
185
}
183
186
187
+ class InteractiveWindowWorkingCopyEditorHandler extends Disposable implements IWorkbenchContribution , IWorkingCopyEditorHandler {
188
+
189
+ constructor (
190
+ @IInstantiationService private readonly _instantiationService : IInstantiationService ,
191
+ @IWorkingCopyEditorService private readonly _workingCopyEditorService : IWorkingCopyEditorService ,
192
+ @IExtensionService private readonly _extensionService : IExtensionService ,
193
+ ) {
194
+ super ( ) ;
195
+
196
+ this . _installHandler ( ) ;
197
+ }
198
+
199
+ handles ( workingCopy : IWorkingCopyIdentifier ) : boolean {
200
+ const viewType = this . _getViewType ( workingCopy ) ;
201
+ return ! ! viewType && viewType === 'interactive' ;
202
+
203
+ }
204
+
205
+ isOpen ( workingCopy : IWorkingCopyIdentifier , editor : EditorInput ) : boolean {
206
+ if ( ! this . handles ( workingCopy ) ) {
207
+ return false ;
208
+ }
209
+
210
+ return editor instanceof InteractiveEditorInput && isEqual ( workingCopy . resource , editor . resource ) ;
211
+ }
212
+
213
+ createEditor ( workingCopy : IWorkingCopyIdentifier ) : EditorInput {
214
+ const counter = / \/ I n t e r a c t i v e - ( \d + ) / . exec ( workingCopy . resource . path ) ;
215
+ const inputBoxPath = counter && counter [ 1 ] ? `/InteractiveInput-${ counter [ 1 ] } ` : 'InteractiveInput' ;
216
+ const inputUri = URI . from ( { scheme : Schemas . vscodeInteractiveInput , path : inputBoxPath } ) ;
217
+ const editorInput = InteractiveEditorInput . create ( this . _instantiationService , workingCopy . resource , inputUri ) ;
218
+
219
+ return editorInput ;
220
+ }
221
+
222
+ private async _installHandler ( ) : Promise < void > {
223
+ await this . _extensionService . whenInstalledExtensionsRegistered ( ) ;
224
+
225
+ this . _register ( this . _workingCopyEditorService . registerHandler ( this ) ) ;
226
+ }
227
+
228
+ private _getViewType ( workingCopy : IWorkingCopyIdentifier ) : string | undefined {
229
+ return NotebookWorkingCopyTypeIdentifier . parse ( workingCopy . typeId ) ;
230
+ }
231
+ }
232
+
233
+
184
234
185
235
const workbenchContributionsRegistry = Registry . as < IWorkbenchContributionsRegistry > ( WorkbenchExtensions . Workbench ) ;
186
236
workbenchContributionsRegistry . registerWorkbenchContribution ( InteractiveDocumentContribution , LifecyclePhase . Ready ) ;
187
237
workbenchContributionsRegistry . registerWorkbenchContribution ( InteractiveInputContentProvider , LifecyclePhase . Ready ) ;
238
+ workbenchContributionsRegistry . registerWorkbenchContribution ( InteractiveWindowWorkingCopyEditorHandler , LifecyclePhase . Ready ) ;
188
239
189
240
export class InteractiveEditorSerializer implements IEditorSerializer {
190
241
public static readonly ID = InteractiveEditorInput . ID ;
0 commit comments