Skip to content

Commit 4e78a42

Browse files
committed
log ext host commands, ext hsot scm
1 parent 2b5d14e commit 4e78a42

14 files changed

Lines changed: 66 additions & 31 deletions

File tree

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +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 { ILogService } from 'vs/platform/log/common/log';
20-
21-
class NoopLogService implements ILogService {
22-
_serviceBrand: any;
23-
trace(message: string, ...args: any[]): void { }
24-
debug(message: string, ...args: any[]): void { }
25-
info(message: string, ...args: any[]): void { }
26-
warn(message: string, ...args: any[]): void { }
27-
error(message: string | Error, ...args: any[]): void { }
28-
critical(message: string | Error, ...args: any[]): void { }
29-
}
19+
import { NoopLogService } from 'vs/platform/log/common/log';
3020

3121
class SimpleExtensionService implements IExtensionService {
3222
_serviceBrand: any;

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ export class LegacyLogMainService implements ILogService {
6969

7070
export function log(level: LogLevel, prefix: string, logFn?: (message: string, ...args: any[]) => string): Function {
7171
return createDecorator((fn, key) => {
72+
// TODO@Joao: load-time log level? return fn;
73+
7274
return function (this: any, ...args: any[]) {
7375
let message = `${prefix} - ${key}`;
7476

@@ -88,4 +90,14 @@ export function log(level: LogLevel, prefix: string, logFn?: (message: string, .
8890
return fn.apply(this, args);
8991
};
9092
});
93+
}
94+
95+
export class NoopLogService implements ILogService {
96+
_serviceBrand: any;
97+
trace(message: string, ...args: any[]): void { }
98+
debug(message: string, ...args: any[]): void { }
99+
info(message: string, ...args: any[]): void { }
100+
warn(message: string, ...args: any[]): void { }
101+
error(message: string | Error, ...args: any[]): void { }
102+
critical(message: string | Error, ...args: any[]): void { }
91103
}

src/vs/platform/log/node/spdlogService.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,26 @@ export class SpdLogService implements ILogService {
2020
}
2121

2222
trace(message: string, ...args: any[]): void {
23-
console.log('TRACE', message, ...args);
23+
// console.log('TRACE', message, ...args);
2424
}
2525

2626
debug(message: string, ...args: any[]): void {
27-
console.log('DEBUG', message, ...args);
27+
// console.log('DEBUG', message, ...args);
2828
}
2929

3030
info(message: string, ...args: any[]): void {
31-
console.log('INFO', message, ...args);
31+
// console.log('INFO', message, ...args);
3232
}
3333

3434
warn(message: string, ...args: any[]): void {
35-
console.warn('WARN', message, ...args);
35+
// console.warn('WARN', message, ...args);
3636
}
3737

3838
error(message: string | Error, ...args: any[]): void {
39-
console.error('ERROR', message, ...args);
39+
// console.error('ERROR', message, ...args);
4040
}
4141

4242
critical(message: string, ...args: any[]): void {
43-
console.error('CRITICAL', message, ...args);
43+
// console.error('CRITICAL', message, ...args);
4444
}
4545
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import { ExtHostFileSystem } from 'vs/workbench/api/node/extHostFileSystem';
5656
import { FileChangeType, FileType } from 'vs/platform/files/common/files';
5757
import { ExtHostDecorations } from 'vs/workbench/api/node/extHostDecorations';
5858
import { toGlobPattern, toLanguageSelector } from 'vs/workbench/api/node/extHostTypeConverters';
59+
import { ILogService } from 'vs/platform/log/common/log';
5960

6061
export interface IExtensionApiFactory {
6162
(extension: IExtensionDescription): typeof vscode;
@@ -79,7 +80,8 @@ export function createApiFactory(
7980
threadService: ExtHostThreadService,
8081
extHostWorkspace: ExtHostWorkspace,
8182
extHostConfiguration: ExtHostConfiguration,
82-
extensionService: ExtHostExtensionService
83+
extensionService: ExtHostExtensionService,
84+
logService: ILogService
8385
): IExtensionApiFactory {
8486

8587
// Addressable instances
@@ -90,7 +92,7 @@ export function createApiFactory(
9092
const extHostDocumentContentProviders = threadService.set(ExtHostContext.ExtHostDocumentContentProviders, new ExtHostDocumentContentProvider(threadService, extHostDocumentsAndEditors));
9193
const extHostDocumentSaveParticipant = threadService.set(ExtHostContext.ExtHostDocumentSaveParticipant, new ExtHostDocumentSaveParticipant(extHostDocuments, threadService.get(MainContext.MainThreadEditors)));
9294
const extHostEditors = threadService.set(ExtHostContext.ExtHostEditors, new ExtHostEditors(threadService, extHostDocumentsAndEditors));
93-
const extHostCommands = threadService.set(ExtHostContext.ExtHostCommands, new ExtHostCommands(threadService, extHostHeapService));
95+
const extHostCommands = threadService.set(ExtHostContext.ExtHostCommands, new ExtHostCommands(threadService, extHostHeapService, logService));
9496
const extHostTreeViews = threadService.set(ExtHostContext.ExtHostTreeViews, new ExtHostTreeViews(threadService.get(MainContext.MainThreadTreeViews), extHostCommands));
9597
threadService.set(ExtHostContext.ExtHostWorkspace, extHostWorkspace);
9698
const extHostDebugService = threadService.set(ExtHostContext.ExtHostDebugService, new ExtHostDebugService(threadService, extHostWorkspace));
@@ -101,7 +103,7 @@ export function createApiFactory(
101103
const extHostFileSystemEvent = threadService.set(ExtHostContext.ExtHostFileSystemEventService, new ExtHostFileSystemEventService());
102104
const extHostQuickOpen = threadService.set(ExtHostContext.ExtHostQuickOpen, new ExtHostQuickOpen(threadService, extHostWorkspace, extHostCommands));
103105
const extHostTerminalService = threadService.set(ExtHostContext.ExtHostTerminalService, new ExtHostTerminalService(threadService));
104-
const extHostSCM = threadService.set(ExtHostContext.ExtHostSCM, new ExtHostSCM(threadService, extHostCommands));
106+
const extHostSCM = threadService.set(ExtHostContext.ExtHostSCM, new ExtHostSCM(threadService, extHostCommands, logService));
105107
const extHostTask = threadService.set(ExtHostContext.ExtHostTask, new ExtHostTask(threadService, extHostWorkspace));
106108
const extHostWindow = threadService.set(ExtHostContext.ExtHostWindow, new ExtHostWindow(threadService));
107109
threadService.set(ExtHostContext.ExtHostExtensionService, extensionService);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import { SerializedError } from 'vs/base/common/errors';
4949
import { IWorkspaceFolderData } from 'vs/platform/workspace/common/workspace';
5050
import { IStat, IFileChange } from 'vs/platform/files/common/files';
5151
import { ConfigurationScope } from 'vs/platform/configuration/common/configurationRegistry';
52+
import { ParsedArgs } from 'vs/platform/environment/common/environment';
5253

5354
export interface IEnvironment {
5455
isExtensionDevelopmentDebug: boolean;
@@ -75,6 +76,8 @@ export interface IInitData {
7576
extensions: IExtensionDescription[];
7677
configuration: IConfigurationInitData;
7778
telemetryInfo: ITelemetryInfo;
79+
args: ParsedArgs;
80+
execPath: string;
7881
}
7982

8083
export interface IConfigurationInitData extends IConfigurationData {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +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 { ILogService, log, LogLevel } from 'vs/platform/log/common/log';
1819

1920
interface CommandHandler {
2021
callback: Function;
@@ -35,7 +36,9 @@ export class ExtHostCommands implements ExtHostCommandsShape {
3536

3637
constructor(
3738
mainContext: IMainContext,
38-
heapService: ExtHostHeapService
39+
heapService: ExtHostHeapService,
40+
// @ts-ignore
41+
@ILogService private logService: ILogService
3942
) {
4043
this._proxy = mainContext.get(MainContext.MainThreadCommands);
4144
this._converter = new CommandsConverter(this, heapService);
@@ -49,6 +52,7 @@ export class ExtHostCommands implements ExtHostCommandsShape {
4952
this._argumentProcessors.push(processor);
5053
}
5154

55+
@log(LogLevel.TRACE, 'ExtHostCommands', (msg, id) => `${msg}(${id})`)
5256
registerCommand(id: string, callback: <T>(...args: any[]) => T | Thenable<T>, thisArg?: any, description?: ICommandHandlerDescription): extHostTypes.Disposable {
5357

5458
if (!id.trim().length) {
@@ -69,6 +73,7 @@ export class ExtHostCommands implements ExtHostCommandsShape {
6973
});
7074
}
7175

76+
@log(LogLevel.TRACE, 'ExtHostCommands', (msg, id) => `${msg}(${id})`)
7277
executeCommand<T>(id: string, ...args: any[]): Thenable<T> {
7378

7479
if (this._commands.has(id)) {
@@ -133,6 +138,7 @@ export class ExtHostCommands implements ExtHostCommandsShape {
133138
}
134139
}
135140

141+
@log(LogLevel.TRACE, 'ExtHostCommands', (msg, filterUnderscoreCommands) => `${msg}(${filterUnderscoreCommands})`)
136142
getCommands(filterUnderscoreCommands: boolean = false): Thenable<string[]> {
137143
return this._proxy.$getCommands().then(result => {
138144
if (filterUnderscoreCommands) {

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: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +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, ILogService } from 'vs/platform/log/common/log';
2021

2122
type ProviderHandle = number;
2223
type GroupHandle = number;
@@ -443,7 +444,9 @@ export class ExtHostSCM {
443444

444445
constructor(
445446
mainContext: IMainContext,
446-
private _commands: ExtHostCommands
447+
private _commands: ExtHostCommands,
448+
// @ts-ignore
449+
@ILogService private logService: ILogService
447450
) {
448451
this._proxy = mainContext.get(MainContext.MainThreadSCM);
449452

@@ -486,6 +489,7 @@ export class ExtHostSCM {
486489
});
487490
}
488491

492+
@log(LogLevel.TRACE, 'ExtHostSCM', (msg, extension, id, label, rootUri) => `${msg}(${extension.id}, ${id}, ${label}, ${rootUri})`)
489493
createSourceControl(extension: IExtensionDescription, id: string, label: string, rootUri: vscode.Uri | undefined): vscode.SourceControl {
490494
const handle = ExtHostSCM._handlePool++;
491495
const sourceControl = new ExtHostSourceControl(this._proxy, this._commands, id, label, rootUri);
@@ -499,6 +503,7 @@ export class ExtHostSCM {
499503
}
500504

501505
// Deprecated
506+
@log(LogLevel.TRACE, 'ExtHostSCM', (msg, extension) => `${msg}(${extension.id})`)
502507
getLastInputBox(extension: IExtensionDescription): ExtHostSCMInputBox {
503508
const sourceControls = this._sourceControlsByExtension.get(extension.id);
504509
const sourceControl = sourceControls && sourceControls[sourceControls.length - 1];
@@ -507,6 +512,7 @@ export class ExtHostSCM {
507512
return inputBox;
508513
}
509514

515+
@log(LogLevel.TRACE, 'ExtHostSCM', (msg, handle, uri) => `${msg}(${handle}, ${uri})`)
510516
$provideOriginalResource(sourceControlHandle: number, uri: URI): TPromise<URI> {
511517
const sourceControl = this._sourceControls.get(sourceControlHandle);
512518

@@ -520,6 +526,7 @@ export class ExtHostSCM {
520526
});
521527
}
522528

529+
@log(LogLevel.TRACE, 'ExtHostSCM', (msg, handle) => `${msg}(${handle})`)
523530
$onInputBoxValueChange(sourceControlHandle: number, value: string): TPromise<void> {
524531
const sourceControl = this._sourceControls.get(sourceControlHandle);
525532

@@ -531,6 +538,7 @@ export class ExtHostSCM {
531538
return TPromise.as(null);
532539
}
533540

541+
@log(LogLevel.TRACE, 'ExtHostSCM', (msg, h1, h2, h3) => `${msg}(${h1}, ${h2}, ${h3})`)
534542
async $executeResourceCommand(sourceControlHandle: number, groupHandle: number, handle: number): TPromise<void> {
535543
const sourceControl = this._sourceControls.get(sourceControlHandle);
536544

src/vs/workbench/node/extensionHostMain.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import { IInitData, IEnvironment, IWorkspaceData, MainContext } from 'vs/workben
2121
import * as errors from 'vs/base/common/errors';
2222
import * as watchdog from 'native-watchdog';
2323
import * as glob from 'vs/base/common/glob';
24+
import { EnvironmentService } from 'vs/platform/environment/node/environmentService';
25+
import { SpdLogService } from 'vs/platform/log/node/spdlogService';
2426

2527
// const nativeExit = process.exit.bind(process);
2628
function patchProcess(allowExit: boolean) {
@@ -83,8 +85,11 @@ export class ExtensionHostMain {
8385
// services
8486
const threadService = new ExtHostThreadService(rpcProtocol);
8587
const extHostWorkspace = new ExtHostWorkspace(threadService, initData.workspace);
88+
const environmentService = new EnvironmentService(initData.args, initData.execPath);
89+
const logService = new SpdLogService('exthost', environmentService);
90+
8691
this._extHostConfiguration = new ExtHostConfiguration(threadService.get(MainContext.MainThreadConfiguration), extHostWorkspace, initData.configuration);
87-
this._extensionService = new ExtHostExtensionService(initData, threadService, extHostWorkspace, this._extHostConfiguration);
92+
this._extensionService = new ExtHostExtensionService(initData, threadService, extHostWorkspace, this._extHostConfiguration, logService);
8893

8994
// error forwarding and stack trace scanning
9095
const extensionErrors = new WeakMap<Error, IExtensionDescription>();

src/vs/workbench/services/extensions/electron-browser/extensionHost.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,9 @@ export class ExtensionHostProcessWorker {
363363
extensions: extensionDescriptions,
364364
// Send configurations scopes only in development mode.
365365
configuration: !this._environmentService.isBuilt || this._environmentService.isExtensionDevelopment ? { ...configurationData, configurationScopes: getScopes(this._configurationService.keys().default) } : configurationData,
366-
telemetryInfo
366+
telemetryInfo,
367+
args: this._environmentService.args,
368+
execPath: this._environmentService.execPath
367369
};
368370
return r;
369371
});

0 commit comments

Comments
 (0)