mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-26 11:38:51 +01:00
#59209 Update output channel when visible
This commit is contained in:
@@ -128,6 +128,7 @@ export function createApiFactory(
|
||||
rpcProtocol.set(ExtHostContext.ExtHostExtensionService, extensionService);
|
||||
const extHostProgress = rpcProtocol.set(ExtHostContext.ExtHostProgress, new ExtHostProgress(rpcProtocol.getProxy(MainContext.MainThreadProgress)));
|
||||
const exthostCommentProviders = rpcProtocol.set(ExtHostContext.ExtHostComments, new ExtHostComments(rpcProtocol, extHostCommands.converter, extHostDocuments));
|
||||
const extHostOutputService = rpcProtocol.set(ExtHostContext.ExtHostOutputService, new ExtHostOutputService(initData.logsLocation, rpcProtocol));
|
||||
|
||||
// Check that no named customers are missing
|
||||
const expected: ProxyIdentifier<any>[] = Object.keys(ExtHostContext).map((key) => (<any>ExtHostContext)[key]);
|
||||
@@ -137,7 +138,6 @@ export function createApiFactory(
|
||||
const extHostMessageService = new ExtHostMessageService(rpcProtocol);
|
||||
const extHostDialogs = new ExtHostDialogs(rpcProtocol);
|
||||
const extHostStatusBar = new ExtHostStatusBar(rpcProtocol);
|
||||
const extHostOutputService = new ExtHostOutputService(initData.logsLocation, rpcProtocol);
|
||||
const extHostLanguages = new ExtHostLanguages(rpcProtocol, extHostDocuments);
|
||||
|
||||
// Register an output channel for exthost log
|
||||
|
||||
@@ -304,6 +304,7 @@ export interface MainThreadMessageServiceShape extends IDisposable {
|
||||
export interface MainThreadOutputServiceShape extends IDisposable {
|
||||
$register(label: string, log: boolean, file?: UriComponents): Thenable<string>;
|
||||
$append(channelId: string, value: string): Thenable<void>;
|
||||
$update(channelId: string): Thenable<void>;
|
||||
$clear(channelId: string): Thenable<void>;
|
||||
$reveal(channelId: string, preserveFocus: boolean): Thenable<void>;
|
||||
$close(channelId: string): Thenable<void>;
|
||||
@@ -989,6 +990,10 @@ export interface ExtHostLogServiceShape {
|
||||
$setLevel(level: LogLevel): void;
|
||||
}
|
||||
|
||||
export interface ExtHostOutputServiceShape {
|
||||
$setVisibleChannel(channelId: string | null): void;
|
||||
}
|
||||
|
||||
export interface ExtHostProgressShape {
|
||||
$acceptProgressCanceled(handle: number): void;
|
||||
}
|
||||
@@ -1066,5 +1071,6 @@ export const ExtHostContext = {
|
||||
ExtHostWebviews: createExtId<ExtHostWebviewsShape>('ExtHostWebviews'),
|
||||
ExtHostProgress: createMainId<ExtHostProgressShape>('ExtHostProgress'),
|
||||
ExtHostComments: createMainId<ExtHostCommentsShape>('ExtHostComments'),
|
||||
ExtHostUrls: createExtId<ExtHostUrlsShape>('ExtHostUrls')
|
||||
ExtHostUrls: createExtId<ExtHostUrlsShape>('ExtHostUrls'),
|
||||
ExtHostOutputService: createMainId<ExtHostOutputServiceShape>('ExtHostOutputService'),
|
||||
};
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { MainContext, MainThreadOutputServiceShape, IMainContext } from './extHost.protocol';
|
||||
import { MainContext, MainThreadOutputServiceShape, IMainContext, ExtHostOutputServiceShape } from './extHost.protocol';
|
||||
import * as vscode from 'vscode';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { posix } from 'path';
|
||||
@@ -13,11 +13,13 @@ import { toLocalISOString } from 'vs/base/common/date';
|
||||
|
||||
export abstract class AbstractExtHostOutputChannel implements vscode.OutputChannel {
|
||||
|
||||
protected readonly _id: Thenable<string>;
|
||||
readonly _id: Thenable<string>;
|
||||
private readonly _name: string;
|
||||
protected readonly _proxy: MainThreadOutputServiceShape;
|
||||
private _disposed: boolean;
|
||||
|
||||
visible: boolean = false;
|
||||
|
||||
constructor(name: string, log: boolean, file: URI, proxy: MainThreadOutputServiceShape) {
|
||||
this._name = name;
|
||||
this._proxy = proxy;
|
||||
@@ -93,6 +95,10 @@ export class ExtHostOutputChannelBackedByFile extends AbstractExtHostOutputChann
|
||||
append(value: string): void {
|
||||
this.validate();
|
||||
this._appender.append(value);
|
||||
if (this.visible) {
|
||||
this._appender.flush();
|
||||
this._id.then(id => this._proxy.$update(id));
|
||||
}
|
||||
}
|
||||
|
||||
show(columnOrPreserveFocus?: vscode.ViewColumn | boolean, preserveFocus?: boolean): void {
|
||||
@@ -117,17 +123,39 @@ export class ExtHostLogFileOutputChannel extends AbstractExtHostOutputChannel {
|
||||
}
|
||||
}
|
||||
|
||||
export class ExtHostOutputService {
|
||||
export class ExtHostOutputService implements ExtHostOutputServiceShape {
|
||||
|
||||
private _proxy: MainThreadOutputServiceShape;
|
||||
private _outputDir: string;
|
||||
private _channels: Map<string, AbstractExtHostOutputChannel> = new Map<string, AbstractExtHostOutputChannel>();
|
||||
private _visibleChannel: AbstractExtHostOutputChannel;
|
||||
|
||||
constructor(logsLocation: URI, mainContext: IMainContext) {
|
||||
this._outputDir = posix.join(logsLocation.fsPath, `output_logging_${toLocalISOString(new Date()).replace(/-|:|\.\d+Z$/g, '')}`);
|
||||
this._proxy = mainContext.getProxy(MainContext.MainThreadOutputService);
|
||||
}
|
||||
|
||||
$setVisibleChannel(channelId: string): void {
|
||||
if (this._visibleChannel) {
|
||||
this._visibleChannel.visible = false;
|
||||
}
|
||||
this._visibleChannel = null;
|
||||
if (channelId) {
|
||||
const channel = this._channels.get(channelId);
|
||||
if (channel) {
|
||||
this._visibleChannel = channel;
|
||||
this._visibleChannel.visible = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
createOutputChannel(name: string): vscode.OutputChannel {
|
||||
const channel = this._createOutputChannel(name);
|
||||
channel._id.then(id => this._channels.set(id, channel));
|
||||
return channel;
|
||||
}
|
||||
|
||||
private _createOutputChannel(name: string): AbstractExtHostOutputChannel {
|
||||
name = name.trim();
|
||||
if (!name) {
|
||||
throw new Error('illegal argument `name`. must not be falsy');
|
||||
|
||||
Reference in New Issue
Block a user