Skip to content

Commit a1df84a

Browse files
committed
💄 strict typings, namings
1 parent e2d5e90 commit a1df84a

3 files changed

Lines changed: 23 additions & 35 deletions

File tree

src/vs/workbench/contrib/notebook/browser/notebookServiceImpl.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -657,43 +657,37 @@ export class NotebookService extends Disposable implements INotebookService, ICu
657657
return this.notebookRenderersInfoStore.get(id);
658658
}
659659

660-
async resolveNotebook(viewType: string, uri: URI, forceReload: boolean, editorId?: string, backupId?: string): Promise<NotebookTextModel | undefined> {
660+
async resolveNotebook(viewType: string, uri: URI, forceReload: boolean, editorId?: string, backupId?: string): Promise<NotebookTextModel> {
661661

662-
await this.canResolve(viewType);
663-
664-
const provider = this._notebookProviders.get(viewType);
665-
if (!provider) {
662+
if (!await this.canResolve(viewType)) {
666663
throw new Error(`CANNOT load notebook, no provider for '${viewType}'`);
667664
}
668665

669-
let notebookModel: NotebookTextModel | undefined = undefined;
666+
const provider = this._notebookProviders.get(viewType)!;
667+
let notebookModel: NotebookTextModel;
670668
if (this._models.has(uri)) {
671669
// the model already exists
672670
notebookModel = this._models.get(uri)!.model;
673671
if (forceReload) {
674672
await provider.controller.reloadNotebook(notebookModel);
675673
}
676-
677674
return notebookModel;
675+
678676
} else {
679677
notebookModel = this._instantiationService.createInstance(NotebookTextModel, NotebookService.mainthreadNotebookDocumentHandle++, viewType, provider.controller.supportBackup, uri);
680678
await provider.controller.createNotebook(notebookModel, backupId);
681-
682-
if (!notebookModel) {
683-
return undefined;
684-
}
685679
}
686680

687681
// new notebook model created
688682
const modelData = new ModelData(
689-
notebookModel!,
683+
notebookModel,
690684
(model) => this._onWillDisposeDocument(model),
691685
);
692686

693687
this._models.set(uri, modelData);
694-
this._onNotebookDocumentAdd.fire([notebookModel!.uri]);
688+
this._onNotebookDocumentAdd.fire([notebookModel.uri]);
695689
// after the document is added to the store and sent to ext host, we transform the ouputs
696-
await this.transformTextModelOutputs(notebookModel!);
690+
await this.transformTextModelOutputs(notebookModel);
697691

698692
if (editorId) {
699693
await provider.controller.resolveNotebookEditor(viewType, uri, editorId);

src/vs/workbench/contrib/notebook/common/notebookEditorModel.ts

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/no
1111
import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
1212
import { URI } from 'vs/base/common/uri';
1313
import { IWorkingCopyService, IWorkingCopy, IWorkingCopyBackup, WorkingCopyCapabilities } from 'vs/workbench/services/workingCopy/common/workingCopyService';
14-
import { basename } from 'vs/base/common/resources';
1514
import { CancellationTokenSource } from 'vs/base/common/cancellation';
1615
import { IBackupFileService } from 'vs/workbench/services/backup/common/backup';
1716
import { Schemas } from 'vs/base/common/network';
1817
import { IFileStatWithMetadata, IFileService } from 'vs/platform/files/common/files';
1918
import { INotificationService, Severity } from 'vs/platform/notification/common/notification';
19+
import { ILabelService } from 'vs/platform/label/common/label';
2020

2121

2222
export interface INotebookLoadOptions {
@@ -29,7 +29,7 @@ export interface INotebookLoadOptions {
2929
}
3030

3131

32-
export class NotebookEditorModel extends EditorModel implements IWorkingCopy, INotebookEditorModel {
32+
export class NotebookEditorModel extends EditorModel implements INotebookEditorModel {
3333
protected readonly _onDidChangeDirty = this._register(new Emitter<void>());
3434
readonly onDidChangeDirty = this._onDidChangeDirty.event;
3535
private readonly _onDidChangeContent = this._register(new Emitter<void>());
@@ -41,31 +41,29 @@ export class NotebookEditorModel extends EditorModel implements IWorkingCopy, IN
4141
return this._notebook;
4242
}
4343

44-
private _name!: string;
45-
46-
get name() {
47-
return this._name;
48-
}
49-
50-
private _workingCopyResource: URI;
44+
private readonly _name: string;
45+
private readonly _workingCopyResource: URI;
5146

5247
constructor(
53-
public readonly resource: URI,
54-
public readonly viewType: string,
48+
readonly resource: URI,
49+
readonly viewType: string,
5550
@INotebookService private readonly _notebookService: INotebookService,
5651
@IWorkingCopyService private readonly _workingCopyService: IWorkingCopyService,
5752
@IBackupFileService private readonly _backupFileService: IBackupFileService,
5853
@IFileService private readonly _fileService: IFileService,
59-
@INotificationService private readonly _notificationService: INotificationService
54+
@INotificationService private readonly _notificationService: INotificationService,
55+
@ILabelService labelService: ILabelService,
6056
) {
6157
super();
6258

59+
this._name = labelService.getUriBasenameLabel(resource);
60+
6361
const input = this;
6462
this._workingCopyResource = resource.with({ scheme: Schemas.vscodeNotebook });
6563
const workingCopyAdapter = new class implements IWorkingCopy {
6664
readonly resource = input._workingCopyResource;
67-
get name() { return input.name; }
68-
readonly capabilities = input.isUntitled() ? WorkingCopyCapabilities.Untitled : input.capabilities;
65+
get name() { return input._name; }
66+
readonly capabilities = input.isUntitled() ? WorkingCopyCapabilities.Untitled : WorkingCopyCapabilities.None;
6967
readonly onDidChangeDirty = input.onDidChangeDirty;
7068
readonly onDidChangeContent = input.onDidChangeContent;
7169
isDirty(): boolean { return input.isDirty(); }
@@ -77,8 +75,6 @@ export class NotebookEditorModel extends EditorModel implements IWorkingCopy, IN
7775
this._register(this._workingCopyService.registerWorkingCopy(workingCopyAdapter));
7876
}
7977

80-
capabilities = WorkingCopyCapabilities.None;
81-
8278
async backup(): Promise<IWorkingCopyBackup<NotebookDocumentBackupData>> {
8379
if (this._notebook.supportBackup) {
8480
const tokenSource = new CancellationTokenSource();
@@ -138,15 +134,13 @@ export class NotebookEditorModel extends EditorModel implements IWorkingCopy, IN
138134
}
139135

140136
private async _loadFromProvider(forceReloadFromDisk: boolean, editorId: string | undefined, backupId: string | undefined) {
141-
const notebook = await this._notebookService.resolveNotebook(this.viewType!, this.resource, forceReloadFromDisk, editorId, backupId);
142-
this._notebook = notebook!;
137+
this._notebook = await this._notebookService.resolveNotebook(this.viewType!, this.resource, forceReloadFromDisk, editorId, backupId);
138+
143139
const newStats = await this._resolveStats(this.resource);
144140
this._lastResolvedFileStat = newStats;
145141

146142
this._register(this._notebook);
147143

148-
this._name = basename(this._notebook!.uri);
149-
150144
this._register(this._notebook.onDidChangeContent(() => {
151145
this._onDidChangeContent.fire();
152146
}));

src/vs/workbench/contrib/notebook/common/notebookService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export interface INotebookService {
5858
getContributedNotebookOutputRenderers(id: string): NotebookOutputRendererInfo | undefined;
5959
getRendererInfo(id: string): INotebookRendererInfo | undefined;
6060

61-
resolveNotebook(viewType: string, uri: URI, forceReload: boolean, editorId?: string, backupId?: string): Promise<NotebookTextModel | undefined>;
61+
resolveNotebook(viewType: string, uri: URI, forceReload: boolean, editorId?: string, backupId?: string): Promise<NotebookTextModel>;
6262
getNotebookTextModel(uri: URI): NotebookTextModel | undefined;
6363
getNotebookTextModels(): Iterable<NotebookTextModel>;
6464
executeNotebook(viewType: string, uri: URI, kernelId: string): Promise<void>;

0 commit comments

Comments
 (0)