@codingame/monaco-vscode-extensions-service-override
Version:
VSCode public API plugged on the monaco editor - extensions service-override
80 lines (77 loc) • 3.35 kB
JavaScript
import { __decorate, __param } from 'vscode/external/tslib/tslib.es6.js';
import { extHostNamedCustomer } from '../../services/extensions/common/extHostCustomers.js';
import { isLogLevel, log, parseLogLevel, LogLevelToString } from 'vscode/vscode/vs/platform/log/common/log';
import { ILoggerService, ILogService } from 'vscode/vscode/vs/platform/log/common/log.service';
import { DisposableStore } from 'vscode/vscode/vs/base/common/lifecycle';
import { ExtHostContext, MainContext } from 'vscode/vscode/vs/workbench/api/common/extHost.protocol';
import { URI } from 'vscode/vscode/vs/base/common/uri';
import { CommandsRegistry } from 'vscode/vscode/vs/platform/commands/common/commands';
import { IEnvironmentService } from 'vscode/vscode/vs/platform/environment/common/environment.service';
let MainThreadLoggerService = class MainThreadLoggerService {
constructor(extHostContext, loggerService) {
this.loggerService = loggerService;
this.disposables = ( new DisposableStore());
const proxy = ( extHostContext.getProxy(ExtHostContext.ExtHostLogLevelServiceShape));
this.disposables.add(loggerService.onDidChangeLogLevel(arg => {
if (isLogLevel(arg)) {
proxy.$setLogLevel(arg);
}
else {
proxy.$setLogLevel(arg[1], arg[0]);
}
}));
}
$log(file, messages) {
const logger = this.loggerService.getLogger(URI.revive(file));
if (!logger) {
throw ( new Error('Create the logger before logging'));
}
for (const [level, message] of messages) {
log(logger, level, message);
}
}
async $createLogger(file, options) {
this.loggerService.createLogger(URI.revive(file), options);
}
async $registerLogger(logResource) {
this.loggerService.registerLogger({
...logResource,
resource: URI.revive(logResource.resource)
});
}
async $deregisterLogger(resource) {
this.loggerService.deregisterLogger(URI.revive(resource));
}
async $setVisibility(resource, visible) {
this.loggerService.setVisibility(URI.revive(resource), visible);
}
$flush(file) {
const logger = this.loggerService.getLogger(URI.revive(file));
if (!logger) {
throw ( new Error('Create the logger before flushing'));
}
logger.flush();
}
dispose() {
this.disposables.dispose();
}
};
MainThreadLoggerService = __decorate([
extHostNamedCustomer(MainContext.MainThreadLogger),
( __param(1, ILoggerService))
], MainThreadLoggerService);
CommandsRegistry.registerCommand('_extensionTests.setLogLevel', function (accessor, level) {
const loggerService = accessor.get(ILoggerService);
const environmentService = accessor.get(IEnvironmentService);
if (environmentService.isExtensionDevelopment && !!environmentService.extensionTestsLocationURI) {
const logLevel = parseLogLevel(level);
if (logLevel !== undefined) {
loggerService.setLogLevel(logLevel);
}
}
});
CommandsRegistry.registerCommand('_extensionTests.getLogLevel', function (accessor) {
const logService = accessor.get(ILogService);
return LogLevelToString(logService.getLevel());
});
export { MainThreadLoggerService };