Skip to content

Commit d788479

Browse files
committed
set language, provide deserialized editor for recovery process
1 parent 76c8654 commit d788479

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

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

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -255,40 +255,37 @@ workbenchContributionsRegistry.registerWorkbenchContribution(InteractiveDocument
255255
workbenchContributionsRegistry.registerWorkbenchContribution(InteractiveInputContentProvider, LifecyclePhase.Ready);
256256
workbenchContributionsRegistry.registerWorkbenchContribution(InteractiveWindowWorkingCopyEditorHandler, LifecyclePhase.Ready);
257257

258+
type interactiveEditorInputData = { resource: URI; inputResource: URI; name: string; language: string };
259+
258260
export class InteractiveEditorSerializer implements IEditorSerializer {
259261
public static readonly ID = InteractiveEditorInput.ID;
260262

261-
constructor(@IConfigurationService private configurationService: IConfigurationService) {
262-
}
263-
264-
canSerialize(): boolean {
265-
return this.configurationService.getValue<boolean>(InteractiveWindowSetting.interactiveWindowRestore);
263+
canSerialize(editor: EditorInput): boolean {
264+
const interactiveEditorInput = editor as InteractiveEditorInput;
265+
return URI.isUri(interactiveEditorInput?.primary?.resource) && URI.isUri(interactiveEditorInput?.inputResource);
266266
}
267267

268268
serialize(input: EditorInput): string {
269269
assertType(input instanceof InteractiveEditorInput);
270270
return JSON.stringify({
271271
resource: input.primary.resource,
272272
inputResource: input.inputResource,
273-
name: input.getName()
273+
name: input.getName(),
274+
language: input.language
274275
});
275276
}
276277

277278
deserialize(instantiationService: IInstantiationService, raw: string) {
278-
if (!this.canSerialize()) {
279-
return undefined;
280-
}
281-
type Data = { resource: URI; inputResource: URI; data: any };
282-
const data = <Data>parse(raw);
279+
const data = <interactiveEditorInputData>parse(raw);
283280
if (!data) {
284281
return undefined;
285282
}
286-
const { resource, inputResource } = data;
287-
if (!data || !URI.isUri(resource) || !URI.isUri(inputResource)) {
283+
const { resource, inputResource, name, language } = data;
284+
if (!URI.isUri(resource) || !URI.isUri(inputResource)) {
288285
return undefined;
289286
}
290287

291-
const input = InteractiveEditorInput.create(instantiationService, resource, inputResource);
288+
const input = InteractiveEditorInput.create(instantiationService, resource, inputResource, name, language);
292289
return input;
293290
}
294291
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,9 @@ export class InteractiveEditor extends EditorPane {
457457
}
458458
}));
459459

460-
const editorModel = await input.resolveInput(this.#notebookWidget.value?.activeKernel?.supportedLanguages[0] ?? PLAINTEXT_LANGUAGE_ID);
460+
const languageId = this.#notebookWidget.value?.activeKernel?.supportedLanguages[0] ?? input.language ?? PLAINTEXT_LANGUAGE_ID;
461+
const editorModel = await input.resolveInput(languageId);
462+
editorModel.setLanguage(languageId);
461463
this.#codeEditorWidget.setModel(editorModel);
462464
if (viewState?.input) {
463465
this.#codeEditorWidget.restoreViewState(viewState.input);

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { IReference } from 'vs/base/common/lifecycle';
88
import * as paths from 'vs/base/common/path';
99
import { isEqual, joinPath } from 'vs/base/common/resources';
1010
import { URI } from 'vs/base/common/uri';
11+
import { PLAINTEXT_LANGUAGE_ID } from 'vs/editor/common/languages/modesRegistry';
1112
import { IResolvedTextEditorModel, ITextModelService } from 'vs/editor/common/services/resolverService';
1213
import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
1314
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
@@ -20,8 +21,8 @@ import { ICompositeNotebookEditorInput, NotebookEditorInput } from 'vs/workbench
2021
import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
2122

2223
export class InteractiveEditorInput extends EditorInput implements ICompositeNotebookEditorInput {
23-
static create(instantiationService: IInstantiationService, resource: URI, inputResource: URI, title?: string) {
24-
return instantiationService.createInstance(InteractiveEditorInput, resource, inputResource, title);
24+
static create(instantiationService: IInstantiationService, resource: URI, inputResource: URI, title?: string, language?: string) {
25+
return instantiationService.createInstance(InteractiveEditorInput, resource, inputResource, title, language);
2526
}
2627

2728
static readonly ID: string = 'workbench.input.interactive';
@@ -36,6 +37,11 @@ export class InteractiveEditorInput extends EditorInput implements ICompositeNot
3637

3738
private _initTitle?: string;
3839

40+
get language() {
41+
return this._inputModelRef?.object.textEditorModel.getLanguageId() ?? this._initLanguage;
42+
}
43+
private _initLanguage?: string;
44+
3945
private _notebookEditorInput: NotebookEditorInput;
4046
get notebookEditorInput() {
4147
return this._notebookEditorInput;
@@ -73,6 +79,7 @@ export class InteractiveEditorInput extends EditorInput implements ICompositeNot
7379
resource: URI,
7480
inputResource: URI,
7581
title: string | undefined,
82+
languageId: string | undefined,
7683
@IInstantiationService instantiationService: IInstantiationService,
7784
@ITextModelService textModelService: ITextModelService,
7885
@IInteractiveDocumentService interactiveDocumentService: IInteractiveDocumentService,
@@ -85,6 +92,7 @@ export class InteractiveEditorInput extends EditorInput implements ICompositeNot
8592
this._notebookEditorInput = input;
8693
this._register(this._notebookEditorInput);
8794
this._initTitle = title;
95+
this._initLanguage = languageId;
8896
this._resource = resource;
8997
this._inputResource = inputResource;
9098
this._inputResolver = null;
@@ -141,12 +149,13 @@ export class InteractiveEditorInput extends EditorInput implements ICompositeNot
141149
return this._inputResolver;
142150
}
143151

144-
async resolveInput(language: string) {
152+
async resolveInput(language?: string) {
145153
if (this._inputModelRef) {
146154
return this._inputModelRef.object.textEditorModel;
147155
}
148156

149-
this._interactiveDocumentService.willCreateInteractiveDocument(this.resource!, this.inputResource, language);
157+
const resolvedLanguage = language ?? this._initLanguage ?? PLAINTEXT_LANGUAGE_ID;
158+
this._interactiveDocumentService.willCreateInteractiveDocument(this.resource!, this.inputResource, resolvedLanguage);
150159
this._inputModelRef = await this._textModelService.createModelReference(this.inputResource);
151160

152161
return this._inputModelRef.object.textEditorModel;

0 commit comments

Comments
 (0)