提交 e170425f 编写于 作者: A Alex Dima

Fixes #8167: Do not use IWorkspaceContextService in compat web worker anymore

上级 5d5b3b44
...@@ -13,6 +13,7 @@ import * as modes from 'vs/editor/common/modes'; ...@@ -13,6 +13,7 @@ import * as modes from 'vs/editor/common/modes';
import {CompatMode, ModeWorkerManager} from 'vs/editor/common/modes/abstractMode'; import {CompatMode, ModeWorkerManager} from 'vs/editor/common/modes/abstractMode';
import {wireCancellationToken} from 'vs/base/common/async'; import {wireCancellationToken} from 'vs/base/common/async';
import {ICompatWorkerService, CompatWorkerAttr} from 'vs/editor/common/services/compatWorkerService'; import {ICompatWorkerService, CompatWorkerAttr} from 'vs/editor/common/services/compatWorkerService';
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
export class OutputMode extends CompatMode { export class OutputMode extends CompatMode {
...@@ -21,7 +22,8 @@ export class OutputMode extends CompatMode { ...@@ -21,7 +22,8 @@ export class OutputMode extends CompatMode {
constructor( constructor(
descriptor: IModeDescriptor, descriptor: IModeDescriptor,
@IInstantiationService instantiationService: IInstantiationService, @IInstantiationService instantiationService: IInstantiationService,
@ICompatWorkerService compatWorkerService: ICompatWorkerService @ICompatWorkerService compatWorkerService: ICompatWorkerService,
@IWorkspaceContextService contextService:IWorkspaceContextService
) { ) {
super(descriptor.id, compatWorkerService); super(descriptor.id, compatWorkerService);
this._modeWorkerManager = new ModeWorkerManager<OutputWorker>(descriptor, 'vs/workbench/parts/output/common/outputWorker', 'OutputWorker', null, instantiationService); this._modeWorkerManager = new ModeWorkerManager<OutputWorker>(descriptor, 'vs/workbench/parts/output/common/outputWorker', 'OutputWorker', null, instantiationService);
...@@ -31,12 +33,24 @@ export class OutputMode extends CompatMode { ...@@ -31,12 +33,24 @@ export class OutputMode extends CompatMode {
return wireCancellationToken(token, this._provideLinks(model.uri)); return wireCancellationToken(token, this._provideLinks(model.uri));
} }
}); });
if (compatWorkerService.isInMainThread) {
let workspace = contextService.getWorkspace();
if (workspace) {
this._configure(workspace.resource);
}
}
} }
private _worker<T>(runner: (worker: OutputWorker) => TPromise<T>): TPromise<T> { private _worker<T>(runner: (worker: OutputWorker) => TPromise<T>): TPromise<T> {
return this._modeWorkerManager.worker(runner); return this._modeWorkerManager.worker(runner);
} }
static $_configure = CompatWorkerAttr(OutputMode, OutputMode.prototype._configure);
private _configure(workspaceResource: URI): TPromise<void> {
return this._worker((w) => w.configure(workspaceResource));
}
static $_provideLinks = CompatWorkerAttr(OutputMode, OutputMode.prototype._provideLinks); static $_provideLinks = CompatWorkerAttr(OutputMode, OutputMode.prototype._provideLinks);
private _provideLinks(resource: URI): TPromise<modes.ILink[]> { private _provideLinks(resource: URI): TPromise<modes.ILink[]> {
return this._worker((w) => w.provideLinks(resource)); return this._worker((w) => w.provideLinks(resource));
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
'use strict'; 'use strict';
import {TPromise} from 'vs/base/common/winjs.base'; import {TPromise} from 'vs/base/common/winjs.base';
import {IMarkerService} from 'vs/platform/markers/common/markers';
import {IResourceService} from 'vs/editor/common/services/resourceService'; import {IResourceService} from 'vs/editor/common/services/resourceService';
import URI from 'vs/base/common/uri'; import URI from 'vs/base/common/uri';
import strings = require('vs/base/common/strings'); import strings = require('vs/base/common/strings');
...@@ -13,35 +12,34 @@ import arrays = require('vs/base/common/arrays'); ...@@ -13,35 +12,34 @@ import arrays = require('vs/base/common/arrays');
import paths = require('vs/base/common/paths'); import paths = require('vs/base/common/paths');
import {ILink} from 'vs/editor/common/modes'; import {ILink} from 'vs/editor/common/modes';
import {Range} from 'vs/editor/common/core/range'; import {Range} from 'vs/editor/common/core/range';
import {IWorkspaceContextService, IWorkspace} from 'vs/platform/workspace/common/workspace';
export interface IResourceCreator {
toResource: (workspaceRelativePath: string) => URI;
}
/** /**
* A base class of text editor worker that helps with detecting links in the text that point to files in the workspace. * A base class of text editor worker that helps with detecting links in the text that point to files in the workspace.
*/ */
export class OutputWorker { export class OutputWorker {
private _contextService: IWorkspaceContextService; private _workspaceResource: URI;
private patterns: RegExp[]; private patterns: RegExp[];
private resourceService:IResourceService; private resourceService:IResourceService;
private markerService: IMarkerService;
private _modeId: string; private _modeId: string;
constructor( constructor(
modeId: string, modeId: string,
@IResourceService resourceService: IResourceService, @IResourceService resourceService: IResourceService
@IMarkerService markerService: IMarkerService,
@IWorkspaceContextService contextService:IWorkspaceContextService
) { ) {
this._modeId = modeId; this._modeId = modeId;
this.resourceService = resourceService; this.resourceService = resourceService;
this.markerService = markerService; this._workspaceResource = null;
this._contextService = contextService; this.patterns = [];
let workspace = this._contextService.getWorkspace();
this.patterns = workspace ? OutputWorker.createPatterns(workspace) : [];
} }
public get contextService(): IWorkspaceContextService { public configure(workspaceResource: URI): TPromise<void> {
return this._contextService; this._workspaceResource = workspaceResource;
this.patterns = OutputWorker.createPatterns(this._workspaceResource);
return TPromise.as(void 0);
} }
public provideLinks(resource: URI): TPromise<ILink[]> { public provideLinks(resource: URI): TPromise<ILink[]> {
...@@ -52,19 +50,28 @@ export class OutputWorker { ...@@ -52,19 +50,28 @@ export class OutputWorker {
let model = this.resourceService.get(resource); let model = this.resourceService.get(resource);
let resourceCreator: IResourceCreator = {
toResource: (workspaceRelativePath: string): URI => {
if (typeof workspaceRelativePath === 'string' && this._workspaceResource) {
return URI.file(paths.join(this._workspaceResource.fsPath, workspaceRelativePath));
}
return null;
}
};
for (let i = 1, lineCount = model.getLineCount(); i <= lineCount; i++) { for (let i = 1, lineCount = model.getLineCount(); i <= lineCount; i++) {
links.push(...OutputWorker.detectLinks(model.getLineContent(i), i, this.patterns, this._contextService)); links.push(...OutputWorker.detectLinks(model.getLineContent(i), i, this.patterns, resourceCreator));
} }
return TPromise.as(links); return TPromise.as(links);
} }
public static createPatterns(workspace: IWorkspace): RegExp[] { public static createPatterns(workspaceResource: URI): RegExp[] {
let patterns: RegExp[] = []; let patterns: RegExp[] = [];
let workspaceRootVariants = arrays.distinct([ let workspaceRootVariants = arrays.distinct([
paths.normalize(workspace.resource.fsPath, true), paths.normalize(workspaceResource.fsPath, true),
paths.normalize(workspace.resource.fsPath, false) paths.normalize(workspaceResource.fsPath, false)
]); ]);
workspaceRootVariants.forEach((workspaceRoot) => { workspaceRootVariants.forEach((workspaceRoot) => {
...@@ -93,7 +100,7 @@ export class OutputWorker { ...@@ -93,7 +100,7 @@ export class OutputWorker {
/** /**
* Detect links. Made public static to allow for tests. * Detect links. Made public static to allow for tests.
*/ */
public static detectLinks(line: string, lineIndex: number, patterns: RegExp[], contextService: IWorkspaceContextService): ILink[] { public static detectLinks(line: string, lineIndex: number, patterns: RegExp[], contextService: IResourceCreator): ILink[] {
let links: ILink[] = []; let links: ILink[] = [];
patterns.forEach((pattern) => { patterns.forEach((pattern) => {
......
...@@ -22,21 +22,13 @@ function toOSPath(p: string): string { ...@@ -22,21 +22,13 @@ function toOSPath(p: string): string {
suite('Workbench - OutputWorker', () => { suite('Workbench - OutputWorker', () => {
test('OutputWorker - Link detection', function () { test('OutputWorker - Link detection', function () {
let patternsSlash = OutputWorker.createPatterns({ let patternsSlash = OutputWorker.createPatterns(
id: 'foo', URI.file('C:/Users/someone/AppData/Local/Temp/_monacodata_9888/workspaces/mankala')
name: 'foo', );
resource: URI.file('C:/Users/someone/AppData/Local/Temp/_monacodata_9888/workspaces/mankala'),
uid: 0, let patternsBackSlash = OutputWorker.createPatterns(
mtime: 0 URI.file('C:\\Users\\someone\\AppData\\Local\\Temp\\_monacodata_9888\\workspaces\\mankala')
}); );
let patternsBackSlash = OutputWorker.createPatterns({
id: 'foo',
name: 'foo',
resource: URI.file('C:\\Users\\someone\\AppData\\Local\\Temp\\_monacodata_9888\\workspaces\\mankala'),
uid: 0,
mtime: 0
});
let contextService = new TestContextService(); let contextService = new TestContextService();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册