Skip to content

Commit 4ecad47

Browse files
committed
1 parent f71f52f commit 4ecad47

17 files changed

Lines changed: 59 additions & 76 deletions

File tree

src/vs/code/electron-browser/sharedProcessMain.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import { ipcRenderer } from 'electron';
3636
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
3737
import { createSharedProcessContributions } from 'vs/code/electron-browser/contrib/contributions';
3838
import { createLogService } from 'vs/platform/log/node/spdlogService';
39-
import { ILogService, registerGlobalLogService } from 'vs/platform/log/common/log';
39+
import { ILogService } from 'vs/platform/log/common/log';
4040

4141
export interface ISharedProcessConfiguration {
4242
readonly machineId: string;
@@ -81,7 +81,6 @@ function main(server: Server, initData: ISharedProcessInitData, configuration: I
8181
const environmentService = new EnvironmentService(initData.args, process.execPath);
8282
const logService = createLogService('sharedprocess', environmentService);
8383
process.once('exit', () => logService.dispose());
84-
registerGlobalLogService(logService);
8584

8685
logService.info('main', JSON.stringify(configuration));
8786

src/vs/code/electron-main/main.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { ServicesAccessor, IInstantiationService } from 'vs/platform/instantiati
2121
import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService';
2222
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
2323
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
24-
import { ILogService, ConsoleLogMainService, MultiplexLogService, registerGlobalLogService } from 'vs/platform/log/common/log';
24+
import { ILogService, ConsoleLogMainService, MultiplexLogService } from 'vs/platform/log/common/log';
2525
import { StateService } from 'vs/platform/state/node/stateService';
2626
import { IStateService } from 'vs/platform/state/common/state';
2727
import { IBackupMainService } from 'vs/platform/backup/common/backup';
@@ -53,7 +53,6 @@ function createServices(args: ParsedArgs): IInstantiationService {
5353
const consoleLogService = new ConsoleLogMainService(environmentService);
5454
const logService = new MultiplexLogService([consoleLogService, spdlogService]);
5555

56-
registerGlobalLogService(logService);
5756
process.once('exit', () => logService.dispose());
5857

5958
// Eventually cleanup

src/vs/code/node/cliProcessMain.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import { getBaseLabel } from 'vs/base/common/labels';
3636
import { IStateService } from 'vs/platform/state/common/state';
3737
import { StateService } from 'vs/platform/state/node/stateService';
3838
import { createLogService } from 'vs/platform/log/node/spdlogService';
39-
import { registerGlobalLogService, ILogService } from 'vs/platform/log/common/log';
39+
import { ILogService } from 'vs/platform/log/common/log';
4040
import { isPromiseCanceledError } from 'vs/base/common/errors';
4141

4242
const notFound = (id: string) => localize('notFound', "Extension '{0}' not found.", id);
@@ -198,7 +198,6 @@ export function main(argv: ParsedArgs): TPromise<void> {
198198
const environmentService = new EnvironmentService(argv, process.execPath);
199199
const logService = createLogService('cli', environmentService);
200200
process.once('exit', () => logService.dispose());
201-
registerGlobalLogService(logService);
202201

203202
logService.info('main', argv);
204203

src/vs/platform/commands/common/commandService.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { IExtensionService } from 'vs/platform/extensions/common/extensions';
1111
import Event, { Emitter } from 'vs/base/common/event';
1212
import { Disposable } from 'vs/base/common/lifecycle';
1313
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
14-
import { log, LogLevel } from 'vs/platform/log/common/log';
14+
import { ILogService } from 'vs/platform/log/common/log';
1515

1616
export class CommandService extends Disposable implements ICommandService {
1717

@@ -25,14 +25,16 @@ export class CommandService extends Disposable implements ICommandService {
2525
constructor(
2626
@IInstantiationService private _instantiationService: IInstantiationService,
2727
@IExtensionService private _extensionService: IExtensionService,
28-
@IContextKeyService private _contextKeyService: IContextKeyService
28+
@IContextKeyService private _contextKeyService: IContextKeyService,
29+
@ILogService private _logService: ILogService
2930
) {
3031
super();
3132
this._extensionService.whenInstalledExtensionsRegistered().then(value => this._extensionHostIsReady = value);
3233
}
3334

34-
@log(LogLevel.Info, 'CommandService', (msg, id) => `${msg}(${id})`)
3535
executeCommand<T>(id: string, ...args: any[]): TPromise<T> {
36+
this._logService.info('CommandService#executeCommand', id);
37+
3638
// we always send an activation event, but
3739
// we don't wait for it when the extension
3840
// host didn't yet start and the command is already registered

src/vs/platform/commands/test/commandService.test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { ContextKeyService } from 'vs/platform/contextkey/browser/contextKeyServ
1616
import { SimpleConfigurationService } from 'vs/editor/standalone/browser/simpleServices';
1717
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
1818
import Event, { Emitter } from 'vs/base/common/event';
19+
import { NoopLogService } from 'vs/platform/log/common/log';
1920

2021
class SimpleExtensionService implements IExtensionService {
2122
_serviceBrand: any;
@@ -74,7 +75,7 @@ suite('CommandService', function () {
7475
lastEvent = activationEvent;
7576
return super.activateByEvent(activationEvent);
7677
}
77-
}, new ContextKeyService(new SimpleConfigurationService()));
78+
}, new ContextKeyService(new SimpleConfigurationService()), new NoopLogService());
7879

7980
return service.executeCommand('foo').then(() => {
8081
assert.ok(lastEvent, 'onCommand:foo');
@@ -92,7 +93,7 @@ suite('CommandService', function () {
9293
activateByEvent(activationEvent: string): TPromise<void> {
9394
return TPromise.wrapError<void>(new Error('bad_activate'));
9495
}
95-
}, new ContextKeyService(new SimpleConfigurationService()));
96+
}, new ContextKeyService(new SimpleConfigurationService()), new NoopLogService());
9697

9798
return service.executeCommand('foo').then(() => assert.ok(false), err => {
9899
assert.equal(err.message, 'bad_activate');
@@ -108,7 +109,7 @@ suite('CommandService', function () {
108109
whenInstalledExtensionsRegistered() {
109110
return new TPromise<boolean>(_resolve => { /*ignore*/ });
110111
}
111-
}, new ContextKeyService(new SimpleConfigurationService()));
112+
}, new ContextKeyService(new SimpleConfigurationService()), new NoopLogService());
112113

113114
service.executeCommand('bar');
114115
assert.equal(callCounter, 1);
@@ -125,7 +126,7 @@ suite('CommandService', function () {
125126
whenInstalledExtensionsRegistered() {
126127
return new TPromise<boolean>(_resolve => { resolveFunc = _resolve; });
127128
}
128-
}, new ContextKeyService(new SimpleConfigurationService()));
129+
}, new ContextKeyService(new SimpleConfigurationService()), new NoopLogService());
129130

130131
let r = service.executeCommand('bar');
131132
assert.equal(callCounter, 0);
@@ -144,7 +145,8 @@ suite('CommandService', function () {
144145
let commandService = new CommandService(
145146
new InstantiationService(),
146147
new SimpleExtensionService(),
147-
contextKeyService
148+
contextKeyService,
149+
new NoopLogService()
148150
);
149151

150152
let counter = 0;

src/vs/platform/log/common/log.ts

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
99
import { createDecorator as createServiceDecorator } from 'vs/platform/instantiation/common/instantiation';
10-
import { createDecorator } from 'vs/base/common/decorators';
1110
import { IDisposable } from 'vs/base/common/lifecycle';
1211
import { isWindows } from 'vs/base/common/platform';
1312

@@ -193,34 +192,3 @@ export class NoopLogService implements ILogService {
193192
critical(message: string | Error, ...args: any[]): void { }
194193
dispose(): void { }
195194
}
196-
197-
let globalLogService: ILogService = new NoopLogService();
198-
199-
export function registerGlobalLogService(logService: ILogService): void {
200-
globalLogService = logService;
201-
}
202-
203-
export function log(level: LogLevel, prefix: string, logFn?: (message: string, ...args: any[]) => string): Function {
204-
return createDecorator((fn, key) => {
205-
// TODO@Joao: load-time log level? return fn;
206-
207-
return function (this: any, ...args: any[]) {
208-
let message = `${prefix} - ${key}`;
209-
210-
if (logFn) {
211-
message = logFn(message, ...args);
212-
}
213-
214-
switch (level) {
215-
case LogLevel.Trace: globalLogService.trace(message); break;
216-
case LogLevel.Debug: globalLogService.debug(message); break;
217-
case LogLevel.Info: globalLogService.info(message); break;
218-
case LogLevel.Warning: globalLogService.warn(message); break;
219-
case LogLevel.Error: globalLogService.error(message); break;
220-
case LogLevel.Critical: globalLogService.critical(message); break;
221-
}
222-
223-
return fn.apply(this, args);
224-
};
225-
});
226-
}

src/vs/workbench/api/node/extHost.api.impl.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import { ExtHostDecorations } from 'vs/workbench/api/node/extHostDecorations';
5858
import { toGlobPattern, toLanguageSelector } from 'vs/workbench/api/node/extHostTypeConverters';
5959
import { ExtensionActivatedByAPI } from 'vs/workbench/api/node/extHostExtensionActivator';
6060
import { isFalsyOrEmpty } from 'vs/base/common/arrays';
61+
import { ILogService } from 'vs/platform/log/common/log';
6162

6263
export interface IExtensionApiFactory {
6364
(extension: IExtensionDescription): typeof vscode;
@@ -81,7 +82,8 @@ export function createApiFactory(
8182
threadService: ExtHostThreadService,
8283
extHostWorkspace: ExtHostWorkspace,
8384
extHostConfiguration: ExtHostConfiguration,
84-
extensionService: ExtHostExtensionService
85+
extensionService: ExtHostExtensionService,
86+
logService: ILogService
8587
): IExtensionApiFactory {
8688

8789
// Addressable instances
@@ -92,7 +94,7 @@ export function createApiFactory(
9294
const extHostDocumentContentProviders = threadService.set(ExtHostContext.ExtHostDocumentContentProviders, new ExtHostDocumentContentProvider(threadService, extHostDocumentsAndEditors));
9395
const extHostDocumentSaveParticipant = threadService.set(ExtHostContext.ExtHostDocumentSaveParticipant, new ExtHostDocumentSaveParticipant(extHostDocuments, threadService.get(MainContext.MainThreadEditors)));
9496
const extHostEditors = threadService.set(ExtHostContext.ExtHostEditors, new ExtHostEditors(threadService, extHostDocumentsAndEditors));
95-
const extHostCommands = threadService.set(ExtHostContext.ExtHostCommands, new ExtHostCommands(threadService, extHostHeapService));
97+
const extHostCommands = threadService.set(ExtHostContext.ExtHostCommands, new ExtHostCommands(threadService, extHostHeapService, logService));
9698
const extHostTreeViews = threadService.set(ExtHostContext.ExtHostTreeViews, new ExtHostTreeViews(threadService.get(MainContext.MainThreadTreeViews), extHostCommands));
9799
threadService.set(ExtHostContext.ExtHostWorkspace, extHostWorkspace);
98100
const extHostDebugService = threadService.set(ExtHostContext.ExtHostDebugService, new ExtHostDebugService(threadService, extHostWorkspace));
@@ -103,7 +105,7 @@ export function createApiFactory(
103105
const extHostFileSystemEvent = threadService.set(ExtHostContext.ExtHostFileSystemEventService, new ExtHostFileSystemEventService());
104106
const extHostQuickOpen = threadService.set(ExtHostContext.ExtHostQuickOpen, new ExtHostQuickOpen(threadService, extHostWorkspace, extHostCommands));
105107
const extHostTerminalService = threadService.set(ExtHostContext.ExtHostTerminalService, new ExtHostTerminalService(threadService));
106-
const extHostSCM = threadService.set(ExtHostContext.ExtHostSCM, new ExtHostSCM(threadService, extHostCommands));
108+
const extHostSCM = threadService.set(ExtHostContext.ExtHostSCM, new ExtHostSCM(threadService, extHostCommands, logService));
107109
const extHostTask = threadService.set(ExtHostContext.ExtHostTask, new ExtHostTask(threadService, extHostWorkspace));
108110
const extHostWindow = threadService.set(ExtHostContext.ExtHostWindow, new ExtHostWindow(threadService));
109111
threadService.set(ExtHostContext.ExtHostExtensionService, extensionService);

src/vs/workbench/api/node/extHostCommands.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { ExtHostHeapService } from 'vs/workbench/api/node/extHostHeapService';
1515
import { isFalsyOrEmpty } from 'vs/base/common/arrays';
1616
import * as modes from 'vs/editor/common/modes';
1717
import * as vscode from 'vscode';
18-
import { log, LogLevel } from 'vs/platform/log/common/log';
18+
import { ILogService } from 'vs/platform/log/common/log';
1919

2020
interface CommandHandler {
2121
callback: Function;
@@ -36,7 +36,8 @@ export class ExtHostCommands implements ExtHostCommandsShape {
3636

3737
constructor(
3838
mainContext: IMainContext,
39-
heapService: ExtHostHeapService
39+
heapService: ExtHostHeapService,
40+
private logService: ILogService
4041
) {
4142
this._proxy = mainContext.get(MainContext.MainThreadCommands);
4243
this._converter = new CommandsConverter(this, heapService);
@@ -50,8 +51,8 @@ export class ExtHostCommands implements ExtHostCommandsShape {
5051
this._argumentProcessors.push(processor);
5152
}
5253

53-
@log(LogLevel.Trace, 'ExtHostCommands', (msg, id) => `${msg}(${id})`)
5454
registerCommand(id: string, callback: <T>(...args: any[]) => T | Thenable<T>, thisArg?: any, description?: ICommandHandlerDescription): extHostTypes.Disposable {
55+
this.logService.trace('ExtHostCommands#registerCommand', id);
5556

5657
if (!id.trim().length) {
5758
throw new Error('invalid id');
@@ -71,8 +72,8 @@ export class ExtHostCommands implements ExtHostCommandsShape {
7172
});
7273
}
7374

74-
@log(LogLevel.Trace, 'ExtHostCommands', (msg, id) => `${msg}(${id})`)
7575
executeCommand<T>(id: string, ...args: any[]): Thenable<T> {
76+
this.logService.trace('ExtHostCommands#executeCommand', id);
7677

7778
if (this._commands.has(id)) {
7879
// we stay inside the extension host and support
@@ -136,8 +137,9 @@ export class ExtHostCommands implements ExtHostCommandsShape {
136137
}
137138
}
138139

139-
@log(LogLevel.Trace, 'ExtHostCommands', (msg, filterUnderscoreCommands) => `${msg}(${filterUnderscoreCommands})`)
140140
getCommands(filterUnderscoreCommands: boolean = false): Thenable<string[]> {
141+
this.logService.trace('ExtHostCommands#getCommands', filterUnderscoreCommands);
142+
141143
return this._proxy.$getCommands().then(result => {
142144
if (filterUnderscoreCommands) {
143145
result = result.filter(command => command[0] !== '_');

src/vs/workbench/api/node/extHostExtensionService.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { ExtHostWorkspace } from 'vs/workbench/api/node/extHostWorkspace';
2121
import { realpath } from 'fs';
2222
import { TernarySearchTree } from 'vs/base/common/map';
2323
import { Barrier } from 'vs/base/common/async';
24+
import { ILogService } from 'vs/platform/log/common/log';
2425

2526
class ExtensionMemento implements IExtensionMemento {
2627

@@ -125,7 +126,8 @@ export class ExtHostExtensionService implements ExtHostExtensionServiceShape {
125126
constructor(initData: IInitData,
126127
threadService: ExtHostThreadService,
127128
extHostWorkspace: ExtHostWorkspace,
128-
extHostConfiguration: ExtHostConfiguration
129+
extHostConfiguration: ExtHostConfiguration,
130+
logService: ILogService
129131
) {
130132
this._barrier = new Barrier();
131133
this._registry = new ExtensionDescriptionRegistry(initData.extensions);
@@ -137,7 +139,7 @@ export class ExtHostExtensionService implements ExtHostExtensionServiceShape {
137139
this._activator = null;
138140

139141
// initialize API first (i.e. do not release barrier until the API is initialized)
140-
const apiFactory = createApiFactory(initData, threadService, extHostWorkspace, extHostConfiguration, this);
142+
const apiFactory = createApiFactory(initData, threadService, extHostWorkspace, extHostConfiguration, this, logService);
141143

142144
initializeExtensionApi(this, apiFactory).then(() => {
143145

src/vs/workbench/api/node/extHostSCM.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { sortedDiff } from 'vs/base/common/arrays';
1717
import { comparePaths } from 'vs/base/common/comparers';
1818
import * as vscode from 'vscode';
1919
import { ISplice } from 'vs/base/common/sequence';
20-
import { log, LogLevel } from 'vs/platform/log/common/log';
20+
import { ILogService } from 'vs/platform/log/common/log';
2121

2222
type ProviderHandle = number;
2323
type GroupHandle = number;
@@ -444,7 +444,8 @@ export class ExtHostSCM {
444444

445445
constructor(
446446
mainContext: IMainContext,
447-
private _commands: ExtHostCommands
447+
private _commands: ExtHostCommands,
448+
@ILogService private logService: ILogService
448449
) {
449450
this._proxy = mainContext.get(MainContext.MainThreadSCM);
450451

@@ -487,8 +488,9 @@ export class ExtHostSCM {
487488
});
488489
}
489490

490-
@log(LogLevel.Trace, 'ExtHostSCM', (msg, extension, id, label, rootUri) => `${msg}(${extension.id}, ${id}, ${label}, ${rootUri})`)
491491
createSourceControl(extension: IExtensionDescription, id: string, label: string, rootUri: vscode.Uri | undefined): vscode.SourceControl {
492+
this.logService.trace('ExtHostSCM#createSourceControl', extension.id, id, label, rootUri);
493+
492494
const handle = ExtHostSCM._handlePool++;
493495
const sourceControl = new ExtHostSourceControl(this._proxy, this._commands, id, label, rootUri);
494496
this._sourceControls.set(handle, sourceControl);
@@ -501,17 +503,19 @@ export class ExtHostSCM {
501503
}
502504

503505
// Deprecated
504-
@log(LogLevel.Trace, 'ExtHostSCM', (msg, extension) => `${msg}(${extension.id})`)
505506
getLastInputBox(extension: IExtensionDescription): ExtHostSCMInputBox {
507+
this.logService.trace('ExtHostSCM#getLastInputBox', extension.id);
508+
506509
const sourceControls = this._sourceControlsByExtension.get(extension.id);
507510
const sourceControl = sourceControls && sourceControls[sourceControls.length - 1];
508511
const inputBox = sourceControl && sourceControl.inputBox;
509512

510513
return inputBox;
511514
}
512515

513-
@log(LogLevel.Trace, 'ExtHostSCM', (msg, handle, uri) => `${msg}(${handle}, ${uri})`)
514516
$provideOriginalResource(sourceControlHandle: number, uri: URI): TPromise<URI> {
517+
this.logService.trace('ExtHostSCM#$provideOriginalResource', sourceControlHandle, uri);
518+
515519
const sourceControl = this._sourceControls.get(sourceControlHandle);
516520

517521
if (!sourceControl || !sourceControl.quickDiffProvider) {
@@ -524,8 +528,9 @@ export class ExtHostSCM {
524528
});
525529
}
526530

527-
@log(LogLevel.Trace, 'ExtHostSCM', (msg, handle) => `${msg}(${handle})`)
528531
$onInputBoxValueChange(sourceControlHandle: number, value: string): TPromise<void> {
532+
this.logService.trace('ExtHostSCM#$onInputBoxValueChange', sourceControlHandle);
533+
529534
const sourceControl = this._sourceControls.get(sourceControlHandle);
530535

531536
if (!sourceControl) {
@@ -536,8 +541,9 @@ export class ExtHostSCM {
536541
return TPromise.as(null);
537542
}
538543

539-
@log(LogLevel.Trace, 'ExtHostSCM', (msg, h1, h2, h3) => `${msg}(${h1}, ${h2}, ${h3})`)
540544
async $executeResourceCommand(sourceControlHandle: number, groupHandle: number, handle: number): TPromise<void> {
545+
this.logService.trace('ExtHostSCM#$executeResourceCommand', sourceControlHandle, groupHandle, handle);
546+
541547
const sourceControl = this._sourceControls.get(sourceControlHandle);
542548

543549
if (!sourceControl) {

0 commit comments

Comments
 (0)