Skip to content

Commit

Permalink
fix: 完善错误处理
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanba committed Jan 31, 2024
1 parent 2bfc1ea commit fc1d428
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { EndOfLine, NotebookCellKind, Uri } from './vscodeAdaptor.js';
export const l2c = {
asNotebookDocument(libroView: LibroView): NotebookDocument {
const model = libroView.model as any;
if (!model.filePath) {
if (model.filePath === undefined) {
throw new Error('no filePath: invalid libro jupyter model');
}
const filePath = model.filePath as string;
Expand All @@ -32,7 +32,7 @@ export const l2c = {

asNotebookCell(cell: CellView): NotebookCell {
const model = cell.parent.model as any;
if (!model.filePath) {
if (model.filePath === undefined) {
throw new Error('no filePath: invalid libro jupyter model');
}
const filePath = model.filePath as string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { LibroView } from '@difizen/libro-core';
import { LibroService } from '@difizen/libro-core';
import { inject, noop, singleton } from '@difizen/mana-app';
import type {
Expand Down Expand Up @@ -37,6 +38,13 @@ import { unsupported } from './util.js';
export class LibroWorkspace implements ILibroWorkspace {
@inject(LibroService) private readonly libroService: LibroService;

isValidNotebook(view: LibroView): boolean {
if ((view as any).lspEnabled === true) {
return true;
}
return false;
}

workspaceFolders: WorkspaceFolder[] | undefined = [];
getWorkspaceFolder(uri: Uri): WorkspaceFolder | undefined {
return;
Expand Down Expand Up @@ -78,26 +86,57 @@ export class LibroWorkspace implements ILibroWorkspace {
applyEdit(edit: WorkspaceEdit, metadata?: WorkspaceEditMetadata): Thenable<boolean> {
return Promise.resolve(true);
}
onDidOpenNotebookDocument: Event<NotebookDocument> = (listener) => {
onDidOpenNotebookDocument: Event<NotebookDocument> = (
listener,
thisArgs,
disposables,
) => {
const disposable = this.libroService.onNotebookViewCreated((libroView) => {
if (!this.isValidNotebook(libroView)) {
return;
}
listener(l2c.asNotebookDocument(libroView));
});
disposables?.push(disposable);
return disposable;
};
onDidSaveNotebookDocument: Event<NotebookDocument> = (listener) => {
onDidSaveNotebookDocument: Event<NotebookDocument> = (
listener,
thisArgs,
disposables,
) => {
const disposable = this.libroService.onNotebookViewSaved((libroView) => {
if (!this.isValidNotebook(libroView)) {
return;
}
listener(l2c.asNotebookDocument(libroView));
});
disposables?.push(disposable);
return disposable;
};
onDidCloseNotebookDocument: Event<NotebookDocument> = (listener) => {
onDidCloseNotebookDocument: Event<NotebookDocument> = (
listener,
thisArgs,
disposables,
) => {
const disposable = this.libroService.onNotebookViewClosed((libroView) => {
if (!this.isValidNotebook(libroView)) {
return;
}
listener(l2c.asNotebookDocument(libroView));
});
disposables?.push(disposable);
return disposable;
};
onDidChangeNotebookDocument: Event<NotebookDocumentChangeEvent> = (listener) => {
onDidChangeNotebookDocument: Event<NotebookDocumentChangeEvent> = (
listener,
thisArgs,
disposables,
) => {
const disposable = this.libroService.onNotebookViewChanged((e) => {
if (!this.isValidNotebook(e.libroView)) {
return;
}
listener({
notebook: l2c.asNotebookDocument(e.libroView),
metadata: {},
Expand All @@ -116,6 +155,7 @@ export class LibroWorkspace implements ILibroWorkspace {
}),
});
});
disposables?.push(disposable);
return disposable;
};

Expand Down

0 comments on commit fc1d428

Please sign in to comment.