Skip to content

Commit 71a4ab0

Browse files
committed
delegate editorInput ownership to EditorService. Activate ipynb extension for IW
1 parent 367c538 commit 71a4ab0

File tree

3 files changed

+161
-135
lines changed

3 files changed

+161
-135
lines changed

extensions/ipynb/package.json

Lines changed: 122 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,124 @@
11
{
2-
"name": "ipynb",
3-
"displayName": "%displayName%",
4-
"description": "%description%",
5-
"publisher": "vscode",
6-
"version": "1.0.0",
7-
"license": "MIT",
8-
"engines": {
9-
"vscode": "^1.57.0"
10-
},
11-
"enabledApiProposals": [
12-
"documentPaste",
13-
"diffContentOptions",
14-
"dropMetadata"
15-
],
16-
"activationEvents": [
17-
"onNotebook:jupyter-notebook"
18-
],
19-
"extensionKind": [
20-
"workspace",
21-
"ui"
22-
],
23-
"main": "./out/ipynbMain.js",
24-
"browser": "./dist/browser/ipynbMain.js",
25-
"capabilities": {
26-
"virtualWorkspaces": true,
27-
"untrustedWorkspaces": {
28-
"supported": true
29-
}
30-
},
31-
"contributes": {
32-
"configuration": [
33-
{
34-
"properties": {
35-
"ipynb.pasteImagesAsAttachments.enabled": {
36-
"type": "boolean",
37-
"scope": "resource",
38-
"markdownDescription": "%ipynb.pasteImagesAsAttachments.enabled%",
39-
"default": true
40-
}
41-
}
42-
}
43-
],
44-
"commands": [
45-
{
46-
"command": "ipynb.newUntitledIpynb",
47-
"title": "%newUntitledIpynb.title%",
48-
"shortTitle": "%newUntitledIpynb.shortTitle%",
49-
"category": "Create"
50-
},
51-
{
52-
"command": "ipynb.openIpynbInNotebookEditor",
53-
"title": "%openIpynbInNotebookEditor.title%"
54-
},
55-
{
56-
"command": "ipynb.cleanInvalidImageAttachment",
57-
"title": "%cleanInvalidImageAttachment.title%"
58-
}
59-
],
60-
"notebooks": [
61-
{
62-
"type": "jupyter-notebook",
63-
"displayName": "Jupyter Notebook",
64-
"selector": [
65-
{
66-
"filenamePattern": "*.ipynb"
67-
}
68-
],
69-
"priority": "default"
70-
}
71-
],
72-
"notebookRenderer": [
73-
{
74-
"id": "vscode.markdown-it-cell-attachment-renderer",
75-
"displayName": "%markdownAttachmentRenderer.displayName%",
76-
"entrypoint": {
77-
"extends": "vscode.markdown-it-renderer",
78-
"path": "./notebook-out/cellAttachmentRenderer.js"
79-
}
80-
}
81-
],
82-
"menus": {
83-
"file/newFile": [
84-
{
85-
"command": "ipynb.newUntitledIpynb",
86-
"group": "notebook"
87-
}
88-
],
89-
"commandPalette": [
90-
{
91-
"command": "ipynb.newUntitledIpynb"
92-
},
93-
{
94-
"command": "ipynb.openIpynbInNotebookEditor",
95-
"when": "false"
96-
},
97-
{
98-
"command": "ipynb.cleanInvalidImageAttachment",
99-
"when": "false"
100-
}
101-
]
102-
}
103-
},
104-
"scripts": {
105-
"compile": "npx gulp compile-extension:ipynb && npm run build-notebook",
106-
"watch": "npx gulp watch-extension:ipynb",
107-
"build-notebook": "node ./esbuild"
108-
},
109-
"dependencies": {
110-
"@enonic/fnv-plus": "^1.3.0",
111-
"detect-indent": "^6.0.0",
112-
"uuid": "^8.3.2"
113-
},
114-
"devDependencies": {
115-
"@jupyterlab/nbformat": "^3.2.9",
116-
"@types/markdown-it": "12.2.3",
117-
"@types/uuid": "^8.3.1"
118-
},
119-
"repository": {
120-
"type": "git",
121-
"url": "https://github.com/microsoft/vscode.git"
122-
}
2+
"name": "ipynb",
3+
"displayName": "%displayName%",
4+
"description": "%description%",
5+
"publisher": "vscode",
6+
"version": "1.0.0",
7+
"license": "MIT",
8+
"engines": {
9+
"vscode": "^1.57.0"
10+
},
11+
"enabledApiProposals": [
12+
"documentPaste",
13+
"diffContentOptions",
14+
"dropMetadata"
15+
],
16+
"activationEvents": [
17+
"onNotebook:jupyter-notebook",
18+
"onNotebook:interactive"
19+
],
20+
"extensionKind": [
21+
"workspace",
22+
"ui"
23+
],
24+
"main": "./out/ipynbMain.js",
25+
"browser": "./dist/browser/ipynbMain.js",
26+
"capabilities": {
27+
"virtualWorkspaces": true,
28+
"untrustedWorkspaces": {
29+
"supported": true
30+
}
31+
},
32+
"contributes": {
33+
"configuration": [
34+
{
35+
"properties": {
36+
"ipynb.pasteImagesAsAttachments.enabled": {
37+
"type": "boolean",
38+
"scope": "resource",
39+
"markdownDescription": "%ipynb.pasteImagesAsAttachments.enabled%",
40+
"default": true
41+
}
42+
}
43+
}
44+
],
45+
"commands": [
46+
{
47+
"command": "ipynb.newUntitledIpynb",
48+
"title": "%newUntitledIpynb.title%",
49+
"shortTitle": "%newUntitledIpynb.shortTitle%",
50+
"category": "Create"
51+
},
52+
{
53+
"command": "ipynb.openIpynbInNotebookEditor",
54+
"title": "%openIpynbInNotebookEditor.title%"
55+
},
56+
{
57+
"command": "ipynb.cleanInvalidImageAttachment",
58+
"title": "%cleanInvalidImageAttachment.title%"
59+
}
60+
],
61+
"notebooks": [
62+
{
63+
"type": "jupyter-notebook",
64+
"displayName": "Jupyter Notebook",
65+
"selector": [
66+
{
67+
"filenamePattern": "*.ipynb"
68+
}
69+
],
70+
"priority": "default"
71+
}
72+
],
73+
"notebookRenderer": [
74+
{
75+
"id": "vscode.markdown-it-cell-attachment-renderer",
76+
"displayName": "%markdownAttachmentRenderer.displayName%",
77+
"entrypoint": {
78+
"extends": "vscode.markdown-it-renderer",
79+
"path": "./notebook-out/cellAttachmentRenderer.js"
80+
}
81+
}
82+
],
83+
"menus": {
84+
"file/newFile": [
85+
{
86+
"command": "ipynb.newUntitledIpynb",
87+
"group": "notebook"
88+
}
89+
],
90+
"commandPalette": [
91+
{
92+
"command": "ipynb.newUntitledIpynb"
93+
},
94+
{
95+
"command": "ipynb.openIpynbInNotebookEditor",
96+
"when": "false"
97+
},
98+
{
99+
"command": "ipynb.cleanInvalidImageAttachment",
100+
"when": "false"
101+
}
102+
]
103+
}
104+
},
105+
"scripts": {
106+
"compile": "npx gulp compile-extension:ipynb && npm run build-notebook",
107+
"watch": "npx gulp watch-extension:ipynb",
108+
"build-notebook": "node ./esbuild"
109+
},
110+
"dependencies": {
111+
"@enonic/fnv-plus": "^1.3.0",
112+
"detect-indent": "^6.0.0",
113+
"uuid": "^8.3.2"
114+
},
115+
"devDependencies": {
116+
"@jupyterlab/nbformat": "^3.2.9",
117+
"@types/markdown-it": "12.2.3",
118+
"@types/uuid": "^8.3.1"
119+
},
120+
"repository": {
121+
"type": "git",
122+
"url": "https://github.com/microsoft/vscode.git"
123+
}
123124
}

