Implements a starting tab reading API (#131998)

* Clean up proposed.d.ts

* More API Polish

* Allow resource to be undefined

* Fix hygiene

* Address feedback

* Remove unnecessary iteration

* Use index from map
This commit is contained in:
Logan Ramos
2021-09-02 10:48:38 -04:00
committed by GitHub
parent 45a1f368f0
commit c2d0a69f87
5 changed files with 97 additions and 38 deletions

View File

@@ -8,18 +8,21 @@ import { IEditorTabDto, IExtHostEditorTabsShape } from 'vs/workbench/api/common/
import { URI } from 'vs/base/common/uri';
import { Emitter, Event } from 'vs/base/common/event';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { ViewColumn } from 'vs/workbench/api/common/extHostTypes';
export interface IEditorTab {
name: string;
group: number;
resource: vscode.Uri
label: string;
viewColumn: ViewColumn;
resource?: vscode.Uri
isActive: boolean
}
export interface IExtHostEditorTabs extends IExtHostEditorTabsShape {
readonly _serviceBrand: undefined;
tabs: readonly IEditorTab[];
onDidChangeTabs: Event<void>;
activeTab: IEditorTab | undefined;
onDidChangeActiveTab: Event<IEditorTab | undefined>;
onDidChangeTabs: Event<IEditorTab[]>;
}
export const IExtHostEditorTabs = createDecorator<IExtHostEditorTabs>('IExtHostEditorTabs');
@@ -27,24 +30,38 @@ export const IExtHostEditorTabs = createDecorator<IExtHostEditorTabs>('IExtHostE
export class ExtHostEditorTabs implements IExtHostEditorTabs {
readonly _serviceBrand: undefined;
private readonly _onDidChangeTabs = new Emitter<void>();
readonly onDidChangeTabs: Event<void> = this._onDidChangeTabs.event;
private readonly _onDidChangeTabs = new Emitter<IEditorTab[]>();
readonly onDidChangeTabs: Event<IEditorTab[]> = this._onDidChangeTabs.event;
private readonly _onDidChangeActiveTab = new Emitter<IEditorTab | undefined>();
readonly onDidChangeActiveTab: Event<IEditorTab | undefined> = this._onDidChangeActiveTab.event;
private _tabs: IEditorTab[] = [];
private _activeTab: IEditorTab | undefined;
get tabs(): readonly IEditorTab[] {
return this._tabs;
}
get activeTab(): IEditorTab | undefined {
return this._activeTab;
}
$acceptEditorTabs(tabs: IEditorTabDto[]): void {
this._tabs = tabs.map(dto => {
return {
name: dto.name,
group: dto.group,
let activeIndex = -1;
this._tabs = tabs.map((dto, index) => {
if (dto.isActive) {
activeIndex = index;
}
return Object.freeze({
label: dto.label,
viewColumn: dto.viewColumn,
resource: URI.revive(dto.resource),
isActive: dto.isActive
};
});
});
this._onDidChangeTabs.fire();
this._activeTab = activeIndex === -1 ? undefined : this._tabs[activeIndex];
this._onDidChangeActiveTab.fire(this._activeTab);
this._onDidChangeTabs.fire(this._tabs);
}
}