提交 6c45ea53 编写于 作者: A Alex Dima

use a simple worker for output link computation

上级 f708ded7
...@@ -29,6 +29,7 @@ exports.collectModules = function(excludes) { ...@@ -29,6 +29,7 @@ exports.collectModules = function(excludes) {
createModuleDescription('vs/workbench/parts/output/common/outputMode', languageMainExcludes), createModuleDescription('vs/workbench/parts/output/common/outputMode', languageMainExcludes),
createModuleDescription('vs/workbench/parts/output/common/outputWorker', languageWorkerExcludes), createModuleDescription('vs/workbench/parts/output/common/outputWorker', languageWorkerExcludes),
createModuleDescription('vs/workbench/parts/output/common/outputLinkComputer', ['vs/base/common/worker/simpleWorker', 'vs/editor/common/services/editorSimpleWorker']),
createModuleDescription('vs/workbench/parts/output/browser/outputPanel', excludes), createModuleDescription('vs/workbench/parts/output/browser/outputPanel', excludes),
createModuleDescription('vs/workbench/parts/debug/browser/debugViewlet', excludes), createModuleDescription('vs/workbench/parts/debug/browser/debugViewlet', excludes),
......
...@@ -25,15 +25,22 @@ import {ContextKeyExpr} from 'vs/platform/contextkey/common/contextkey'; ...@@ -25,15 +25,22 @@ import {ContextKeyExpr} from 'vs/platform/contextkey/common/contextkey';
registerSingleton(IOutputService, OutputService); registerSingleton(IOutputService, OutputService);
// Register Output Mode // Register Output Mode
ModesRegistry.registerCompatMode({ ModesRegistry.registerLanguage({
id: OUTPUT_MODE_ID, id: OUTPUT_MODE_ID,
extensions: [], extensions: [],
aliases: [null], aliases: [null],
mimetypes: [OUTPUT_MIME], mimetypes: [OUTPUT_MIME]
moduleId: 'vs/workbench/parts/output/common/outputMode',
ctorName: 'OutputMode'
}); });
// ModesRegistry.registerCompatMode({
// id: OUTPUT_MODE_ID,
// extensions: [],
// aliases: [null],
// mimetypes: [OUTPUT_MIME],
// moduleId: 'vs/workbench/parts/output/common/outputMode',
// ctorName: 'OutputMode'
// });
// Register Output Panel // Register Output Panel
(<panel.PanelRegistry>platform.Registry.as(panel.Extensions.Panels)).registerPanel(new panel.PanelDescriptor( (<panel.PanelRegistry>platform.Registry.as(panel.Extensions.Panels)).registerPanel(new panel.PanelDescriptor(
'vs/workbench/parts/output/browser/outputPanel', 'vs/workbench/parts/output/browser/outputPanel',
......
...@@ -17,6 +17,9 @@ import {IOutputEvent, IOutputChannel, IOutputService, Extensions, OUTPUT_PANEL_I ...@@ -17,6 +17,9 @@ import {IOutputEvent, IOutputChannel, IOutputService, Extensions, OUTPUT_PANEL_I
import {OutputEditorInput} from 'vs/workbench/parts/output/browser/outputEditorInput'; import {OutputEditorInput} from 'vs/workbench/parts/output/browser/outputEditorInput';
import {OutputPanel} from 'vs/workbench/parts/output/browser/outputPanel'; import {OutputPanel} from 'vs/workbench/parts/output/browser/outputPanel';
import {IPanelService} from 'vs/workbench/services/panel/common/panelService'; import {IPanelService} from 'vs/workbench/services/panel/common/panelService';
import {IModelService} from 'vs/editor/common/services/modelService';
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {OutputLinkProvider} from 'vs/workbench/parts/output/common/outputLinkProvider';
const OUTPUT_ACTIVE_CHANNEL_KEY = 'output.activechannel'; const OUTPUT_ACTIVE_CHANNEL_KEY = 'output.activechannel';
...@@ -31,12 +34,16 @@ export class OutputService implements IOutputService { ...@@ -31,12 +34,16 @@ export class OutputService implements IOutputService {
private _onOutputChannel: Emitter<string>; private _onOutputChannel: Emitter<string>;
private _onActiveOutputChannel: Emitter<string>; private _onActiveOutputChannel: Emitter<string>;
private _outputLinkDetector: OutputLinkProvider;
constructor( constructor(
@IStorageService private storageService: IStorageService, @IStorageService private storageService: IStorageService,
@IInstantiationService private instantiationService: IInstantiationService, @IInstantiationService private instantiationService: IInstantiationService,
@IEventService private eventService: IEventService, @IEventService private eventService: IEventService,
@ILifecycleService private lifecycleService: ILifecycleService, @ILifecycleService private lifecycleService: ILifecycleService,
@IPanelService private panelService: IPanelService @IPanelService private panelService: IPanelService,
@IWorkspaceContextService contextService:IWorkspaceContextService,
@IModelService modelService: IModelService
) { ) {
this._onOutput = new Emitter<IOutputEvent>(); this._onOutput = new Emitter<IOutputEvent>();
this._onOutputChannel = new Emitter<string>(); this._onOutputChannel = new Emitter<string>();
...@@ -46,6 +53,8 @@ export class OutputService implements IOutputService { ...@@ -46,6 +53,8 @@ export class OutputService implements IOutputService {
const channels = Registry.as<IOutputChannelRegistry>(Extensions.OutputChannels).getChannels(); const channels = Registry.as<IOutputChannelRegistry>(Extensions.OutputChannels).getChannels();
this.activeChannelId = this.storageService.get(OUTPUT_ACTIVE_CHANNEL_KEY, StorageScope.WORKSPACE, channels && channels.length > 0 ? channels[0].id : null); this.activeChannelId = this.storageService.get(OUTPUT_ACTIVE_CHANNEL_KEY, StorageScope.WORKSPACE, channels && channels.length > 0 ? channels[0].id : null);
this._outputLinkDetector = new OutputLinkProvider(contextService, modelService);
} }
public get onOutput(): Event<IOutputEvent> { public get onOutput(): Event<IOutputEvent> {
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import {IMirrorModel, IWorkerContext} from 'vs/editor/common/services/editorSimpleWorker';
import {OutputWorker, IResourceCreator} from 'vs/workbench/parts/output/common/outputWorker';
import {ILink} from 'vs/editor/common/modes';
import {TPromise} from 'vs/base/common/winjs.base';
import URI from 'vs/base/common/uri';
import paths = require('vs/base/common/paths');
export interface ICreateData {
workspaceResourceUri: string;
}
export class OutputLinkComputer {
private _ctx:IWorkerContext;
private _patterns: RegExp[];
private _workspaceResource: URI;
constructor(ctx:IWorkerContext, createData:ICreateData) {
this._ctx = ctx;
this._workspaceResource = URI.parse(createData.workspaceResourceUri);
this._patterns = OutputWorker.createPatterns(this._workspaceResource);
}
private _getModel(uri:string): IMirrorModel {
let models = this._ctx.getMirrorModels();
for (let i = 0; i < models.length; i++) {
let model = models[i];
if (model.uri.toString() === uri) {
return model;
}
}
return null;
}
public computeLinks(uri:string): TPromise<ILink[]> {
let model = this._getModel(uri);
if (!model) {
return;
}
let links: ILink[] = [];
let resourceCreator: IResourceCreator = {
toResource: (workspaceRelativePath: string): URI => {
if (typeof workspaceRelativePath === 'string') {
return URI.file(paths.join(this._workspaceResource.fsPath, workspaceRelativePath));
}
return null;
}
};
let lines = model.getValue().split(/\r\n|\r|\n/);
for (let i = 0, len = lines.length; i < len; i++) {
links.push(...OutputWorker.detectLinks(lines[i], i + 1, this._patterns, resourceCreator));
}
return TPromise.as(links);
}
}
export function create(ctx:IWorkerContext, createData:ICreateData): OutputLinkComputer {
return new OutputLinkComputer(ctx, createData);
}
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import {TPromise} from 'vs/base/common/winjs.base';
import URI from 'vs/base/common/uri';
import {RunOnceScheduler, wireCancellationToken} from 'vs/base/common/async';
import {IModelService} from 'vs/editor/common/services/modelService';
import {LinkProviderRegistry, ILink} from 'vs/editor/common/modes';
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {OUTPUT_MODE_ID} from 'vs/workbench/parts/output/common/output';
import {MonacoWebWorker, createWebWorker} from 'vs/editor/common/services/webWorker';
import {ICreateData, OutputLinkComputer} from 'vs/workbench/parts/output/common/outputLinkComputer';
export class OutputLinkProvider {
private static DISPOSE_WORKER_TIME = 3 * 60 * 1000; // dispose worker after 3 minutes of inactivity
private _modelService: IModelService;
private _workspaceResource: URI;
private _worker: MonacoWebWorker<OutputLinkComputer>;
private _disposeWorker: RunOnceScheduler;
constructor(
contextService:IWorkspaceContextService,
modelService: IModelService
) {
let workspace = contextService.getWorkspace();
// Does not do anything unless there is a workspace...
if (workspace) {
this._modelService = modelService;
this._workspaceResource = workspace.resource;
LinkProviderRegistry.register(OUTPUT_MODE_ID, {
provideLinks: (model, token): Thenable<ILink[]> => {
return wireCancellationToken(token, this._provideLinks(model.uri));
}
});
this._worker = null;
this._disposeWorker = new RunOnceScheduler(() => {
if (this._worker) {
this._worker.dispose();
this._worker = null;
}
}, OutputLinkProvider.DISPOSE_WORKER_TIME);
}
}
private _getOrCreateWorker(): MonacoWebWorker<OutputLinkComputer> {
this._disposeWorker.schedule();
if (!this._worker) {
let createData:ICreateData = {
workspaceResourceUri: this._workspaceResource.toString()
};
this._worker = createWebWorker<OutputLinkComputer>(this._modelService, {
moduleId: 'vs/workbench/parts/output/common/outputLinkComputer',
createData: createData,
label: 'outputLinkComputer'
});
}
return this._worker;
}
private _provideLinks(modelUri:URI): TPromise<ILink[]> {
return this._getOrCreateWorker().withSyncedResources([modelUri]).then((linkComputer) => {
return linkComputer.computeLinks(modelUri.toString());
});
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册