Skip to content

Commit 28d3032

Browse files
committed
1 parent 2c083a7 commit 28d3032

File tree

3 files changed

+48
-18
lines changed

3 files changed

+48
-18
lines changed

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

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { localize } from 'vs/nls';
77
import { VSBuffer } from 'vs/base/common/buffer';
88
import { CancellationToken } from 'vs/base/common/cancellation';
99
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
10-
import { Disposable } from 'vs/base/common/lifecycle';
10+
import { Disposable, IDisposable } from 'vs/base/common/lifecycle';
1111
import { parse } from 'vs/base/common/marshalling';
1212
import { assertType } from 'vs/base/common/types';
1313
import { URI } from 'vs/base/common/uri';
@@ -52,6 +52,9 @@ import { peekViewBorder /*, peekViewEditorBackground, peekViewResultsBackground
5252
import * as icons from 'vs/workbench/contrib/notebook/browser/notebookIcons';
5353
import { isFalsyOrWhitespace } from 'vs/base/common/strings';
5454
import { EditOperation } from 'vs/editor/common/core/editOperation';
55+
import { ITextModelContentProvider, ITextModelService } from 'vs/editor/common/services/resolverService';
56+
import { ITextModel } from 'vs/editor/common/model';
57+
import { IModelService } from 'vs/editor/common/services/modelService';
5558

5659

5760
Registry.as<IEditorPaneRegistry>(EditorExtensions.EditorPane).registerEditorPane(
@@ -218,8 +221,35 @@ export class InteractiveDocumentContribution extends Disposable implements IWork
218221
}
219222
}
220223

224+
class InteractiveInputContentProvider implements ITextModelContentProvider {
225+
226+
private readonly _registration: IDisposable;
227+
228+
constructor(
229+
@ITextModelService textModelService: ITextModelService,
230+
@IModelService private readonly _modelService: IModelService,
231+
) {
232+
this._registration = textModelService.registerTextModelContentProvider(Schemas.vscodeInteractiveInput, this);
233+
}
234+
235+
dispose(): void {
236+
this._registration.dispose();
237+
}
238+
239+
async provideTextContent(resource: URI): Promise<ITextModel | null> {
240+
const existing = this._modelService.getModel(resource);
241+
if (existing) {
242+
return existing;
243+
}
244+
let result: ITextModel | null = this._modelService.createModel('', null, resource, false);
245+
return result;
246+
}
247+
}
248+
249+
221250
const workbenchContributionsRegistry = Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench);
222251
workbenchContributionsRegistry.registerWorkbenchContribution(InteractiveDocumentContribution, LifecyclePhase.Starting);
252+
workbenchContributionsRegistry.registerWorkbenchContribution(InteractiveInputContentProvider, LifecyclePhase.Starting);
223253

224254
export class InteractiveEditorSerializer implements IEditorSerializer {
225255
canSerialize(): boolean {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ export class InteractiveEditor extends EditorPane {
330330
}
331331
}));
332332

333-
const editorModel = input.resolveInput(this.#notebookWidget.value?.activeKernel?.supportedLanguages[0] ?? 'plaintext');
333+
const editorModel = await input.resolveInput(this.#notebookWidget.value?.activeKernel?.supportedLanguages[0] ?? 'plaintext');
334334
this.#codeEditorWidget.setModel(editorModel);
335335
this.#widgetDisposableStore.add(this.#codeEditorWidget.onDidFocusEditorWidget(() => this.#onDidFocusWidget.fire()));
336336
this.#widgetDisposableStore.add(this.#codeEditorWidget.onDidContentSizeChange(e => {

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { Event } from 'vs/base/common/event';
7+
import { IReference } from 'vs/base/common/lifecycle';
78
import * as paths from 'vs/base/common/path';
89
import { isEqual } from 'vs/base/common/resources';
910
import { URI } from 'vs/base/common/uri';
10-
import { ITextModel } from 'vs/editor/common/model';
1111
import { IModelService } from 'vs/editor/common/services/modelService';
12+
import { IResolvedTextEditorModel, ITextModelService } from 'vs/editor/common/services/resolverService';
1213
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
1314
import { IUntypedEditorInput } from 'vs/workbench/common/editor';
1415
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
@@ -54,16 +55,12 @@ export class InteractiveEditorInput extends EditorInput implements ICompositeNot
5455
private _inputResolver: Promise<IResolvedNotebookEditorModel | null> | null;
5556
private _editorModelReference: IResolvedNotebookEditorModel | null;
5657

57-
private _inputModel: ITextModel | null;
58-
59-
get inputModel() {
60-
return this._inputModel;
61-
}
58+
private _inputModelRef: IReference<IResolvedTextEditorModel> | null;
6259

6360
get primary(): EditorInput {
6461
return this._notebookEditorInput;
6562
}
66-
private _modelService: IModelService;
63+
private _textModelService: ITextModelService;
6764
private _interactiveDocumentService: IInteractiveDocumentService;
6865

6966

@@ -73,6 +70,8 @@ export class InteractiveEditorInput extends EditorInput implements ICompositeNot
7370
title: string | undefined,
7471
@IInstantiationService instantiationService: IInstantiationService,
7572
@IModelService modelService: IModelService,
73+
@ITextModelService textModelService: ITextModelService,
74+
7675
@IInteractiveDocumentService interactiveDocumentService: IInteractiveDocumentService
7776
) {
7877
const input = NotebookEditorInput.create(instantiationService, resource, 'interactive', {});
@@ -83,8 +82,8 @@ export class InteractiveEditorInput extends EditorInput implements ICompositeNot
8382
this._inputResource = inputResource;
8483
this._inputResolver = null;
8584
this._editorModelReference = null;
86-
this._inputModel = null;
87-
this._modelService = modelService;
85+
this._inputModelRef = null;
86+
this._textModelService = textModelService;
8887
this._interactiveDocumentService = interactiveDocumentService;
8988

9089
this._registerListeners();
@@ -131,14 +130,15 @@ export class InteractiveEditorInput extends EditorInput implements ICompositeNot
131130
return this._inputResolver;
132131
}
133132

134-
resolveInput(language: string) {
135-
if (this._inputModel) {
136-
return this._inputModel;
133+
async resolveInput(language: string) {
134+
if (this._inputModelRef) {
135+
return this._inputModelRef.object.textEditorModel;
137136
}
138137

139138
this._interactiveDocumentService.willCreateInteractiveDocument(this.resource!, this.inputResource, language);
140-
this._inputModel = this._modelService.createModel('', null, this.inputResource, false);
141-
return this._inputModel;
139+
this._inputModelRef = await this._textModelService.createModelReference(this.inputResource);
140+
141+
return this._inputModelRef.object.textEditorModel;
142142
}
143143

144144
override matches(otherInput: EditorInput | IUntypedEditorInput): boolean {
@@ -170,8 +170,8 @@ export class InteractiveEditorInput extends EditorInput implements ICompositeNot
170170
this._editorModelReference?.dispose();
171171
this._editorModelReference = null;
172172
this._interactiveDocumentService.willRemoveInteractiveDocument(this.resource!, this.inputResource);
173-
this._inputModel?.dispose();
174-
this._inputModel = null;
173+
this._inputModelRef?.dispose();
174+
this._inputModelRef = null;
175175
super.dispose();
176176
}
177177
}

0 commit comments

Comments
 (0)