提交 19b321ba 编写于 作者: B Benjamin Pasero

Adopt resource editor inputs for output (part of #17063)

上级 2d83288e
......@@ -74,26 +74,6 @@ export class StringEditorInput extends EditorInput {
}
}
/**
* Clears the textual value of this input and will also update the underlying model if this input is resolved.
*/
public clearValue(): void {
this.value = '';
if (this.cachedModel) {
this.cachedModel.clearValue();
}
}
/**
* Appends to the textual value of this input and will also update the underlying model if this input is resolved.
*/
public append(value: string): void {
this.value += value;
if (this.cachedModel) {
this.cachedModel.append(value);
}
}
public resolve(refresh?: boolean): TPromise<EditorModel> {
// Use Cached Model
......
......@@ -8,11 +8,8 @@ import { TPromise } from 'vs/base/common/winjs.base';
import { BaseTextEditorModel } from 'vs/workbench/common/editor/textEditorModel';
import { EditorModel } from 'vs/workbench/common/editor';
import URI from 'vs/base/common/uri';
import { Position } from 'vs/editor/common/core/position';
import { Range } from 'vs/editor/common/core/range';
import { IModeService } from 'vs/editor/common/services/modeService';
import { IModelService } from 'vs/editor/common/services/modelService';
import { EditOperation } from 'vs/editor/common/core/editOperation';
/**
* An editor model whith an in-memory, readonly content that is not backed by any particular resource.
......@@ -53,52 +50,6 @@ export class StringEditorModel extends BaseTextEditorModel {
}
}
/**
* Appends value to this string editor model.
*/
public append(value: string): void {
this.value += value;
if (this.textEditorModel) {
let model = this.textEditorModel;
let lastLine = model.getLineCount();
let lastLineMaxColumn = model.getLineMaxColumn(lastLine);
model.applyEdits([EditOperation.insert(new Position(lastLine, lastLineMaxColumn), value)]);
}
}
/**
* Clears the value of this string editor model
*/
public clearValue(): void {
this.value = '';
if (this.textEditorModel) {
let model = this.textEditorModel;
let lastLine = model.getLineCount();
model.applyEdits([EditOperation.delete(new Range(1, 1, lastLine, model.getLineMaxColumn(lastLine)))]);
}
}
/**
* Removes all lines from the top if the line number exceeds the given line count. Returns the new value if lines got trimmed.
*/
public trim(linecount: number): string {
if (this.textEditorModel) {
let model = this.textEditorModel;
let lastLine = model.getLineCount();
if (lastLine > linecount) {
model.applyEdits([EditOperation.delete(new Range(1, 1, lastLine - linecount + 1, 1))]);
let newValue = model.getValue();
this.value = newValue;
return this.value;
}
}
return null;
}
public load(): TPromise<EditorModel> {
// Create text editor model if not yet done
......
/*---------------------------------------------------------------------------------------------
* 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 nls = require('vs/nls');
import lifecycle = require('vs/base/common/lifecycle');
import strings = require('vs/base/common/strings');
import { TPromise } from 'vs/base/common/winjs.base';
import { RunOnceScheduler } from 'vs/base/common/async';
import { EditorModel } from 'vs/workbench/common/editor';
import { StringEditorInput } from 'vs/workbench/common/editor/stringEditorInput';
import { OUTPUT_EDITOR_INPUT_ID, OUTPUT_PANEL_ID, IOutputEvent, OUTPUT_MIME, IOutputService, MAX_OUTPUT_LENGTH, IOutputChannel } from 'vs/workbench/parts/output/common/output';
import { OutputPanel } from 'vs/workbench/parts/output/browser/outputPanel';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
/**
* Output Editor Input
*/
export class OutputEditorInput extends StringEditorInput {
private static OUTPUT_DELAY = 300; // delay in ms to accumulate output before emitting an event about it
private static instances: { [channel: string]: OutputEditorInput; } = Object.create(null);
private outputSet: boolean;
private bufferedOutput: string;
private toDispose: lifecycle.IDisposable[];
private appendOutputScheduler: RunOnceScheduler;
public static getInstances(): OutputEditorInput[] {
return Object.keys(OutputEditorInput.instances).map((key) => OutputEditorInput.instances[key]);
}
public static getInstance(instantiationService: IInstantiationService, channel: IOutputChannel): OutputEditorInput {
if (OutputEditorInput.instances[channel.id]) {
return OutputEditorInput.instances[channel.id];
}
OutputEditorInput.instances[channel.id] = instantiationService.createInstance(OutputEditorInput, channel);
return OutputEditorInput.instances[channel.id];
}
constructor(
private outputChannel: IOutputChannel,
@IInstantiationService instantiationService: IInstantiationService,
@IOutputService private outputService: IOutputService,
@IPanelService private panelService: IPanelService
) {
super(nls.localize('output', "Output"), outputChannel ? nls.localize('outputChannel', "for '{0}'", outputChannel.label) : '', '', OUTPUT_MIME, true, instantiationService);
this.bufferedOutput = '';
this.toDispose = [];
this.toDispose.push(this.outputService.onOutput(this.onOutputReceived, this));
this.toDispose.push(this.outputService.onActiveOutputChannel(() => this.scheduleOutputAppend()));
this.toDispose.push(this.panelService.onDidPanelOpen(panel => {
if (panel.getId() === OUTPUT_PANEL_ID) {
this.appendOutput();
}
}));
this.appendOutputScheduler = new RunOnceScheduler(() => {
if (this.isVisible()) {
this.appendOutput();
}
}, OutputEditorInput.OUTPUT_DELAY);
}
private appendOutput(): void {
if (this.bufferedOutput.length === 0) {
return;
}
if (this.value.length + this.bufferedOutput.length > MAX_OUTPUT_LENGTH) {
this.setValue(this.outputChannel.output);
} else {
this.append(this.bufferedOutput);
}
this.bufferedOutput = '';
const panel = this.panelService.getActivePanel();
(<OutputPanel>panel).revealLastLine(true);
}
private onOutputReceived(e: IOutputEvent): void {
if (this.outputSet && e.channelId === this.outputChannel.id) {
if (e.output) {
this.bufferedOutput = strings.appendWithLimit(this.bufferedOutput, e.output, MAX_OUTPUT_LENGTH);
this.scheduleOutputAppend();
} else if (e.output === null) {
this.bufferedOutput = '';
this.clearValue(); // special output indicates we should clear
}
}
}
private isVisible(): boolean {
const panel = this.panelService.getActivePanel();
return panel && panel.getId() === OUTPUT_PANEL_ID && this.outputService.getActiveChannel().id === this.outputChannel.id;
}
private scheduleOutputAppend(): void {
if (this.isVisible() && this.bufferedOutput && !this.appendOutputScheduler.isScheduled()) {
this.appendOutputScheduler.schedule();
}
}
public getTypeId(): string {
return OUTPUT_EDITOR_INPUT_ID;
}
public resolve(refresh?: boolean): TPromise<EditorModel> {
return super.resolve(refresh).then(model => {
// Just return model if output already set
if (this.outputSet) {
return model;
}
this.setValue(this.outputChannel.output);
this.outputSet = true;
return model;
});
}
public matches(otherInput: any): boolean {
if (otherInput instanceof OutputEditorInput) {
let otherOutputEditorInput = <OutputEditorInput>otherInput;
if (otherOutputEditorInput.outputChannel.id === this.outputChannel.id) {
return super.matches(otherInput);
}
}
return false;
}
public dispose(): void {
this.appendOutputScheduler.dispose();
this.toDispose = lifecycle.dispose(this.toDispose);
super.dispose();
}
}
......@@ -18,8 +18,7 @@ import { ServiceCollection } from 'vs/platform/instantiation/common/serviceColle
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { EditorInput, EditorOptions } from 'vs/workbench/common/editor';
import { StringEditor } from 'vs/workbench/browser/parts/editor/stringEditor';
import { OUTPUT_PANEL_ID, IOutputService, CONTEXT_IN_OUTPUT } from 'vs/workbench/parts/output/common/output';
import { OutputEditorInput } from 'vs/workbench/parts/output/browser/outputEditorInput';
import { OutputEditors, OUTPUT_PANEL_ID, IOutputService, CONTEXT_IN_OUTPUT } from 'vs/workbench/parts/output/common/output';
import { SwitchOutputAction, SwitchOutputActionItem, ClearOutputAction } from 'vs/workbench/parts/output/browser/outputActions';
import { IThemeService } from 'vs/workbench/services/themes/common/themeService';
import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
......@@ -106,7 +105,7 @@ export class OutputPanel extends StringEditor {
super.createEditor(parent);
CONTEXT_IN_OUTPUT.bindTo(scopedContextKeyService).set(true);
this.setInput(OutputEditorInput.getInstance(this.instantiationService, this.outputService.getActiveChannel()), null);
this.setInput(OutputEditors.getInstance(this.instantiationService, this.outputService.getActiveChannel()), null);
}
public get instantiationService(): IInstantiationService {
......
......@@ -6,18 +6,25 @@
import { TPromise } from 'vs/base/common/winjs.base';
import strings = require('vs/base/common/strings');
import Event, { Emitter } from 'vs/base/common/event';
import URI from 'vs/base/common/uri';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { IEditor } from 'vs/platform/editor/common/editor';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { Registry } from 'vs/platform/platform';
import { EditorOptions } from 'vs/workbench/common/editor';
import { IOutputEvent, IOutputChannel, IOutputService, Extensions, OUTPUT_PANEL_ID, IOutputChannelRegistry, MAX_OUTPUT_LENGTH } from 'vs/workbench/parts/output/common/output';
import { OutputEditorInput } from 'vs/workbench/parts/output/browser/outputEditorInput';
import { OutputEditors, IOutputEvent, IOutputChannel, IOutputService, Extensions, OUTPUT_PANEL_ID, IOutputChannelRegistry, MAX_OUTPUT_LENGTH, OUTPUT_SCHEME, OUTPUT_MIME } from 'vs/workbench/parts/output/common/output';
import { OutputPanel } from 'vs/workbench/parts/output/browser/outputPanel';
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';
import { ITextModelResolverService, ITextModelContentProvider } from 'vs/editor/common/services/resolverService';
import { IModel } from 'vs/editor/common/editorCommon';
import { IModeService } from 'vs/editor/common/services/modeService';
import { RunOnceScheduler } from 'vs/base/common/async';
import { EditOperation } from 'vs/editor/common/core/editOperation';
import { Position } from 'vs/editor/common/core/position';
const OUTPUT_ACTIVE_CHANNEL_KEY = 'output.activechannel';
......@@ -40,7 +47,8 @@ export class OutputService implements IOutputService {
@IInstantiationService private instantiationService: IInstantiationService,
@IPanelService private panelService: IPanelService,
@IWorkspaceContextService contextService: IWorkspaceContextService,
@IModelService modelService: IModelService
@IModelService modelService: IModelService,
@ITextModelResolverService textModelResolverService: ITextModelResolverService
) {
this._onOutput = new Emitter<IOutputEvent>();
this._onOutputChannel = new Emitter<string>();
......@@ -52,6 +60,9 @@ export class OutputService implements IOutputService {
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);
// Register as text model content provider for output
textModelResolverService.registerTextModelContentProvider(OUTPUT_SCHEME, instantiationService.createInstance(OutputContentProvider, this));
}
public get onOutput(): Event<IOutputEvent> {
......@@ -127,8 +138,151 @@ export class OutputService implements IOutputService {
this._onActiveOutputChannel.fire(channelId); // emit event that a new channel is active
return this.panelService.openPanel(OUTPUT_PANEL_ID, !preserveFocus).then((outputPanel: OutputPanel) => {
return outputPanel && outputPanel.setInput(OutputEditorInput.getInstance(this.instantiationService, this.getChannel(channelId)), EditorOptions.create({ preserveFocus: preserveFocus })).
return outputPanel && outputPanel.setInput(OutputEditors.getInstance(this.instantiationService, this.getChannel(channelId)), EditorOptions.create({ preserveFocus: preserveFocus })).
then(() => outputPanel);
});
}
}
class OutputContentProvider implements ITextModelContentProvider {
private static OUTPUT_DELAY = 300;
private bufferedOutput: { [channel: string]: string; };
private appendOutputScheduler: { [channel: string]: RunOnceScheduler; };
private toDispose: IDisposable[];
constructor(
private outputService: IOutputService,
@IModelService private modelService: IModelService,
@IModeService private modeService: IModeService,
@IPanelService private panelService: IPanelService
) {
this.bufferedOutput = Object.create(null);
this.appendOutputScheduler = Object.create(null);
this.toDispose = [];
this.registerListeners();
}
private registerListeners(): void {
this.toDispose.push(this.outputService.onOutput(e => this.onOutputReceived(e)));
this.toDispose.push(this.outputService.onActiveOutputChannel(channel => this.scheduleOutputAppend(channel)));
this.toDispose.push(this.panelService.onDidPanelOpen(panel => {
if (panel.getId() === OUTPUT_PANEL_ID) {
this.appendOutput();
}
}));
}
private onOutputReceived(e: IOutputEvent): void {
const model = this.getModel(e.channelId);
if (!model) {
return; // only react if we have a known model
}
// Append to model
if (e.output) {
this.bufferedOutput[e.channelId] = strings.appendWithLimit(this.bufferedOutput[e.channelId] || '', e.output, MAX_OUTPUT_LENGTH);
this.scheduleOutputAppend(e.channelId);
}
// Clear from model
else if (e.output === null) {
this.bufferedOutput[e.channelId] = '';
model.setValue('');
}
}
private getModel(channel: string): IModel {
return this.modelService.getModel(URI.from({ scheme: OUTPUT_SCHEME, path: channel }));
}
private scheduleOutputAppend(channel: string): void {
if (!this.isVisible(channel)) {
return; // only if the output channel is visible
}
if (!this.bufferedOutput[channel]) {
return; // only if we have any output to show
}
let scheduler = this.appendOutputScheduler[channel];
if (!scheduler) {
scheduler = new RunOnceScheduler(() => {
if (this.isVisible(channel)) {
this.appendOutput(channel);
}
}, OutputContentProvider.OUTPUT_DELAY);
this.appendOutputScheduler[channel] = scheduler;
this.toDispose.push(scheduler);
}
if (scheduler.isScheduled()) {
return; // only if not already scheduled
}
scheduler.schedule();
}
private appendOutput(channel?: string): void {
if (!channel) {
const activeChannel = this.outputService.getActiveChannel();
channel = activeChannel && activeChannel.id;
}
if (!channel) {
return; // return if we do not have a valid channel to append to
}
const model = this.getModel(channel);
if (!model) {
return; // only react if we have a known model
}
const bufferedOutput = this.bufferedOutput[channel];
if (!bufferedOutput) {
return; // return if nothing to append
}
// just fill in the full (trimmed) output if we exceed max length
if (model.getValueLength() + bufferedOutput.length > MAX_OUTPUT_LENGTH) {
model.setValue(this.outputService.getChannel(channel).output);
}
// otherwise append
else {
const lastLine = model.getLineCount();
const lastLineMaxColumn = model.getLineMaxColumn(lastLine);
model.applyEdits([EditOperation.insert(new Position(lastLine, lastLineMaxColumn), bufferedOutput)]);
}
// reveal last line
const panel = this.panelService.getActivePanel();
(<OutputPanel>panel).revealLastLine(true);
}
private isVisible(channel: string): boolean {
const panel = this.panelService.getActivePanel();
return panel && panel.getId() === OUTPUT_PANEL_ID && this.outputService.getActiveChannel().id === channel;
}
public provideTextContent(resource: URI): TPromise<IModel> {
const content = this.outputService.getChannel(resource.fsPath).output;
let codeEditorModel = this.modelService.getModel(resource);
if (!codeEditorModel) {
codeEditorModel = this.modelService.createModel(content, this.modeService.getOrCreateMode(OUTPUT_MIME), resource);
}
return TPromise.as(codeEditorModel);
}
public dispose(): void {
this.toDispose = dispose(this.toDispose);
}
}
\ No newline at end of file
......@@ -7,9 +7,12 @@
import { TPromise } from 'vs/base/common/winjs.base';
import Event from 'vs/base/common/event';
import { Registry } from 'vs/platform/platform';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { createDecorator, IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IEditor } from 'vs/platform/editor/common/editor';
import { RawContextKey } from 'vs/platform/contextkey/common/contextkey';
import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorInput';
import nls = require('vs/nls');
import URI from 'vs/base/common/uri';
/**
* Mime type used by the output editor.
......@@ -17,14 +20,14 @@ import { RawContextKey } from 'vs/platform/contextkey/common/contextkey';
export const OUTPUT_MIME = 'text/x-code-output';
/**
* Id used by the output editor.
* Output resource scheme.
*/
export const OUTPUT_MODE_ID = 'Log';
export const OUTPUT_SCHEME = 'output';
/**
* Output editor input id.
* Id used by the output editor.
*/
export const OUTPUT_EDITOR_INPUT_ID = 'vs.output';
export const OUTPUT_MODE_ID = 'Log';
/**
* Output panel id
......@@ -150,3 +153,20 @@ class OutputChannelRegistry implements IOutputChannelRegistry {
}
Registry.add(Extensions.OutputChannels, new OutputChannelRegistry());
export class OutputEditors {
private static instances: { [channel: string]: ResourceEditorInput; } = Object.create(null);
public static getInstance(instantiationService: IInstantiationService, channel: IOutputChannel): ResourceEditorInput {
if (OutputEditors.instances[channel.id]) {
return OutputEditors.instances[channel.id];
}
const resource = URI.from({ scheme: OUTPUT_SCHEME, path: channel.id });
OutputEditors.instances[channel.id] = instantiationService.createInstance(ResourceEditorInput, nls.localize('output', "Output"), channel ? nls.localize('channel', "for '{0}'", channel.label) : '', resource);
return OutputEditors.instances[channel.id];
}
}
\ No newline at end of file
......@@ -20,7 +20,6 @@ import { ModeServiceImpl } from 'vs/editor/common/services/modeServiceImpl';
import WorkbenchEditorService = require('vs/workbench/services/editor/common/editorService');
suite('Workbench - StringEditorInput', () => {
let instantiationService: TestInstantiationService;
let editorService: WorkbenchEditorService.IWorkbenchEditorService;
let modelService: IModelService;
......@@ -34,13 +33,12 @@ suite('Workbench - StringEditorInput', () => {
});
test('StringEditorInput', function (done) {
let input: StringEditorInput = instantiationService.createInstance(StringEditorInput, 'name', 'description', 'value', 'mode', false);
const otherInput: StringEditorInput = instantiationService.createInstance(StringEditorInput, 'name', 'description', 'othervalue', 'mode', false);
const otherInputSame: StringEditorInput = instantiationService.createInstance(StringEditorInput, 'name', 'description', 'value', 'mode', false);
let input = instantiationService.createInstance(StringEditorInput, 'name', 'description', 'value', 'mode', false);
let otherInput = instantiationService.createInstance(StringEditorInput, 'name', 'description', 'othervalue', 'mode', false);
let otherInputSame = instantiationService.createInstance(StringEditorInput, 'name', 'description', 'value', 'mode', false);
let inputSingleton = instantiationService.createInstance(StringEditorInput, 'name', 'description', 'value', 'mode', true);
let otherInputSingleton = instantiationService.createInstance(StringEditorInput, 'name', 'description', 'othervalue', 'mode', true);
const inputSingleton: StringEditorInput = instantiationService.createInstance(StringEditorInput, 'name', 'description', 'value', 'mode', true);
const otherInputSingleton: StringEditorInput = instantiationService.createInstance(StringEditorInput, 'name', 'description', 'othervalue', 'mode', true);
assert(inputSingleton.matches(otherInputSingleton));
(<any>otherInputSingleton).singleton = false;
assert(!inputSingleton.matches(otherInputSingleton));
......@@ -55,11 +53,11 @@ suite('Workbench - StringEditorInput', () => {
input = instantiationService.createInstance(StringEditorInput, 'name', 'description', 'value', 'mode', false);
input.resolve(true).then(resolved => {
let resolvedModelA = resolved;
const resolvedModelA = resolved;
return input.resolve(true).then(resolved => {
assert(resolvedModelA === resolved); // assert: Resolved Model cached per instance
let otherInput = instantiationService.createInstance(StringEditorInput, 'name', 'description', 'value', 'mode', false);
const otherInput: StringEditorInput = instantiationService.createInstance(StringEditorInput, 'name', 'description', 'value', 'mode', false);
return otherInput.resolve(true).then(resolved => {
assert(resolvedModelA !== resolved); // NOT assert: Different instance, different model
......@@ -68,7 +66,7 @@ suite('Workbench - StringEditorInput', () => {
return input.resolve(true).then(resolved => {
assert(resolvedModelA !== resolved); // Different instance, because input got disposed
let model = (<any>resolved).textEditorModel;
const model = (<any>resolved).textEditorModel;
return input.resolve(true).then(againResolved => {
assert(model === (<any>againResolved).textEditorModel); // Models should not differ because string input is constant
......@@ -81,27 +79,23 @@ suite('Workbench - StringEditorInput', () => {
});
test('StringEditorInput - setValue, clearValue, append', function () {
let input = instantiationService.createInstance(StringEditorInput, 'name', 'description', 'value', 'mode', false);
const input: StringEditorInput = instantiationService.createInstance(StringEditorInput, 'name', 'description', 'value', 'mode', false);
assert.strictEqual(input.getValue(), 'value');
input.setValue('foo');
assert.strictEqual(input.getValue(), 'foo');
input.clearValue();
input.setValue('');
assert(!input.getValue());
input.append('1');
assert.strictEqual(input.getValue(), '1');
input.append('2');
assert.strictEqual(input.getValue(), '12');
});
test('Input.matches() - StringEditorInput', function () {
let inst = new TestInstantiationService();
const inst = new TestInstantiationService();
let stringEditorInput = inst.createInstance(StringEditorInput, 'name', 'description', 'value', 'mode', false);
let promiseEditorInput = inst.createInstance(ResourceEditorInput, 'name', 'description', URI.from({ scheme: 'inMemory', authority: null, path: 'thePath' }));
const stringEditorInput: StringEditorInput = inst.createInstance(StringEditorInput, 'name', 'description', 'value', 'mode', false);
const promiseEditorInput: StringEditorInput = inst.createInstance(ResourceEditorInput, 'name', 'description', URI.from({ scheme: 'inMemory', authority: null, path: 'thePath' }));
let stringEditorInput2 = inst.createInstance(StringEditorInput, 'name', 'description', 'value', 'mode', false);
let promiseEditorInput2 = inst.createInstance(ResourceEditorInput, 'name', 'description', URI.from({ scheme: 'inMemory', authority: null, path: 'thePath' }));
const stringEditorInput2: StringEditorInput = inst.createInstance(StringEditorInput, 'name', 'description', 'value', 'mode', false);
const promiseEditorInput2: StringEditorInput = inst.createInstance(ResourceEditorInput, 'name', 'description', URI.from({ scheme: 'inMemory', authority: null, path: 'thePath' }));
assert.strictEqual(stringEditorInput.matches(null), false);
assert.strictEqual(promiseEditorInput.matches(null), false);
......@@ -115,6 +109,7 @@ suite('Workbench - StringEditorInput', () => {
function stubModelService(instantiationService: TestInstantiationService): IModelService {
instantiationService.stub(IConfigurationService, new TestConfigurationService());
return instantiationService.createInstance(ModelServiceImpl);
}
});
\ No newline at end of file
......@@ -16,7 +16,6 @@ import { TestConfigurationService } from 'vs/platform/configuration/test/common/
import { ModelServiceImpl } from 'vs/editor/common/services/modelServiceImpl';
suite('Workbench - StringEditorModel', () => {
let instantiationService: TestInstantiationService;
setup(() => {
......@@ -26,11 +25,11 @@ suite('Workbench - StringEditorModel', () => {
test('StringEditorModel', function (done) {
instantiationService.stub(IModelService, stubModelService(instantiationService));
let m = instantiationService.createInstance(StringEditorModel, 'value', 'mode', null);
const m: StringEditorModel = instantiationService.createInstance(StringEditorModel, 'value', 'mode', null);
m.load().then(model => {
assert(model === m);
let textEditorModel = m.textEditorModel;
const textEditorModel = m.textEditorModel;
assert.strictEqual(textEditorModel.getValue(), 'value');
assert.strictEqual(m.isResolved(), true);
......@@ -46,36 +45,22 @@ suite('Workbench - StringEditorModel', () => {
});
});
test('StringEditorModel - setValue, clearValue, append, trim', function (done) {
test('StringEditorModel - setValue', function (done) {
instantiationService.stub(IModelService, stubModelService(instantiationService));
let m = instantiationService.createInstance(StringEditorModel, 'value', 'mode', null);
const m: StringEditorModel = instantiationService.createInstance(StringEditorModel, 'value', 'mode', null);
m.load().then(model => {
assert(model === m);
let textEditorModel = m.textEditorModel;
const textEditorModel = m.textEditorModel;
assert.strictEqual(textEditorModel.getValue(), 'value');
m.setValue('foobar');
assert.strictEqual(m.getValue(), 'foobar');
assert.strictEqual(textEditorModel.getValue(), 'foobar');
m.clearValue();
m.setValue('');
assert(!m.getValue());
assert(!textEditorModel.getValue());
m.append('1');
assert.strictEqual(m.getValue(), '1');
assert.strictEqual(textEditorModel.getValue(), '1');
m.append('1');
assert.strictEqual(m.getValue(), '11');
assert.strictEqual(textEditorModel.getValue(), '11');
m.setValue('line\nline\nline');
m.trim(2);
assert.strictEqual(m.getValue(), 'line\nline');
assert.strictEqual(textEditorModel.getValue(), 'line\nline');
}).done(() => {
m.dispose();
done();
......@@ -84,6 +69,7 @@ suite('Workbench - StringEditorModel', () => {
function stubModelService(instantiationService: TestInstantiationService): IModelService {
instantiationService.stub(IConfigurationService, new TestConfigurationService());
return instantiationService.createInstance(ModelServiceImpl);
}
});
\ No newline at end of file
......@@ -162,21 +162,21 @@ suite('Workbench - Untitled Editor', () => {
});
input.resolve().then((model: UntitledEditorModel) => {
model.append('foo');
model.setValue('foo');
assert.equal(counter, 0, 'Dirty model should not trigger event immediately');
TPromise.timeout(3).then(() => {
assert.equal(counter, 1, 'Dirty model should trigger event');
model.append('bar');
model.setValue('bar');
TPromise.timeout(3).then(() => {
assert.equal(counter, 2, 'Content change when dirty should trigger event');
model.clearValue();
model.setValue('');
TPromise.timeout(3).then(() => {
assert.equal(counter, 3, 'Manual revert should trigger event');
model.append('foo');
model.setValue('foo');
TPromise.timeout(3).then(() => {
assert.equal(counter, 4, 'Dirty model should trigger event');
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册