mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-14 20:34:30 +01:00
add more log calls to some services (for #41680)
This commit is contained in:
@@ -9,6 +9,7 @@ import { createDecorator } from 'vs/platform/instantiation/common/instantiation'
|
||||
import Event, { Emitter } from 'vs/base/common/event';
|
||||
|
||||
import { ipcRenderer as ipc } from 'electron';
|
||||
import { ILogService } from 'vs/platform/log/common/log';
|
||||
|
||||
export const IBroadcastService = createDecorator<IBroadcastService>('broadcastService');
|
||||
|
||||
@@ -30,7 +31,10 @@ export class BroadcastService implements IBroadcastService {
|
||||
|
||||
private _onBroadcast: Emitter<IBroadcast>;
|
||||
|
||||
constructor(private windowId: number) {
|
||||
constructor(
|
||||
private windowId: number,
|
||||
@ILogService private logService: ILogService
|
||||
) {
|
||||
this._onBroadcast = new Emitter<IBroadcast>();
|
||||
|
||||
this.registerListeners();
|
||||
@@ -38,6 +42,8 @@ export class BroadcastService implements IBroadcastService {
|
||||
|
||||
private registerListeners(): void {
|
||||
ipc.on('vscode:broadcast', (event, b: IBroadcast) => {
|
||||
this.logService.trace(`Received broadcast from main in window ${this.windowId}: `, b);
|
||||
|
||||
this._onBroadcast.fire(b);
|
||||
});
|
||||
}
|
||||
@@ -47,6 +53,8 @@ export class BroadcastService implements IBroadcastService {
|
||||
}
|
||||
|
||||
public broadcast(b: IBroadcast): void {
|
||||
this.logService.trace(`Sending broadcast to main from window ${this.windowId}: `, b);
|
||||
|
||||
ipc.send('vscode:broadcast', this.windowId, {
|
||||
channel: b.channel,
|
||||
payload: b.payload
|
||||
|
||||
@@ -15,6 +15,7 @@ import Event, { Emitter } from 'vs/base/common/event';
|
||||
import { IWindowService } from 'vs/platform/windows/common/windows';
|
||||
import { mark } from 'vs/base/common/performance';
|
||||
import { Barrier } from 'vs/base/common/async';
|
||||
import { ILogService } from 'vs/platform/log/common/log';
|
||||
|
||||
export class LifecycleService implements ILifecycleService {
|
||||
|
||||
@@ -32,10 +33,9 @@ export class LifecycleService implements ILifecycleService {
|
||||
constructor(
|
||||
@IMessageService private _messageService: IMessageService,
|
||||
@IWindowService private _windowService: IWindowService,
|
||||
@IStorageService private _storageService: IStorageService
|
||||
@IStorageService private _storageService: IStorageService,
|
||||
@ILogService private _logService: ILogService
|
||||
) {
|
||||
this._registerListeners();
|
||||
|
||||
const lastShutdownReason = this._storageService.getInteger(LifecycleService._lastShutdownReasonKey, StorageScope.WORKSPACE);
|
||||
this._storageService.remove(LifecycleService._lastShutdownReasonKey, StorageScope.WORKSPACE);
|
||||
if (lastShutdownReason === ShutdownReason.RELOAD) {
|
||||
@@ -45,51 +45,10 @@ export class LifecycleService implements ILifecycleService {
|
||||
} else {
|
||||
this._startupKind = StartupKind.NewWindow;
|
||||
}
|
||||
}
|
||||
|
||||
public get phase(): LifecyclePhase {
|
||||
return this._phase;
|
||||
}
|
||||
this._logService.trace(`lifecycle: starting up (startup kind: ${this._startupKind})`);
|
||||
|
||||
public set phase(value: LifecyclePhase) {
|
||||
if (value < this.phase) {
|
||||
throw new Error('Lifecycle cannot go backwards');
|
||||
}
|
||||
if (this._phase === value) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._phase = value;
|
||||
mark(`LifecyclePhase/${LifecyclePhase[value]}`);
|
||||
|
||||
if (this._phaseWhen.has(this._phase)) {
|
||||
this._phaseWhen.get(this._phase).open();
|
||||
this._phaseWhen.delete(this._phase);
|
||||
}
|
||||
}
|
||||
|
||||
public when(phase: LifecyclePhase): Thenable<any> {
|
||||
if (phase <= this._phase) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
let barrier = this._phaseWhen.get(phase);
|
||||
if (!barrier) {
|
||||
barrier = new Barrier();
|
||||
this._phaseWhen.set(phase, barrier);
|
||||
}
|
||||
return barrier.wait();
|
||||
}
|
||||
|
||||
public get startupKind(): StartupKind {
|
||||
return this._startupKind;
|
||||
}
|
||||
|
||||
public get onWillShutdown(): Event<ShutdownEvent> {
|
||||
return this._onWillShutdown.event;
|
||||
}
|
||||
|
||||
public get onShutdown(): Event<ShutdownReason> {
|
||||
return this._onShutdown.event;
|
||||
this._registerListeners();
|
||||
}
|
||||
|
||||
private _registerListeners(): void {
|
||||
@@ -97,14 +56,19 @@ export class LifecycleService implements ILifecycleService {
|
||||
|
||||
// Main side indicates that window is about to unload, check for vetos
|
||||
ipc.on('vscode:onBeforeUnload', (event, reply: { okChannel: string, cancelChannel: string, reason: ShutdownReason }) => {
|
||||
this._logService.trace(`lifecycle: onBeforeUnload (reason: ${reply.reason})`);
|
||||
|
||||
// store shutdown reason to retrieve next startup
|
||||
this._storageService.store(LifecycleService._lastShutdownReasonKey, JSON.stringify(reply.reason), StorageScope.WORKSPACE);
|
||||
|
||||
// trigger onWillShutdown events and veto collecting
|
||||
this.onBeforeUnload(reply.reason).done(veto => {
|
||||
if (veto) {
|
||||
this._logService.trace('lifecycle: onBeforeUnload prevented via veto');
|
||||
this._storageService.remove(LifecycleService._lastShutdownReasonKey, StorageScope.WORKSPACE);
|
||||
ipc.send(reply.cancelChannel, windowId);
|
||||
} else {
|
||||
this._logService.trace('lifecycle: onBeforeUnload continues without veto');
|
||||
ipc.send(reply.okChannel, windowId);
|
||||
}
|
||||
});
|
||||
@@ -112,6 +76,8 @@ export class LifecycleService implements ILifecycleService {
|
||||
|
||||
// Main side indicates that we will indeed shutdown
|
||||
ipc.on('vscode:onWillUnload', (event, reply: { replyChannel: string, reason: ShutdownReason }) => {
|
||||
this._logService.trace(`lifecycle: onWillUnload (reason: ${reply.reason})`);
|
||||
|
||||
this._onShutdown.fire(reply.reason);
|
||||
ipc.send(reply.replyChannel, windowId);
|
||||
});
|
||||
@@ -129,4 +95,54 @@ export class LifecycleService implements ILifecycleService {
|
||||
|
||||
return handleVetos(vetos, err => this._messageService.show(Severity.Error, toErrorMessage(err)));
|
||||
}
|
||||
|
||||
public get phase(): LifecyclePhase {
|
||||
return this._phase;
|
||||
}
|
||||
|
||||
public set phase(value: LifecyclePhase) {
|
||||
if (value < this.phase) {
|
||||
throw new Error('Lifecycle cannot go backwards');
|
||||
}
|
||||
|
||||
if (this._phase === value) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._logService.trace(`lifecycle: phase changed (value: ${value})`);
|
||||
|
||||
this._phase = value;
|
||||
mark(`LifecyclePhase/${LifecyclePhase[value]}`);
|
||||
|
||||
if (this._phaseWhen.has(this._phase)) {
|
||||
this._phaseWhen.get(this._phase).open();
|
||||
this._phaseWhen.delete(this._phase);
|
||||
}
|
||||
}
|
||||
|
||||
public when(phase: LifecyclePhase): Thenable<any> {
|
||||
if (phase <= this._phase) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
let barrier = this._phaseWhen.get(phase);
|
||||
if (!barrier) {
|
||||
barrier = new Barrier();
|
||||
this._phaseWhen.set(phase, barrier);
|
||||
}
|
||||
|
||||
return barrier.wait();
|
||||
}
|
||||
|
||||
public get startupKind(): StartupKind {
|
||||
return this._startupKind;
|
||||
}
|
||||
|
||||
public get onWillShutdown(): Event<ShutdownEvent> {
|
||||
return this._onWillShutdown.event;
|
||||
}
|
||||
|
||||
public get onShutdown(): Event<ShutdownReason> {
|
||||
return this._onShutdown.event;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,15 +190,20 @@ export class LifecycleService implements ILifecycleService {
|
||||
// first ask the window itself if it vetos the unload
|
||||
return this.onBeforeUnloadWindowInRenderer(window, windowUnloadReason).then(veto => {
|
||||
if (veto) {
|
||||
this.logService.trace('Lifecycle#unload(): veto in renderer', window.id);
|
||||
|
||||
return this.handleVeto(veto);
|
||||
}
|
||||
|
||||
// then check for vetos in the main side
|
||||
return this.onBeforeUnloadWindowInMain(window, windowUnloadReason).then(veto => {
|
||||
if (veto) {
|
||||
return this.handleVeto(veto);
|
||||
}
|
||||
this.logService.trace('Lifecycle#unload(): veto in main', window.id);
|
||||
|
||||
return this.handleVeto(veto);
|
||||
} else {
|
||||
this.logService.trace('Lifecycle#unload(): unload continues without veto', window.id);
|
||||
}
|
||||
|
||||
// finally if there are no vetos, unload the renderer
|
||||
return this.onWillUnloadWindowInRenderer(window, windowUnloadReason).then(() => false);
|
||||
@@ -294,10 +299,14 @@ export class LifecycleService implements ILifecycleService {
|
||||
}
|
||||
|
||||
public kill(code?: number): void {
|
||||
this.logService.trace('Lifecycle#kill()');
|
||||
|
||||
app.exit(code);
|
||||
}
|
||||
|
||||
public relaunch(options?: { addArgs?: string[], removeArgs?: string[] }): void {
|
||||
this.logService.trace('Lifecycle#relaunch()');
|
||||
|
||||
const args = process.argv.slice(1);
|
||||
if (options && options.addArgs) {
|
||||
args.push(...options.addArgs);
|
||||
|
||||
@@ -340,7 +340,7 @@ export class WorkbenchShell {
|
||||
|
||||
const instantiationService: IInstantiationService = new InstantiationService(serviceCollection, true);
|
||||
|
||||
this.broadcastService = new BroadcastService(this.configuration.windowId);
|
||||
this.broadcastService = instantiationService.createInstance(BroadcastService, this.configuration.windowId);
|
||||
serviceCollection.set(IBroadcastService, this.broadcastService);
|
||||
|
||||
serviceCollection.set(IWindowService, new SyncDescriptor(WindowService, this.configuration.windowId, this.configuration));
|
||||
|
||||
Reference in New Issue
Block a user