From 4e78a42abf3cdc73961b955b7653df29843cb176 Mon Sep 17 00:00:00 2001 From: Joao Moreno Date: Wed, 29 Nov 2017 14:22:38 +0100 Subject: [PATCH] log ext host commands, ext hsot scm --- src/vs/platform/commands/test/commandService.test.ts | 12 +----------- src/vs/platform/log/common/log.ts | 12 ++++++++++++ src/vs/platform/log/node/spdlogService.ts | 12 ++++++------ src/vs/workbench/api/node/extHost.api.impl.ts | 8 +++++--- src/vs/workbench/api/node/extHost.protocol.ts | 3 +++ src/vs/workbench/api/node/extHostCommands.ts | 8 +++++++- src/vs/workbench/api/node/extHostExtensionService.ts | 6 ++++-- src/vs/workbench/api/node/extHostSCM.ts | 10 +++++++++- src/vs/workbench/node/extensionHostMain.ts | 7 ++++++- .../extensions/electron-browser/extensionHost.ts | 4 +++- .../electron-browser/api/extHostApiCommands.test.ts | 4 +++- .../electron-browser/api/extHostCommands.test.ts | 5 +++-- .../api/extHostLanguageFeatures.test.ts | 3 ++- .../electron-browser/api/extHostTreeViews.test.ts | 3 ++- 14 files changed, 66 insertions(+), 31 deletions(-) diff --git a/src/vs/platform/commands/test/commandService.test.ts b/src/vs/platform/commands/test/commandService.test.ts index f5f927255d5..a7c90002c62 100644 --- a/src/vs/platform/commands/test/commandService.test.ts +++ b/src/vs/platform/commands/test/commandService.test.ts @@ -16,17 +16,7 @@ import { ContextKeyService } from 'vs/platform/contextkey/browser/contextKeyServ import { SimpleConfigurationService } from 'vs/editor/standalone/browser/simpleServices'; import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; import Event, { Emitter } from 'vs/base/common/event'; -import { ILogService } from 'vs/platform/log/common/log'; - -class NoopLogService implements ILogService { - _serviceBrand: any; - trace(message: string, ...args: any[]): void { } - debug(message: string, ...args: any[]): void { } - info(message: string, ...args: any[]): void { } - warn(message: string, ...args: any[]): void { } - error(message: string | Error, ...args: any[]): void { } - critical(message: string | Error, ...args: any[]): void { } -} +import { NoopLogService } from 'vs/platform/log/common/log'; class SimpleExtensionService implements IExtensionService { _serviceBrand: any; diff --git a/src/vs/platform/log/common/log.ts b/src/vs/platform/log/common/log.ts index 0312a8e7c54..7b12d9563e7 100644 --- a/src/vs/platform/log/common/log.ts +++ b/src/vs/platform/log/common/log.ts @@ -69,6 +69,8 @@ export class LegacyLogMainService implements ILogService { export function log(level: LogLevel, prefix: string, logFn?: (message: string, ...args: any[]) => string): Function { return createDecorator((fn, key) => { + // TODO@Joao: load-time log level? return fn; + return function (this: any, ...args: any[]) { let message = `${prefix} - ${key}`; @@ -88,4 +90,14 @@ export function log(level: LogLevel, prefix: string, logFn?: (message: string, . return fn.apply(this, args); }; }); +} + +export class NoopLogService implements ILogService { + _serviceBrand: any; + trace(message: string, ...args: any[]): void { } + debug(message: string, ...args: any[]): void { } + info(message: string, ...args: any[]): void { } + warn(message: string, ...args: any[]): void { } + error(message: string | Error, ...args: any[]): void { } + critical(message: string | Error, ...args: any[]): void { } } \ No newline at end of file diff --git a/src/vs/platform/log/node/spdlogService.ts b/src/vs/platform/log/node/spdlogService.ts index 5d4e1a789fa..5fdb306f82f 100644 --- a/src/vs/platform/log/node/spdlogService.ts +++ b/src/vs/platform/log/node/spdlogService.ts @@ -20,26 +20,26 @@ export class SpdLogService implements ILogService { } trace(message: string, ...args: any[]): void { - console.log('TRACE', message, ...args); + // console.log('TRACE', message, ...args); } debug(message: string, ...args: any[]): void { - console.log('DEBUG', message, ...args); + // console.log('DEBUG', message, ...args); } info(message: string, ...args: any[]): void { - console.log('INFO', message, ...args); + // console.log('INFO', message, ...args); } warn(message: string, ...args: any[]): void { - console.warn('WARN', message, ...args); + // console.warn('WARN', message, ...args); } error(message: string | Error, ...args: any[]): void { - console.error('ERROR', message, ...args); + // console.error('ERROR', message, ...args); } critical(message: string, ...args: any[]): void { - console.error('CRITICAL', message, ...args); + // console.error('CRITICAL', message, ...args); } } \ No newline at end of file diff --git a/src/vs/workbench/api/node/extHost.api.impl.ts b/src/vs/workbench/api/node/extHost.api.impl.ts index c1cc7e76ba7..59b939dcda0 100644 --- a/src/vs/workbench/api/node/extHost.api.impl.ts +++ b/src/vs/workbench/api/node/extHost.api.impl.ts @@ -56,6 +56,7 @@ import { ExtHostFileSystem } from 'vs/workbench/api/node/extHostFileSystem'; import { FileChangeType, FileType } from 'vs/platform/files/common/files'; import { ExtHostDecorations } from 'vs/workbench/api/node/extHostDecorations'; import { toGlobPattern, toLanguageSelector } from 'vs/workbench/api/node/extHostTypeConverters'; +import { ILogService } from 'vs/platform/log/common/log'; export interface IExtensionApiFactory { (extension: IExtensionDescription): typeof vscode; @@ -79,7 +80,8 @@ export function createApiFactory( threadService: ExtHostThreadService, extHostWorkspace: ExtHostWorkspace, extHostConfiguration: ExtHostConfiguration, - extensionService: ExtHostExtensionService + extensionService: ExtHostExtensionService, + logService: ILogService ): IExtensionApiFactory { // Addressable instances @@ -90,7 +92,7 @@ export function createApiFactory( const extHostDocumentContentProviders = threadService.set(ExtHostContext.ExtHostDocumentContentProviders, new ExtHostDocumentContentProvider(threadService, extHostDocumentsAndEditors)); const extHostDocumentSaveParticipant = threadService.set(ExtHostContext.ExtHostDocumentSaveParticipant, new ExtHostDocumentSaveParticipant(extHostDocuments, threadService.get(MainContext.MainThreadEditors))); const extHostEditors = threadService.set(ExtHostContext.ExtHostEditors, new ExtHostEditors(threadService, extHostDocumentsAndEditors)); - const extHostCommands = threadService.set(ExtHostContext.ExtHostCommands, new ExtHostCommands(threadService, extHostHeapService)); + const extHostCommands = threadService.set(ExtHostContext.ExtHostCommands, new ExtHostCommands(threadService, extHostHeapService, logService)); const extHostTreeViews = threadService.set(ExtHostContext.ExtHostTreeViews, new ExtHostTreeViews(threadService.get(MainContext.MainThreadTreeViews), extHostCommands)); threadService.set(ExtHostContext.ExtHostWorkspace, extHostWorkspace); const extHostDebugService = threadService.set(ExtHostContext.ExtHostDebugService, new ExtHostDebugService(threadService, extHostWorkspace)); @@ -101,7 +103,7 @@ export function createApiFactory( const extHostFileSystemEvent = threadService.set(ExtHostContext.ExtHostFileSystemEventService, new ExtHostFileSystemEventService()); const extHostQuickOpen = threadService.set(ExtHostContext.ExtHostQuickOpen, new ExtHostQuickOpen(threadService, extHostWorkspace, extHostCommands)); const extHostTerminalService = threadService.set(ExtHostContext.ExtHostTerminalService, new ExtHostTerminalService(threadService)); - const extHostSCM = threadService.set(ExtHostContext.ExtHostSCM, new ExtHostSCM(threadService, extHostCommands)); + const extHostSCM = threadService.set(ExtHostContext.ExtHostSCM, new ExtHostSCM(threadService, extHostCommands, logService)); const extHostTask = threadService.set(ExtHostContext.ExtHostTask, new ExtHostTask(threadService, extHostWorkspace)); const extHostWindow = threadService.set(ExtHostContext.ExtHostWindow, new ExtHostWindow(threadService)); threadService.set(ExtHostContext.ExtHostExtensionService, extensionService); diff --git a/src/vs/workbench/api/node/extHost.protocol.ts b/src/vs/workbench/api/node/extHost.protocol.ts index 1eaa93f29ee..358c436132d 100644 --- a/src/vs/workbench/api/node/extHost.protocol.ts +++ b/src/vs/workbench/api/node/extHost.protocol.ts @@ -49,6 +49,7 @@ import { SerializedError } from 'vs/base/common/errors'; import { IWorkspaceFolderData } from 'vs/platform/workspace/common/workspace'; import { IStat, IFileChange } from 'vs/platform/files/common/files'; import { ConfigurationScope } from 'vs/platform/configuration/common/configurationRegistry'; +import { ParsedArgs } from 'vs/platform/environment/common/environment'; export interface IEnvironment { isExtensionDevelopmentDebug: boolean; @@ -75,6 +76,8 @@ export interface IInitData { extensions: IExtensionDescription[]; configuration: IConfigurationInitData; telemetryInfo: ITelemetryInfo; + args: ParsedArgs; + execPath: string; } export interface IConfigurationInitData extends IConfigurationData { diff --git a/src/vs/workbench/api/node/extHostCommands.ts b/src/vs/workbench/api/node/extHostCommands.ts index 774d71f8e26..abeaf711612 100644 --- a/src/vs/workbench/api/node/extHostCommands.ts +++ b/src/vs/workbench/api/node/extHostCommands.ts @@ -15,6 +15,7 @@ import { ExtHostHeapService } from 'vs/workbench/api/node/extHostHeapService'; import { isFalsyOrEmpty } from 'vs/base/common/arrays'; import * as modes from 'vs/editor/common/modes'; import * as vscode from 'vscode'; +import { ILogService, log, LogLevel } from 'vs/platform/log/common/log'; interface CommandHandler { callback: Function; @@ -35,7 +36,9 @@ export class ExtHostCommands implements ExtHostCommandsShape { constructor( mainContext: IMainContext, - heapService: ExtHostHeapService + heapService: ExtHostHeapService, + // @ts-ignore + @ILogService private logService: ILogService ) { this._proxy = mainContext.get(MainContext.MainThreadCommands); this._converter = new CommandsConverter(this, heapService); @@ -49,6 +52,7 @@ export class ExtHostCommands implements ExtHostCommandsShape { this._argumentProcessors.push(processor); } + @log(LogLevel.TRACE, 'ExtHostCommands', (msg, id) => `${msg}(${id})`) registerCommand(id: string, callback: (...args: any[]) => T | Thenable, thisArg?: any, description?: ICommandHandlerDescription): extHostTypes.Disposable { if (!id.trim().length) { @@ -69,6 +73,7 @@ export class ExtHostCommands implements ExtHostCommandsShape { }); } + @log(LogLevel.TRACE, 'ExtHostCommands', (msg, id) => `${msg}(${id})`) executeCommand(id: string, ...args: any[]): Thenable { if (this._commands.has(id)) { @@ -133,6 +138,7 @@ export class ExtHostCommands implements ExtHostCommandsShape { } } + @log(LogLevel.TRACE, 'ExtHostCommands', (msg, filterUnderscoreCommands) => `${msg}(${filterUnderscoreCommands})`) getCommands(filterUnderscoreCommands: boolean = false): Thenable { return this._proxy.$getCommands().then(result => { if (filterUnderscoreCommands) { diff --git a/src/vs/workbench/api/node/extHostExtensionService.ts b/src/vs/workbench/api/node/extHostExtensionService.ts index 7679350dda8..902fa342f48 100644 --- a/src/vs/workbench/api/node/extHostExtensionService.ts +++ b/src/vs/workbench/api/node/extHostExtensionService.ts @@ -21,6 +21,7 @@ import { ExtHostWorkspace } from 'vs/workbench/api/node/extHostWorkspace'; import { realpath } from 'fs'; import { TernarySearchTree } from 'vs/base/common/map'; import { Barrier } from 'vs/base/common/async'; +import { ILogService } from 'vs/platform/log/common/log'; class ExtensionMemento implements IExtensionMemento { @@ -125,7 +126,8 @@ export class ExtHostExtensionService implements ExtHostExtensionServiceShape { constructor(initData: IInitData, threadService: ExtHostThreadService, extHostWorkspace: ExtHostWorkspace, - extHostConfiguration: ExtHostConfiguration + extHostConfiguration: ExtHostConfiguration, + logService: ILogService ) { this._barrier = new Barrier(); this._registry = new ExtensionDescriptionRegistry(initData.extensions); @@ -137,7 +139,7 @@ export class ExtHostExtensionService implements ExtHostExtensionServiceShape { this._activator = null; // initialize API first (i.e. do not release barrier until the API is initialized) - const apiFactory = createApiFactory(initData, threadService, extHostWorkspace, extHostConfiguration, this); + const apiFactory = createApiFactory(initData, threadService, extHostWorkspace, extHostConfiguration, this, logService); initializeExtensionApi(this, apiFactory).then(() => { diff --git a/src/vs/workbench/api/node/extHostSCM.ts b/src/vs/workbench/api/node/extHostSCM.ts index 9c3637a8c4c..5159a2e37df 100644 --- a/src/vs/workbench/api/node/extHostSCM.ts +++ b/src/vs/workbench/api/node/extHostSCM.ts @@ -17,6 +17,7 @@ import { sortedDiff } from 'vs/base/common/arrays'; import { comparePaths } from 'vs/base/common/comparers'; import * as vscode from 'vscode'; import { ISplice } from 'vs/base/common/sequence'; +import { log, LogLevel, ILogService } from 'vs/platform/log/common/log'; type ProviderHandle = number; type GroupHandle = number; @@ -443,7 +444,9 @@ export class ExtHostSCM { constructor( mainContext: IMainContext, - private _commands: ExtHostCommands + private _commands: ExtHostCommands, + // @ts-ignore + @ILogService private logService: ILogService ) { this._proxy = mainContext.get(MainContext.MainThreadSCM); @@ -486,6 +489,7 @@ export class ExtHostSCM { }); } + @log(LogLevel.TRACE, 'ExtHostSCM', (msg, extension, id, label, rootUri) => `${msg}(${extension.id}, ${id}, ${label}, ${rootUri})`) createSourceControl(extension: IExtensionDescription, id: string, label: string, rootUri: vscode.Uri | undefined): vscode.SourceControl { const handle = ExtHostSCM._handlePool++; const sourceControl = new ExtHostSourceControl(this._proxy, this._commands, id, label, rootUri); @@ -499,6 +503,7 @@ export class ExtHostSCM { } // Deprecated + @log(LogLevel.TRACE, 'ExtHostSCM', (msg, extension) => `${msg}(${extension.id})`) getLastInputBox(extension: IExtensionDescription): ExtHostSCMInputBox { const sourceControls = this._sourceControlsByExtension.get(extension.id); const sourceControl = sourceControls && sourceControls[sourceControls.length - 1]; @@ -507,6 +512,7 @@ export class ExtHostSCM { return inputBox; } + @log(LogLevel.TRACE, 'ExtHostSCM', (msg, handle, uri) => `${msg}(${handle}, ${uri})`) $provideOriginalResource(sourceControlHandle: number, uri: URI): TPromise { const sourceControl = this._sourceControls.get(sourceControlHandle); @@ -520,6 +526,7 @@ export class ExtHostSCM { }); } + @log(LogLevel.TRACE, 'ExtHostSCM', (msg, handle) => `${msg}(${handle})`) $onInputBoxValueChange(sourceControlHandle: number, value: string): TPromise { const sourceControl = this._sourceControls.get(sourceControlHandle); @@ -531,6 +538,7 @@ export class ExtHostSCM { return TPromise.as(null); } + @log(LogLevel.TRACE, 'ExtHostSCM', (msg, h1, h2, h3) => `${msg}(${h1}, ${h2}, ${h3})`) async $executeResourceCommand(sourceControlHandle: number, groupHandle: number, handle: number): TPromise { const sourceControl = this._sourceControls.get(sourceControlHandle); diff --git a/src/vs/workbench/node/extensionHostMain.ts b/src/vs/workbench/node/extensionHostMain.ts index d1ecab4b631..2b9d1d04059 100644 --- a/src/vs/workbench/node/extensionHostMain.ts +++ b/src/vs/workbench/node/extensionHostMain.ts @@ -21,6 +21,8 @@ import { IInitData, IEnvironment, IWorkspaceData, MainContext } from 'vs/workben import * as errors from 'vs/base/common/errors'; import * as watchdog from 'native-watchdog'; import * as glob from 'vs/base/common/glob'; +import { EnvironmentService } from 'vs/platform/environment/node/environmentService'; +import { SpdLogService } from 'vs/platform/log/node/spdlogService'; // const nativeExit = process.exit.bind(process); function patchProcess(allowExit: boolean) { @@ -83,8 +85,11 @@ export class ExtensionHostMain { // services const threadService = new ExtHostThreadService(rpcProtocol); const extHostWorkspace = new ExtHostWorkspace(threadService, initData.workspace); + const environmentService = new EnvironmentService(initData.args, initData.execPath); + const logService = new SpdLogService('exthost', environmentService); + this._extHostConfiguration = new ExtHostConfiguration(threadService.get(MainContext.MainThreadConfiguration), extHostWorkspace, initData.configuration); - this._extensionService = new ExtHostExtensionService(initData, threadService, extHostWorkspace, this._extHostConfiguration); + this._extensionService = new ExtHostExtensionService(initData, threadService, extHostWorkspace, this._extHostConfiguration, logService); // error forwarding and stack trace scanning const extensionErrors = new WeakMap(); diff --git a/src/vs/workbench/services/extensions/electron-browser/extensionHost.ts b/src/vs/workbench/services/extensions/electron-browser/extensionHost.ts index 5ba3c86b6e2..7c77059f29e 100644 --- a/src/vs/workbench/services/extensions/electron-browser/extensionHost.ts +++ b/src/vs/workbench/services/extensions/electron-browser/extensionHost.ts @@ -363,7 +363,9 @@ export class ExtensionHostProcessWorker { extensions: extensionDescriptions, // Send configurations scopes only in development mode. configuration: !this._environmentService.isBuilt || this._environmentService.isExtensionDevelopment ? { ...configurationData, configurationScopes: getScopes(this._configurationService.keys().default) } : configurationData, - telemetryInfo + telemetryInfo, + args: this._environmentService.args, + execPath: this._environmentService.execPath }; return r; }); diff --git a/src/vs/workbench/test/electron-browser/api/extHostApiCommands.test.ts b/src/vs/workbench/test/electron-browser/api/extHostApiCommands.test.ts index e8c7a63c6fb..3c1d07155f2 100644 --- a/src/vs/workbench/test/electron-browser/api/extHostApiCommands.test.ts +++ b/src/vs/workbench/test/electron-browser/api/extHostApiCommands.test.ts @@ -32,6 +32,7 @@ import { ExtHostDiagnostics } from 'vs/workbench/api/node/extHostDiagnostics'; import * as vscode from 'vscode'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import 'vs/workbench/parts/search/electron-browser/search.contribution'; +import { NoopLogService } from 'vs/platform/log/common/log'; const defaultSelector = { scheme: 'far' }; const model: EditorCommon.IModel = EditorModel.createFromString( @@ -112,8 +113,9 @@ suite('ExtHostLanguageFeatureCommands', function () { threadService.set(ExtHostContext.ExtHostDocuments, extHostDocuments); const heapService = new ExtHostHeapService(); + const logService = new NoopLogService(); - commands = new ExtHostCommands(threadService, heapService); + commands = new ExtHostCommands(threadService, heapService, logService); threadService.set(ExtHostContext.ExtHostCommands, commands); threadService.setTestInstance(MainContext.MainThreadCommands, inst.createInstance(MainThreadCommands, threadService)); ExtHostApiCommands.register(commands); diff --git a/src/vs/workbench/test/electron-browser/api/extHostCommands.test.ts b/src/vs/workbench/test/electron-browser/api/extHostCommands.test.ts index 69759480fc2..9ea21cf75fa 100644 --- a/src/vs/workbench/test/electron-browser/api/extHostCommands.test.ts +++ b/src/vs/workbench/test/electron-browser/api/extHostCommands.test.ts @@ -12,6 +12,7 @@ import { TPromise } from 'vs/base/common/winjs.base'; import { CommandsRegistry } from 'vs/platform/commands/common/commands'; import { OneGetThreadService } from './testThreadService'; import { mock } from 'vs/workbench/test/electron-browser/api/mock'; +import { NoopLogService } from 'vs/platform/log/common/log'; suite('ExtHostCommands', function () { @@ -29,7 +30,7 @@ suite('ExtHostCommands', function () { } }; - const commands = new ExtHostCommands(OneGetThreadService(shape), undefined); + const commands = new ExtHostCommands(OneGetThreadService(shape), undefined, new NoopLogService()); commands.registerCommand('foo', (): any => { }).dispose(); assert.equal(lastUnregister, 'foo'); assert.equal(CommandsRegistry.getCommand('foo'), undefined); @@ -50,7 +51,7 @@ suite('ExtHostCommands', function () { } }; - const commands = new ExtHostCommands(OneGetThreadService(shape), undefined); + const commands = new ExtHostCommands(OneGetThreadService(shape), undefined, new NoopLogService()); const reg = commands.registerCommand('foo', (): any => { }); reg.dispose(); reg.dispose(); diff --git a/src/vs/workbench/test/electron-browser/api/extHostLanguageFeatures.test.ts b/src/vs/workbench/test/electron-browser/api/extHostLanguageFeatures.test.ts index d6f2f03381b..e1fb7ffbb5d 100644 --- a/src/vs/workbench/test/electron-browser/api/extHostLanguageFeatures.test.ts +++ b/src/vs/workbench/test/electron-browser/api/extHostLanguageFeatures.test.ts @@ -44,6 +44,7 @@ import { ExtHostDiagnostics } from 'vs/workbench/api/node/extHostDiagnostics'; import { ExtHostHeapService } from 'vs/workbench/api/node/extHostHeapService'; import * as vscode from 'vscode'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; +import { NoopLogService } from 'vs/platform/log/common/log'; const defaultSelector = { scheme: 'far' }; const model: EditorCommon.IModel = EditorModel.createFromString( @@ -102,7 +103,7 @@ suite('ExtHostLanguageFeatures', function () { const heapService = new ExtHostHeapService(); - const commands = new ExtHostCommands(threadService, heapService); + const commands = new ExtHostCommands(threadService, heapService, new NoopLogService()); threadService.set(ExtHostContext.ExtHostCommands, commands); threadService.setTestInstance(MainContext.MainThreadCommands, inst.createInstance(MainThreadCommands, threadService)); diff --git a/src/vs/workbench/test/electron-browser/api/extHostTreeViews.test.ts b/src/vs/workbench/test/electron-browser/api/extHostTreeViews.test.ts index 1eaf46831e4..85c50190733 100644 --- a/src/vs/workbench/test/electron-browser/api/extHostTreeViews.test.ts +++ b/src/vs/workbench/test/electron-browser/api/extHostTreeViews.test.ts @@ -17,6 +17,7 @@ import { TestInstantiationService } from 'vs/platform/instantiation/test/common/ import { MainThreadCommands } from 'vs/workbench/api/electron-browser/mainThreadCommands'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { mock } from 'vs/workbench/test/electron-browser/api/mock'; +import { NoopLogService } from 'vs/platform/log/common/log'; suite('ExtHostConfiguration', function () { @@ -48,7 +49,7 @@ suite('ExtHostConfiguration', function () { threadService.setTestInstance(MainContext.MainThreadCommands, inst.createInstance(MainThreadCommands, threadService)); target = new RecordingShape(); - testObject = new ExtHostTreeViews(target, new ExtHostCommands(threadService, new ExtHostHeapService())); + testObject = new ExtHostTreeViews(target, new ExtHostCommands(threadService, new ExtHostHeapService(), new NoopLogService())); onDidChangeTreeData = new Emitter(); testObject.registerTreeDataProvider('testDataProvider', aTreeDataProvider()); -- GitLab