提交 4e78a42a 编写于 作者: J Joao Moreno

log ext host commands, ext hsot scm

上级 2b5d14e4
......@@ -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;
......
......@@ -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
......@@ -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
......@@ -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);
......
......@@ -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 {
......
......@@ -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: <T>(...args: any[]) => T | Thenable<T>, 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<T>(id: string, ...args: any[]): Thenable<T> {
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<string[]> {
return this._proxy.$getCommands().then(result => {
if (filterUnderscoreCommands) {
......
......@@ -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(() => {
......
......@@ -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<URI> {
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<void> {
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<void> {
const sourceControl = this._sourceControls.get(sourceControlHandle);
......
......@@ -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<Error, IExtensionDescription>();
......
......@@ -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;
});
......
......@@ -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);
......
......@@ -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();
......
......@@ -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));
......
......@@ -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<string>();
testObject.registerTreeDataProvider('testDataProvider', aTreeDataProvider());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册