make getEditorById strict

This commit is contained in:
Johannes Rieken
2021-06-07 17:47:34 +02:00
parent a31c6c3550
commit 8006b8c9a4
4 changed files with 4 additions and 18 deletions

View File

@@ -106,20 +106,14 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {
});
}
getEditorById(editorId: string, strict: true): ExtHostNotebookEditor;
getEditorById(editorId: string): ExtHostNotebookEditor | undefined;
getEditorById(editorId: string, strict?: true): ExtHostNotebookEditor | undefined {
getEditorById(editorId: string): ExtHostNotebookEditor {
const editor = this._editors.get(editorId);
if (!editor && strict) {
if (!editor) {
throw new Error(`unknown text editor: ${editorId}. known editors: ${[...this._editors.keys()]} `);
}
return editor;
}
allEditors(): ExtHostNotebookEditor[] {
return [...this._editors.values()];
}
getIdByEditor(editor: vscode.NotebookEditor): string | undefined {
for (const [id, candidate] of this._editors) {
if (candidate.apiEditor === editor) {

View File

@@ -55,7 +55,7 @@ export class ExtHostNotebookEditors implements ExtHostNotebookEditorsShape {
$acceptEditorPropertiesChanged(id: string, data: INotebookEditorPropertiesChangeData): void {
this._logService.debug('ExtHostNotebook#$acceptEditorPropertiesChanged', id, data);
const editor = this._notebooksAndEditors.getEditorById(id, true);
const editor = this._notebooksAndEditors.getEditorById(id);
// ONE: make all state updates
if (data.visibleRanges) {
editor._acceptVisibleRanges(data.visibleRanges.ranges.map(typeConverters.NotebookRange.to));
@@ -81,7 +81,7 @@ export class ExtHostNotebookEditors implements ExtHostNotebookEditorsShape {
$acceptEditorViewColumns(data: INotebookEditorViewColumnInfo): void {
for (const id in data) {
const editor = this._notebooksAndEditors.getEditorById(id, true);
const editor = this._notebooksAndEditors.getEditorById(id);
editor._acceptViewColumn(typeConverters.ViewColumn.to(data[id]));
}
}

View File

@@ -286,10 +286,6 @@ export class ExtHostNotebookKernels implements ExtHostNotebookKernelsShape {
}
const editor = this._extHostNotebook.getEditorById(editorId);
if (!editor) {
throw new Error(`send message for UNKNOWN editor: ${editorId}`);
}
obj.onDidReceiveMessage.fire(Object.freeze({ editor: editor.apiEditor, message }));
}

View File

@@ -19,10 +19,6 @@ export class ExtHostNotebookRenderers implements ExtHostNotebookRenderersShape {
public $postRendererMessage(editorId: string, rendererId: string, message: unknown): void {
const editor = this._extHostNotebook.getEditorById(editorId);
if (!editor) {
return;
}
this._rendererMessageEmitters.get(rendererId)?.fire({ editor: editor.apiEditor, message });
}