From 19b321baf11308380771fd15449a792827a16707 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Wed, 28 Dec 2016 10:19:19 +0100 Subject: [PATCH] Adopt resource editor inputs for output (part of #17063) --- .../common/editor/stringEditorInput.ts | 20 --- .../common/editor/stringEditorModel.ts | 49 ------ .../parts/output/browser/outputEditorInput.ts | 145 ---------------- .../parts/output/browser/outputPanel.ts | 5 +- .../parts/output/browser/outputServices.ts | 162 +++++++++++++++++- .../workbench/parts/output/common/output.ts | 30 +++- .../common/editor/stringEditorInput.test.ts | 37 ++-- .../common/editor/stringEditorModel.test.ts | 28 +-- .../test/common/editor/untitledEditor.test.ts | 8 +- 9 files changed, 212 insertions(+), 272 deletions(-) delete mode 100644 src/vs/workbench/parts/output/browser/outputEditorInput.ts diff --git a/src/vs/workbench/common/editor/stringEditorInput.ts b/src/vs/workbench/common/editor/stringEditorInput.ts index 9e4d7656293..bf5b0489b87 100644 --- a/src/vs/workbench/common/editor/stringEditorInput.ts +++ b/src/vs/workbench/common/editor/stringEditorInput.ts @@ -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 { // Use Cached Model diff --git a/src/vs/workbench/common/editor/stringEditorModel.ts b/src/vs/workbench/common/editor/stringEditorModel.ts index 82ba83b27a3..bee71a6bb7b 100644 --- a/src/vs/workbench/common/editor/stringEditorModel.ts +++ b/src/vs/workbench/common/editor/stringEditorModel.ts @@ -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 { // Create text editor model if not yet done diff --git a/src/vs/workbench/parts/output/browser/outputEditorInput.ts b/src/vs/workbench/parts/output/browser/outputEditorInput.ts deleted file mode 100644 index 1b9e457be68..00000000000 --- a/src/vs/workbench/parts/output/browser/outputEditorInput.ts +++ /dev/null @@ -1,145 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * 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(); - (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 { - 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 = 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(); - } -} diff --git a/src/vs/workbench/parts/output/browser/outputPanel.ts b/src/vs/workbench/parts/output/browser/outputPanel.ts index d1baef56afa..fea1339e8c0 100644 --- a/src/vs/workbench/parts/output/browser/outputPanel.ts +++ b/src/vs/workbench/parts/output/browser/outputPanel.ts @@ -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 { diff --git a/src/vs/workbench/parts/output/browser/outputServices.ts b/src/vs/workbench/parts/output/browser/outputServices.ts index 334de57560d..cd5d58d457a 100644 --- a/src/vs/workbench/parts/output/browser/outputServices.ts +++ b/src/vs/workbench/parts/output/browser/outputServices.ts @@ -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(); this._onOutputChannel = new Emitter(); @@ -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 { @@ -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(); + (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 { + 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 diff --git a/src/vs/workbench/parts/output/common/output.ts b/src/vs/workbench/parts/output/common/output.ts index 9e2e8d41c10..eb3de6fec37 100644 --- a/src/vs/workbench/parts/output/common/output.ts +++ b/src/vs/workbench/parts/output/common/output.ts @@ -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 diff --git a/src/vs/workbench/test/common/editor/stringEditorInput.test.ts b/src/vs/workbench/test/common/editor/stringEditorInput.test.ts index b6b2926d710..9d4fda893a1 100644 --- a/src/vs/workbench/test/common/editor/stringEditorInput.test.ts +++ b/src/vs/workbench/test/common/editor/stringEditorInput.test.ts @@ -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)); (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 = (resolved).textEditorModel; + const model = (resolved).textEditorModel; return input.resolve(true).then(againResolved => { assert(model === (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 diff --git a/src/vs/workbench/test/common/editor/stringEditorModel.test.ts b/src/vs/workbench/test/common/editor/stringEditorModel.test.ts index fb28147b5b8..8258b2c28b2 100644 --- a/src/vs/workbench/test/common/editor/stringEditorModel.test.ts +++ b/src/vs/workbench/test/common/editor/stringEditorModel.test.ts @@ -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 diff --git a/src/vs/workbench/test/common/editor/untitledEditor.test.ts b/src/vs/workbench/test/common/editor/untitledEditor.test.ts index a4ca3e9ce16..0da7ca4eada 100644 --- a/src/vs/workbench/test/common/editor/untitledEditor.test.ts +++ b/src/vs/workbench/test/common/editor/untitledEditor.test.ts @@ -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'); -- GitLab