src/vs/workbench/contrib/interactive/browser/interactive.contribution.ts

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import { contrastBorder, listInactiveSelectionBackground, registerColor, transpa
3838
import { registerThemingParticipant } from 'vs/platform/theme/common/themeService';
3939
import { EditorPaneDescriptor, IEditorPaneRegistry } from 'vs/workbench/browser/editor';
4040
import { Extensions as WorkbenchExtensions, IWorkbenchContribution, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions';
41-
import { EditorExtensions, EditorsOrder, IEditorFactoryRegistry, IEditorSerializer } from 'vs/workbench/common/editor';
41+
import { EditorExtensions, EditorsOrder, IEditorFactoryRegistry, IEditorSerializer, IUntypedEditorInput } from 'vs/workbench/common/editor';
4242
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
4343
import { PANEL_BORDER } from 'vs/workbench/common/theme';
4444
import { ResourceNotebookCellEdit } from 'vs/workbench/contrib/bulkEdit/browser/bulkCellEdits';
@@ -81,7 +81,8 @@ export class InteractiveDocumentContribution extends Disposable implements IWork
8181
constructor(
8282
@INotebookService notebookService: INotebookService,
8383
@IEditorResolverService editorResolverService: IEditorResolverService,
84-
@IEditorService editorService: IEditorService
84+
@IEditorService editorService: IEditorService,
85+
@IInstantiationService private readonly instantiationService: IInstantiationService
8586
) {
8687
super();
8788

@@ -134,19 +135,36 @@ export class InteractiveDocumentContribution extends Disposable implements IWork
134135
{
135136
createEditorInput: ({ resource, options }) => {
136137
const data = CellUri.parse(resource);
137-
let notebookUri: URI = resource;
138138
let cellOptions: IResourceEditorInput | undefined;
139139

140140
if (data) {
141-
notebookUri = data.notebook;
142141
cellOptions = { resource, options };
143142
}
144143

145144
const notebookOptions = { ...options, cellOptions } as INotebookEditorOptions;
146145

147-
const editorInput = editorService.getEditors(EditorsOrder.SEQUENTIAL).find(editor => editor.editor instanceof InteractiveEditorInput && editor.editor.resource?.toString() === notebookUri.toString());
146+
const editorInput = createEditor(resource, this.instantiationService);
148147
return {
149-
editor: editorInput!.editor,
148+
editor: editorInput,
149+
options: notebookOptions
150+
};
151+
},
152+
createUntitledEditorInput: ({ resource, options }) => {
153+
if (!resource) {
154+
throw new Error('Interactive window editors must have a resource name');
155+
}
156+
const data = CellUri.parse(resource);
157+
let cellOptions: IResourceEditorInput | undefined;
158+
159+
if (data) {
160+
cellOptions = { resource, options };
161+
}
162+
163+
const notebookOptions = { ...options, cellOptions } as INotebookEditorOptions;
164+
165+
const editorInput = createEditor(resource, this.instantiationService);
166+
return {
167+
editor: editorInput,
150168
options: notebookOptions
151169
};
152170
}
@@ -180,6 +198,15 @@ class InteractiveInputContentProvider implements ITextModelContentProvider {
180198
}
181199
}
182200

201+
function createEditor(resource: URI, instantiationService: IInstantiationService): EditorInput {
202+
const counter = /\/Interactive-(\d+)/.exec(resource.path);
203+
const inputBoxPath = counter && counter[1] ? `/InteractiveInput-${counter[1]}` : 'InteractiveInput';
204+
const inputUri = URI.from({ scheme: Schemas.vscodeInteractiveInput, path: inputBoxPath });
205+
const editorInput = InteractiveEditorInput.create(instantiationService, resource, inputUri);
206+
207+
return editorInput;
208+
}
209+
183210
class InteractiveWindowWorkingCopyEditorHandler extends Disposable implements IWorkbenchContribution, IWorkingCopyEditorHandler {
184211

185212
constructor(
@@ -207,12 +234,7 @@ class InteractiveWindowWorkingCopyEditorHandler extends Disposable implements IW
207234
}
208235

209236
createEditor(workingCopy: IWorkingCopyIdentifier): EditorInput {
210-
const counter = /\/Interactive-(\d+)/.exec(workingCopy.resource.path);
211-
const inputBoxPath = counter && counter[1] ? `/InteractiveInput-${counter[1]}` : 'InteractiveInput';
212-
const inputUri = URI.from({ scheme: Schemas.vscodeInteractiveInput, path: inputBoxPath });
213-
const editorInput = InteractiveEditorInput.create(this._instantiationService, workingCopy.resource, inputUri);
214-
215-
return editorInput;
237+
return createEditor(workingCopy.resource, this._instantiationService);
216238
}
217239

218240
private async _installHandler(): Promise<void> {
@@ -386,9 +408,9 @@ registerAction2(class extends Action2 {
386408
}
387409
}
388410

389-
const editorInput = InteractiveEditorInput.create(accessor.get(IInstantiationService), notebookUri, inputUri, title);
390411
historyService.clearHistory(notebookUri);
391-
const editorPane = await editorService.openEditor(editorInput, editorOptions, group);
412+
const editorInput: IUntypedEditorInput = { resource: notebookUri, options: editorOptions };
413+
const editorPane = await editorService.openEditor(editorInput, group);
392414
const editorControl = editorPane?.getControl() as { notebookEditor: NotebookEditorWidget | undefined; codeEditor: CodeEditorWidget } | undefined;
393415
// Extensions must retain references to these URIs to manipulate the interactive editor
394416
logService.debug('New interactive window opened. Notebook editor id', editorControl?.notebookEditor?.getId());

src/vs/workbench/contrib/interactive/browser/interactiveEditorInput.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { IInteractiveHistoryService } from 'vs/workbench/contrib/interactive/bro
1818
import { IResolvedNotebookEditorModel } from 'vs/workbench/contrib/notebook/common/notebookCommon';
1919
import { ICompositeNotebookEditorInput, NotebookEditorInput } from 'vs/workbench/contrib/notebook/common/notebookEditorInput';
2020
import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
21+
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
2122

2223
export class InteractiveEditorInput extends EditorInput implements ICompositeNotebookEditorInput {
2324
static create(instantiationService: IInstantiationService, resource: URI, inputResource: URI, title?: string) {
@@ -79,6 +80,7 @@ export class InteractiveEditorInput extends EditorInput implements ICompositeNot
7980
@IInteractiveHistoryService historyService: IInteractiveHistoryService,
8081
@INotebookService private readonly _notebookService: INotebookService,
8182
@IFileDialogService private readonly _fileDialogService: IFileDialogService,
83+
@IExtensionService private readonly _extensionService: IExtensionService
8284
) {
8385
const input = NotebookEditorInput.create(instantiationService, resource, 'interactive', {});
8486
super();
@@ -136,6 +138,7 @@ export class InteractiveEditorInput extends EditorInput implements ICompositeNot
136138
return this._inputResolver;
137139
}
138140

141+
await this._extensionService.activateByEvent('onNotebook:interactive');
139142
this._inputResolver = this._resolveEditorModel();
140143

141144
return this._inputResolver;

0 commit comments

Comments
 (0)