first steps towards Tab#input

This commit is contained in:
Johannes
2022-03-17 16:43:09 +01:00
parent 72169d1bfb
commit 2f9632ec45
7 changed files with 182 additions and 31 deletions

View File

@@ -1325,6 +1325,8 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
WorkspaceTrustState: extHostTypes.WorkspaceTrustState,
LanguageStatusSeverity: extHostTypes.LanguageStatusSeverity,
QuickPickItemKind: extHostTypes.QuickPickItemKind,
TextTabInput: extHostTypes.TextTabInput,
TextDiffTabInput: extHostTypes.TextDiffTabInput,
};
};
}

View File

@@ -609,6 +609,51 @@ export interface ExtHostEditorInsetsShape {
//#region --- tabs model
export const enum TabInputKind {
UnknownInput,
TextInput,
TextDiffInput,
NotebookInput,
NotebookDiffInput,
CustomEditorInput
}
export interface UnknownInputDto {
kind: TabInputKind.UnknownInput;
}
export interface TextInputDto {
kind: TabInputKind.TextInput;
uri: UriComponents;
}
export interface TextDiffInputDto {
kind: TabInputKind.TextDiffInput;
original: UriComponents;
modified: UriComponents;
}
export interface NotebookInputDto {
kind: TabInputKind.NotebookInput;
notebookType: string;
uri: UriComponents;
}
export interface NotebookDiffInputDto {
kind: TabInputKind.NotebookDiffInput;
notebookType: string;
original: UriComponents;
modified: UriComponents;
}
export interface CustomInputDto {
kind: TabInputKind.CustomEditorInput;
viewType: string;
uri: UriComponents;
}
export type AnyInputDto = UnknownInputDto | TextInputDto | TextDiffInputDto | NotebookInputDto | NotebookDiffInputDto | CustomInputDto;
export interface MainThreadEditorTabsShape extends IDisposable {
// manage tabs: move, close, rearrange etc
$moveTab(tabId: string, index: number, viewColumn: EditorGroupColumn): void;
@@ -634,6 +679,7 @@ export interface IEditorTabDto {
id: string;
viewColumn: EditorGroupColumn;
label: string;
input: AnyInputDto;
resource?: UriComponents;
editorId?: string;
isActive: boolean;

View File

@@ -5,11 +5,11 @@
import type * as vscode from 'vscode';
import * as typeConverters from 'vs/workbench/api/common/extHostTypeConverters';
import { IEditorTabDto, IEditorTabGroupDto, IExtHostEditorTabsShape, MainContext, MainThreadEditorTabsShape } from 'vs/workbench/api/common/extHost.protocol';
import { IEditorTabDto, IEditorTabGroupDto, IExtHostEditorTabsShape, MainContext, MainThreadEditorTabsShape, TabInputKind } from 'vs/workbench/api/common/extHost.protocol';
import { URI } from 'vs/base/common/uri';
import { Emitter } from 'vs/base/common/event';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { ViewColumn } from 'vs/workbench/api/common/extHostTypes';
import { TextDiffTabInput, TextTabInput, ViewColumn } from 'vs/workbench/api/common/extHostTypes';
import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService';
export interface IExtHostEditorTabs extends IExtHostEditorTabsShape {
@@ -19,17 +19,19 @@ export interface IExtHostEditorTabs extends IExtHostEditorTabsShape {
export const IExtHostEditorTabs = createDecorator<IExtHostEditorTabs>('IExtHostEditorTabs');
type AnyTab = TextTabInput | TextDiffTabInput;
class ExtHostEditorTab {
private _apiObject: vscode.Tab | undefined;
private _dto: IEditorTabDto;
private _proxy: MainThreadEditorTabsShape;
private _activeTabIdGetter: () => string;
private _dto!: IEditorTabDto;
private _input: AnyTab | undefined;
private readonly _proxy: MainThreadEditorTabsShape;
private readonly _activeTabIdGetter: () => string;
constructor(dto: IEditorTabDto, proxy: MainThreadEditorTabsShape, activeTabIdGetter: () => string) {
this._dto = dto;
this._proxy = proxy;
this._activeTabIdGetter = activeTabIdGetter;
this.acceptDtoUpdate(dto);
}
get apiObject(): vscode.Tab {
@@ -44,6 +46,9 @@ class ExtHostEditorTab {
get label() {
return that._dto.label;
},
get input() {
return that._input;
},
get resource() {
return URI.revive(that._dto.resource);
},
@@ -80,8 +85,19 @@ class ExtHostEditorTab {
acceptDtoUpdate(dto: IEditorTabDto) {
this._dto = dto;
this._input = this._initInput();
}
private _initInput() {
switch (this._dto.input.kind) {
case TabInputKind.TextInput:
return new TextTabInput(URI.revive(this._dto.input.uri));
case TabInputKind.TextDiffInput:
return new TextDiffTabInput(URI.revive(this._dto.input.original), URI.revive(this._dto.input.modified));
// TODO@lramos15 support all the cases
}
return undefined;
}
}
class ExtHostEditorTabGroup {

View File

@@ -3595,3 +3595,13 @@ export class TypeHierarchyItem {
this.selectionRange = selectionRange;
}
}
// ---
export class TextTabInput {
constructor(readonly uri: URI) { }
}
export class TextDiffTabInput {
constructor(readonly original: URI, readonly modified: URI) { }
}