mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-23 01:58:53 +01:00
Overhauls timeline display to stream in results
Implements many API review changes Fixes #89558
This commit is contained in:
@@ -9,12 +9,12 @@ import { URI } from 'vs/base/common/uri';
|
||||
import { ILogService } from 'vs/platform/log/common/log';
|
||||
import { MainContext, MainThreadTimelineShape, IExtHostContext, ExtHostTimelineShape, ExtHostContext } from 'vs/workbench/api/common/extHost.protocol';
|
||||
import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers';
|
||||
import { ITimelineService, TimelineItem, TimelineProviderDescriptor } from 'vs/workbench/contrib/timeline/common/timeline';
|
||||
import { ITimelineService, TimelineItem, TimelineProviderDescriptor, TimelineChangeEvent } from 'vs/workbench/contrib/timeline/common/timeline';
|
||||
|
||||
@extHostNamedCustomer(MainContext.MainThreadTimeline)
|
||||
export class MainThreadTimeline implements MainThreadTimelineShape {
|
||||
private readonly _proxy: ExtHostTimelineShape;
|
||||
private readonly _providerEmitters = new Map<string, Emitter<URI | undefined>>();
|
||||
private readonly _providerEmitters = new Map<string, Emitter<TimelineChangeEvent>>();
|
||||
|
||||
constructor(
|
||||
context: IExtHostContext,
|
||||
@@ -29,41 +29,41 @@ export class MainThreadTimeline implements MainThreadTimelineShape {
|
||||
}
|
||||
|
||||
$registerTimelineProvider(provider: TimelineProviderDescriptor): void {
|
||||
this.logService.trace(`MainThreadTimeline#registerTimelineProvider: source=${provider.source}`);
|
||||
this.logService.trace(`MainThreadTimeline#registerTimelineProvider: id=${provider.id}`);
|
||||
|
||||
const proxy = this._proxy;
|
||||
|
||||
const emitters = this._providerEmitters;
|
||||
let onDidChange = emitters.get(provider.source);
|
||||
let onDidChange = emitters.get(provider.id);
|
||||
if (onDidChange === undefined) {
|
||||
onDidChange = new Emitter<URI | undefined>();
|
||||
emitters.set(provider.source, onDidChange);
|
||||
onDidChange = new Emitter<TimelineChangeEvent>();
|
||||
emitters.set(provider.id, onDidChange);
|
||||
}
|
||||
|
||||
this._timelineService.registerTimelineProvider({
|
||||
...provider,
|
||||
onDidChange: onDidChange.event,
|
||||
provideTimeline(uri: URI, token: CancellationToken) {
|
||||
return proxy.$getTimeline(provider.source, uri, token);
|
||||
return proxy.$getTimeline(provider.id, uri, token);
|
||||
},
|
||||
dispose() {
|
||||
emitters.delete(provider.source);
|
||||
emitters.delete(provider.id);
|
||||
onDidChange?.dispose();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$unregisterTimelineProvider(source: string): void {
|
||||
this.logService.trace(`MainThreadTimeline#unregisterTimelineProvider: source=${source}`);
|
||||
$unregisterTimelineProvider(id: string): void {
|
||||
this.logService.trace(`MainThreadTimeline#unregisterTimelineProvider: id=${id}`);
|
||||
|
||||
this._timelineService.unregisterTimelineProvider(source);
|
||||
this._timelineService.unregisterTimelineProvider(id);
|
||||
}
|
||||
|
||||
$emitTimelineChangeEvent(source: string, uri: URI | undefined): void {
|
||||
this.logService.trace(`MainThreadTimeline#emitChangeEvent: source=${source}, uri=${uri?.toString(true)}`);
|
||||
$emitTimelineChangeEvent(e: TimelineChangeEvent): void {
|
||||
this.logService.trace(`MainThreadTimeline#emitChangeEvent: id=${e.id}, uri=${e.uri?.toString(true)}`);
|
||||
|
||||
const emitter = this._providerEmitters.get(source);
|
||||
emitter?.fire(uri);
|
||||
const emitter = this._providerEmitters.get(e.id!);
|
||||
emitter?.fire(e);
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
|
||||
@@ -764,7 +764,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
|
||||
},
|
||||
registerTimelineProvider: (scheme: string, provider: vscode.TimelineProvider) => {
|
||||
checkProposedApiEnabled(extension);
|
||||
return extHostTimeline.registerTimelineProvider(provider, extHostCommands.converter);
|
||||
return extHostTimeline.registerTimelineProvider(provider, extension.identifier, extHostCommands.converter);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ import { SaveReason } from 'vs/workbench/common/editor';
|
||||
import { ExtensionActivationReason } from 'vs/workbench/api/common/extHostExtensionActivator';
|
||||
import { TunnelDto } from 'vs/workbench/api/common/extHostTunnelService';
|
||||
import { TunnelOptions } from 'vs/platform/remote/common/tunnel';
|
||||
import { TimelineItem, TimelineProviderDescriptor } from 'vs/workbench/contrib/timeline/common/timeline';
|
||||
import { TimelineItem, TimelineProviderDescriptor, TimelineChangeEvent, TimelineItemWithSource } from 'vs/workbench/contrib/timeline/common/timeline';
|
||||
|
||||
export interface IEnvironment {
|
||||
isExtensionDevelopmentDebug: boolean;
|
||||
@@ -801,7 +801,7 @@ export interface MainThreadTunnelServiceShape extends IDisposable {
|
||||
export interface MainThreadTimelineShape extends IDisposable {
|
||||
$registerTimelineProvider(provider: TimelineProviderDescriptor): void;
|
||||
$unregisterTimelineProvider(source: string): void;
|
||||
$emitTimelineChangeEvent(source: string, uri: UriComponents | undefined): void;
|
||||
$emitTimelineChangeEvent(e: TimelineChangeEvent): void;
|
||||
|
||||
$getTimeline(uri: UriComponents, token: CancellationToken): Promise<TimelineItem[]>;
|
||||
}
|
||||
@@ -1451,7 +1451,7 @@ export interface ExtHostTunnelServiceShape {
|
||||
}
|
||||
|
||||
export interface ExtHostTimelineShape {
|
||||
$getTimeline(source: string, uri: UriComponents, token: CancellationToken): Promise<TimelineItem[]>;
|
||||
$getTimeline(source: string, uri: UriComponents, token: CancellationToken): Promise<TimelineItemWithSource[]>;
|
||||
}
|
||||
|
||||
// --- proxy identifiers
|
||||
|
||||
@@ -7,15 +7,16 @@ import * as vscode from 'vscode';
|
||||
import { UriComponents, URI } from 'vs/base/common/uri';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { ExtHostTimelineShape, MainThreadTimelineShape, IMainContext, MainContext } from 'vs/workbench/api/common/extHost.protocol';
|
||||
import { TimelineItem, TimelineItemWithSource, TimelineProvider } from 'vs/workbench/contrib/timeline/common/timeline';
|
||||
import { TimelineItemWithSource, TimelineProvider } from 'vs/workbench/contrib/timeline/common/timeline';
|
||||
import { IDisposable, toDisposable, DisposableStore } from 'vs/base/common/lifecycle';
|
||||
import { CancellationToken } from 'vs/base/common/cancellation';
|
||||
import { CommandsConverter } from 'vs/workbench/api/common/extHostCommands';
|
||||
import { ThemeIcon } from 'vs/workbench/api/common/extHostTypes';
|
||||
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
|
||||
|
||||
export interface IExtHostTimeline extends ExtHostTimelineShape {
|
||||
readonly _serviceBrand: undefined;
|
||||
$getTimeline(source: string, uri: UriComponents, token: vscode.CancellationToken): Promise<TimelineItem[]>;
|
||||
$getTimeline(id: string, uri: UriComponents, token: vscode.CancellationToken): Promise<TimelineItemWithSource[]>;
|
||||
}
|
||||
|
||||
export const IExtHostTimeline = createDecorator<IExtHostTimeline>('IExtHostTimeline');
|
||||
@@ -33,23 +34,24 @@ export class ExtHostTimeline implements IExtHostTimeline {
|
||||
this._proxy = mainContext.getProxy(MainContext.MainThreadTimeline);
|
||||
}
|
||||
|
||||
async $getTimeline(source: string, uri: UriComponents, token: vscode.CancellationToken): Promise<TimelineItem[]> {
|
||||
const provider = this._providers.get(source);
|
||||
async $getTimeline(id: string, uri: UriComponents, token: vscode.CancellationToken): Promise<TimelineItemWithSource[]> {
|
||||
const provider = this._providers.get(id);
|
||||
return provider?.provideTimeline(URI.revive(uri), token) ?? [];
|
||||
}
|
||||
|
||||
registerTimelineProvider(provider: vscode.TimelineProvider, commandConverter: CommandsConverter): IDisposable {
|
||||
registerTimelineProvider(provider: vscode.TimelineProvider, extensionId: ExtensionIdentifier, commandConverter: CommandsConverter): IDisposable {
|
||||
const timelineDisposables = new DisposableStore();
|
||||
|
||||
const convertTimelineItem = this.convertTimelineItem(provider.source, commandConverter, timelineDisposables);
|
||||
const convertTimelineItem = this.convertTimelineItem(provider.id, commandConverter, timelineDisposables);
|
||||
|
||||
let disposable: IDisposable | undefined;
|
||||
if (provider.onDidChange) {
|
||||
disposable = provider.onDidChange(this.emitTimelineChangeEvent(provider.source), this);
|
||||
disposable = provider.onDidChange(this.emitTimelineChangeEvent(provider.id), this);
|
||||
}
|
||||
|
||||
return this.registerTimelineProviderCore({
|
||||
...provider,
|
||||
onDidChange: undefined,
|
||||
async provideTimeline(uri: URI, token: CancellationToken) {
|
||||
timelineDisposables.clear();
|
||||
|
||||
@@ -98,30 +100,29 @@ export class ExtHostTimeline implements IExtHostTimeline {
|
||||
};
|
||||
}
|
||||
|
||||
private emitTimelineChangeEvent(source: string) {
|
||||
return (uri: vscode.Uri | undefined) => {
|
||||
this._proxy.$emitTimelineChangeEvent(source, uri);
|
||||
private emitTimelineChangeEvent(id: string) {
|
||||
return (e: vscode.TimelineChangeEvent) => {
|
||||
this._proxy.$emitTimelineChangeEvent({ ...e, id: id });
|
||||
};
|
||||
}
|
||||
|
||||
private registerTimelineProviderCore(provider: TimelineProvider): IDisposable {
|
||||
// console.log(`ExtHostTimeline#registerTimelineProvider: source=${provider.source}`);
|
||||
// console.log(`ExtHostTimeline#registerTimelineProvider: id=${provider.id}`);
|
||||
|
||||
const existing = this._providers.get(provider.source);
|
||||
if (existing && !existing.replaceable) {
|
||||
throw new Error(`Timeline Provider ${provider.source} already exists.`);
|
||||
const existing = this._providers.get(provider.id);
|
||||
if (existing) {
|
||||
throw new Error(`Timeline Provider ${provider.id} already exists.`);
|
||||
}
|
||||
|
||||
this._proxy.$registerTimelineProvider({
|
||||
source: provider.source,
|
||||
sourceDescription: provider.sourceDescription,
|
||||
replaceable: provider.replaceable
|
||||
id: provider.id,
|
||||
label: provider.label
|
||||
});
|
||||
this._providers.set(provider.source, provider);
|
||||
this._providers.set(provider.id, provider);
|
||||
|
||||
return toDisposable(() => {
|
||||
this._providers.delete(provider.source);
|
||||
this._proxy.$unregisterTimelineProvider(provider.source);
|
||||
this._providers.delete(provider.id);
|
||||
this._proxy.$unregisterTimelineProvider(provider.id);
|
||||
provider.dispose();
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user