diff --git a/src/vs/editor/common/editorCommon.ts b/src/vs/editor/common/editorCommon.ts index 8ba12c929a2..7d1011c4a62 100644 --- a/src/vs/editor/common/editorCommon.ts +++ b/src/vs/editor/common/editorCommon.ts @@ -21,6 +21,7 @@ import { IndentRange } from 'vs/editor/common/model/indentRanges'; import { ICommandHandlerDescription } from 'vs/platform/commands/common/commands'; import { ContextKeyExpr, RawContextKey } from 'vs/platform/contextkey/common/contextkey'; import { FontInfo } from 'vs/editor/common/config/fontInfo'; +import { ITextSource } from 'vs/editor/common/model/textSource'; /** * @internal @@ -2457,37 +2458,6 @@ export interface IModelContentChangedEvent { readonly isRedoing: boolean; } -/** - * The raw text backing a model. - * @internal - */ -export interface ITextSource { - /** - * The entire text length. - */ - readonly length: number; - /** - * The text split into lines. - */ - readonly lines: string[]; - /** - * The BOM (leading character sequence of the file). - */ - readonly BOM: string; - /** - * The end of line sequence. - */ - readonly EOL: string; - /** - * The text contains Unicode characters classified as "R" or "AL". - */ - readonly containsRTL: boolean; - /** - * The text contains only characters inside the ASCII range 32-126 or \t \r \n - */ - readonly isBasicASCII: boolean; -} - /** * The raw text backing a model. * @internal diff --git a/src/vs/editor/common/model/editableTextModel.ts b/src/vs/editor/common/model/editableTextModel.ts index a76c6d6eeae..fcfc4a9a4e1 100644 --- a/src/vs/editor/common/model/editableTextModel.ts +++ b/src/vs/editor/common/model/editableTextModel.ts @@ -14,6 +14,7 @@ import { Selection } from 'vs/editor/common/core/selection'; import { Position } from 'vs/editor/common/core/position'; import { IDisposable } from 'vs/base/common/lifecycle'; import { LanguageIdentifier } from 'vs/editor/common/modes'; +import { ITextSource } from 'vs/editor/common/model/textSource'; export interface IValidatedEditOperation { sortIndex: number; @@ -69,7 +70,7 @@ export class EditableTextModel extends TextModelWithDecorations implements edito super.dispose(); } - protected _resetValue(newValue: editorCommon.ITextSource): void { + protected _resetValue(newValue: ITextSource): void { super._resetValue(newValue); // Destroy my edit history and settings diff --git a/src/vs/editor/common/model/textModel.ts b/src/vs/editor/common/model/textModel.ts index 9c0999e2315..7b0ebf7de54 100644 --- a/src/vs/editor/common/model/textModel.ts +++ b/src/vs/editor/common/model/textModel.ts @@ -15,7 +15,7 @@ import { DEFAULT_INDENTATION, DEFAULT_TRIM_AUTO_WHITESPACE } from 'vs/editor/com import { PrefixSumComputer } from 'vs/editor/common/viewModel/prefixSumComputer'; import { IndentRange, computeRanges } from 'vs/editor/common/model/indentRanges'; import { TextModelSearch, SearchParams } from 'vs/editor/common/model/textModelSearch'; -import { ITextSource2 } from 'vs/editor/common/model/textSource'; +import { ITextSource, RawTextSource, IRawTextSource } from 'vs/editor/common/model/textSource'; const LIMIT_FIND_COUNT = 999; export const LONG_LINE_BOUNDARY = 1000; @@ -286,7 +286,7 @@ export class TextModel extends OrderGuaranteeEventEmitter implements editorCommo } } - protected _resetValue(newValue: editorCommon.ITextSource): void { + protected _resetValue(newValue: ITextSource): void { this._constructLines(newValue); this._increaseVersionId(); } @@ -304,7 +304,7 @@ export class TextModel extends OrderGuaranteeEventEmitter implements editorCommo }; } - public equals(other: editorCommon.ITextSource): boolean { + public equals(other: ITextSource): boolean { this._assertNotDisposed(); if (this._BOM !== other.BOM) { return false; @@ -340,7 +340,7 @@ export class TextModel extends OrderGuaranteeEventEmitter implements editorCommo this.setValueFromRawText(rawText); } - public setValueFromRawText(newValue: editorCommon.ITextSource): void { + public setValueFromRawText(newValue: ITextSource): void { this._assertNotDisposed(); if (newValue === null) { // There's nothing to do @@ -750,43 +750,12 @@ export class TextModel extends OrderGuaranteeEventEmitter implements editorCommo } } - public static toTextSource(rawText: string): ITextSource2 { - // Count the number of lines that end with \r\n - let carriageReturnCnt = 0; - let lastCarriageReturnIndex = -1; - while ((lastCarriageReturnIndex = rawText.indexOf('\r', lastCarriageReturnIndex + 1)) !== -1) { - carriageReturnCnt++; - } - - const containsRTL = strings.containsRTL(rawText); - const isBasicASCII = (containsRTL ? false : strings.isBasicASCII(rawText)); - - // Split the text into lines - const lines = rawText.split(/\r\n|\r|\n/); - - // Remove the BOM (if present) - let BOM = ''; - if (strings.startsWithUTF8BOM(lines[0])) { - BOM = strings.UTF8_BOM_CHARACTER; - lines[0] = lines[0].substr(1); - } - - return { - BOM: BOM, - lines: lines, - length: rawText.length, - containsRTL: containsRTL, - isBasicASCII: isBasicASCII, - totalCRCount: carriageReturnCnt - }; - } - /** * if text source is empty or with precisely one line, returns null. No end of line is detected. * if text source contains more lines ending with '\r\n', returns '\r\n'. * Otherwise returns '\n'. More lines end with '\n'. */ - public static getEndOfLine(textSource: ITextSource2): string { + public static getEndOfLine(textSource: IRawTextSource): string { const lineFeedCnt = textSource.lines.length - 1; if (lineFeedCnt === 0) { // This is an empty file or a file with precisely one line @@ -801,11 +770,11 @@ export class TextModel extends OrderGuaranteeEventEmitter implements editorCommo } public static toRawText(rawText: string, opts: editorCommon.ITextModelCreationOptions): editorCommon.IRawText { - const textSource = TextModel.toTextSource(rawText); + const textSource = RawTextSource.fromString(rawText); return TextModel.toRawTextFromTextSource(textSource, opts); } - public static toRawTextFromTextSource(textSource: ITextSource2, opts: editorCommon.ITextModelCreationOptions): editorCommon.IRawText { + public static toRawTextFromTextSource(textSource: IRawTextSource, opts: editorCommon.ITextModelCreationOptions): editorCommon.IRawText { let EOL = TextModel.getEndOfLine(textSource); if (!EOL) { // This is an empty file or a file with precisely one line @@ -841,7 +810,7 @@ export class TextModel extends OrderGuaranteeEventEmitter implements editorCommo }; } - private _constructLines(rawText: editorCommon.ITextSource): void { + private _constructLines(rawText: ITextSource): void { const tabSize = this._options.tabSize; let rawLines = rawText.lines; let modelLines: ModelLine[] = []; @@ -898,7 +867,7 @@ export class TextModel extends OrderGuaranteeEventEmitter implements editorCommo export class RawText { - public static toRawText(textSourceOrString: ITextSource2 | string, opts: editorCommon.ITextModelCreationOptions): editorCommon.IRawText { + public static toRawText(textSourceOrString: IRawTextSource | string, opts: editorCommon.ITextModelCreationOptions): editorCommon.IRawText { if (typeof textSourceOrString === 'string') { return RawText.fromString(textSourceOrString, opts); } else { @@ -906,7 +875,7 @@ export class RawText { } } - public static toRawTextWithModelOptions(textSourceOrString: ITextSource2 | string, model: editorCommon.IModel): editorCommon.IRawText { + public static toRawTextWithModelOptions(textSourceOrString: IRawTextSource | string, model: editorCommon.IModel): editorCommon.IRawText { if (typeof textSourceOrString === 'string') { return RawText.fromStringWithModelOptions(textSourceOrString, model); } else { @@ -918,7 +887,7 @@ export class RawText { return TextModel.toRawText(rawText, opts); } - public static fromTextSource(textSource: ITextSource2, opts: editorCommon.ITextModelCreationOptions): editorCommon.IRawText { + public static fromTextSource(textSource: IRawTextSource, opts: editorCommon.ITextModelCreationOptions): editorCommon.IRawText { return TextModel.toRawTextFromTextSource(textSource, opts); } @@ -933,7 +902,7 @@ export class RawText { }); } - public static fromTextSourceWithModelOptions(textSource: ITextSource2, model: editorCommon.IModel): editorCommon.IRawText { + public static fromTextSourceWithModelOptions(textSource: IRawTextSource, model: editorCommon.IModel): editorCommon.IRawText { let opts = model.getOptions(); return TextModel.toRawTextFromTextSource(textSource, { tabSize: opts.tabSize, diff --git a/src/vs/editor/common/model/textModelWithDecorations.ts b/src/vs/editor/common/model/textModelWithDecorations.ts index 927068c5065..78e5f597d2b 100644 --- a/src/vs/editor/common/model/textModelWithDecorations.ts +++ b/src/vs/editor/common/model/textModelWithDecorations.ts @@ -14,6 +14,7 @@ import { MarkersTracker, LineMarker } from 'vs/editor/common/model/modelLine'; import { Position } from 'vs/editor/common/core/position'; import { INewMarker, TextModelWithMarkers } from 'vs/editor/common/model/textModelWithMarkers'; import { LanguageIdentifier } from 'vs/editor/common/modes'; +import { ITextSource } from 'vs/editor/common/model/textSource'; class DecorationsTracker { @@ -165,7 +166,7 @@ export class TextModelWithDecorations extends TextModelWithMarkers implements ed super.dispose(); } - protected _resetValue(newValue: editorCommon.ITextSource): void { + protected _resetValue(newValue: ITextSource): void { super._resetValue(newValue); // Destroy all my decorations diff --git a/src/vs/editor/common/model/textModelWithMarkers.ts b/src/vs/editor/common/model/textModelWithMarkers.ts index 939e3fa2eae..0934f650ffa 100644 --- a/src/vs/editor/common/model/textModelWithMarkers.ts +++ b/src/vs/editor/common/model/textModelWithMarkers.ts @@ -6,10 +6,11 @@ import { IdGenerator } from 'vs/base/common/idGenerator'; import { Position } from 'vs/editor/common/core/position'; -import { ITextSource, IRawText, ITextModelWithMarkers } from 'vs/editor/common/editorCommon'; +import { IRawText, ITextModelWithMarkers } from 'vs/editor/common/editorCommon'; import { LineMarker } from 'vs/editor/common/model/modelLine'; import { TextModelWithTokens } from 'vs/editor/common/model/textModelWithTokens'; import { LanguageIdentifier } from 'vs/editor/common/modes'; +import { ITextSource } from 'vs/editor/common/model/textSource'; export interface IMarkerIdToMarkerMap { [key: string]: LineMarker; diff --git a/src/vs/editor/common/model/textModelWithTokens.ts b/src/vs/editor/common/model/textModelWithTokens.ts index da093ecd1ec..63ee6c82976 100644 --- a/src/vs/editor/common/model/textModelWithTokens.ts +++ b/src/vs/editor/common/model/textModelWithTokens.ts @@ -21,6 +21,7 @@ import { LanguageConfigurationRegistry } from 'vs/editor/common/modes/languageCo import { LineTokens, LineToken } from 'vs/editor/common/core/lineTokens'; import { getWordAtText } from 'vs/editor/common/model/wordHelper'; import { TokenizationResult2 } from 'vs/editor/common/core/token'; +import { ITextSource } from 'vs/editor/common/model/textSource'; class ModelTokensChangedEventBuilder { @@ -107,7 +108,7 @@ export class TextModelWithTokens extends TextModel implements editorCommon.IToke return false; } - protected _resetValue(newValue: editorCommon.ITextSource): void { + protected _resetValue(newValue: ITextSource): void { super._resetValue(newValue); // Cancel tokenization, clear all tokens and begin tokenizing this._resetTokenizationState(); diff --git a/src/vs/editor/common/model/textSource.ts b/src/vs/editor/common/model/textSource.ts index 67f11ded3fc..ba6782dc8d4 100644 --- a/src/vs/editor/common/model/textSource.ts +++ b/src/vs/editor/common/model/textSource.ts @@ -4,10 +4,12 @@ *--------------------------------------------------------------------------------------------*/ 'use strict'; +import * as strings from 'vs/base/common/strings'; + /** - * The text source + * A processed string ready to be turned into an editor model. */ -export interface ITextSource2 { +export interface IRawTextSource { /** * The entire text length. */ @@ -33,3 +35,68 @@ export interface ITextSource2 { */ readonly isBasicASCII: boolean; } + +export class RawTextSource { + + public static fromString(rawText: string): IRawTextSource { + // Count the number of lines that end with \r\n + let carriageReturnCnt = 0; + let lastCarriageReturnIndex = -1; + while ((lastCarriageReturnIndex = rawText.indexOf('\r', lastCarriageReturnIndex + 1)) !== -1) { + carriageReturnCnt++; + } + + const containsRTL = strings.containsRTL(rawText); + const isBasicASCII = (containsRTL ? false : strings.isBasicASCII(rawText)); + + // Split the text into lines + const lines = rawText.split(/\r\n|\r|\n/); + + // Remove the BOM (if present) + let BOM = ''; + if (strings.startsWithUTF8BOM(lines[0])) { + BOM = strings.UTF8_BOM_CHARACTER; + lines[0] = lines[0].substr(1); + } + + return { + BOM: BOM, + lines: lines, + length: rawText.length, + containsRTL: containsRTL, + isBasicASCII: isBasicASCII, + totalCRCount: carriageReturnCnt + }; + } + +} + +/** + * A processed string with its EOL resolved ready to be turned into an editor model. + */ +export interface ITextSource { + /** + * The entire text length. + */ + readonly length: number; + /** + * The text split into lines. + */ + readonly lines: string[]; + /** + * The BOM (leading character sequence of the file). + */ + readonly BOM: string; + /** + * The end of line sequence. + */ + readonly EOL: string; + /** + * The text contains Unicode characters classified as "R" or "AL". + */ + readonly containsRTL: boolean; + /** + * The text contains only characters inside the ASCII range 32-126 or \t \r \n + */ + readonly isBasicASCII: boolean; +} diff --git a/src/vs/editor/common/services/modelService.ts b/src/vs/editor/common/services/modelService.ts index ef6cf11f728..e96abb99398 100644 --- a/src/vs/editor/common/services/modelService.ts +++ b/src/vs/editor/common/services/modelService.ts @@ -10,16 +10,16 @@ import { TPromise } from 'vs/base/common/winjs.base'; import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; import { IModel, ITextModelCreationOptions } from 'vs/editor/common/editorCommon'; import { IMode } from 'vs/editor/common/modes'; -import { ITextSource2 } from 'vs/editor/common/model/textSource'; +import { IRawTextSource } from 'vs/editor/common/model/textSource'; export var IModelService = createDecorator('modelService'); export interface IModelService { _serviceBrand: any; - createModel(value: string | ITextSource2, modeOrPromise: TPromise | IMode, resource: URI): IModel; + createModel(value: string | IRawTextSource, modeOrPromise: TPromise | IMode, resource: URI): IModel; - updateModel(model: IModel, value: string | ITextSource2): void; + updateModel(model: IModel, value: string | IRawTextSource): void; setMode(model: IModel, modeOrPromise: TPromise | IMode): void; diff --git a/src/vs/editor/common/services/modelServiceImpl.ts b/src/vs/editor/common/services/modelServiceImpl.ts index fefe8162d06..4e43e55eb9e 100644 --- a/src/vs/editor/common/services/modelServiceImpl.ts +++ b/src/vs/editor/common/services/modelServiceImpl.ts @@ -24,7 +24,7 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur import { DEFAULT_INDENTATION, DEFAULT_TRIM_AUTO_WHITESPACE } from 'vs/editor/common/config/defaultConfig'; import { PLAINTEXT_LANGUAGE_IDENTIFIER } from 'vs/editor/common/modes/modesRegistry'; import { RawText } from 'vs/editor/common/model/textModel'; -import { ITextSource2 } from 'vs/editor/common/model/textSource'; +import { IRawTextSource } from 'vs/editor/common/model/textSource'; function MODEL_ID(resource: URI): string { return resource.toString(); @@ -339,7 +339,7 @@ export class ModelServiceImpl implements IModelService { // --- begin IModelService - private _createModelData(value: string | ITextSource2, languageIdentifier: LanguageIdentifier, resource: URI): ModelData { + private _createModelData(value: string | IRawTextSource, languageIdentifier: LanguageIdentifier, resource: URI): ModelData { // create & save the model const options = this.getCreationOptions(languageIdentifier.language); @@ -358,7 +358,7 @@ export class ModelServiceImpl implements IModelService { return modelData; } - public updateModel(model: editorCommon.IModel, value: string | ITextSource2): void { + public updateModel(model: editorCommon.IModel, value: string | IRawTextSource): void { let options = this.getCreationOptions(model.getLanguageIdentifier().language); let rawText: editorCommon.IRawText = RawText.toRawText(value, options); @@ -371,7 +371,7 @@ export class ModelServiceImpl implements IModelService { model.setValueFromRawText(rawText); } - public createModel(value: string | ITextSource2, modeOrPromise: TPromise | IMode, resource: URI): editorCommon.IModel { + public createModel(value: string | IRawTextSource, modeOrPromise: TPromise | IMode, resource: URI): editorCommon.IModel { let modelData: ModelData; if (!modeOrPromise || TPromise.is(modeOrPromise)) { diff --git a/src/vs/editor/node/model/modelBuilder.ts b/src/vs/editor/node/model/modelBuilder.ts index 609cb5941b4..77417f82d44 100644 --- a/src/vs/editor/node/model/modelBuilder.ts +++ b/src/vs/editor/node/model/modelBuilder.ts @@ -9,11 +9,11 @@ import * as crypto from 'crypto'; import * as strings from 'vs/base/common/strings'; import { TPromise } from 'vs/base/common/winjs.base'; import { CharCode } from 'vs/base/common/charCode'; -import { ITextSource2 } from 'vs/editor/common/model/textSource'; +import { IRawTextSource } from 'vs/editor/common/model/textSource'; export interface ModelBuilderResult { readonly hash: string; - readonly value: ITextSource2; + readonly value: IRawTextSource; } class ModelLineBasedBuilder { @@ -60,7 +60,7 @@ class ModelLineBasedBuilder { } } -export function computeHash(rawText: ITextSource2): string { +export function computeHash(rawText: IRawTextSource): string { let hash = crypto.createHash('sha1'); for (let i = 0, len = rawText.lines.length; i < len; i++) { hash.update(rawText.lines[i] + '\n'); diff --git a/src/vs/editor/test/node/model/modelBuilder.test.ts b/src/vs/editor/test/node/model/modelBuilder.test.ts index 2b654347079..1914887e04b 100644 --- a/src/vs/editor/test/node/model/modelBuilder.test.ts +++ b/src/vs/editor/test/node/model/modelBuilder.test.ts @@ -9,10 +9,10 @@ import { ModelBuilder, computeHash } from 'vs/editor/node/model/modelBuilder'; import { ITextModelCreationOptions } from 'vs/editor/common/editorCommon'; import { TextModel } from 'vs/editor/common/model/textModel'; import * as strings from 'vs/base/common/strings'; -import { ITextSource2 } from 'vs/editor/common/model/textSource'; +import { RawTextSource, IRawTextSource } from 'vs/editor/common/model/textSource'; export function testModelBuilder(chunks: string[], opts: ITextModelCreationOptions = TextModel.DEFAULT_CREATION_OPTIONS): string { - let expectedTextSource = TextModel.toTextSource(chunks.join('')); + let expectedTextSource = RawTextSource.fromString(chunks.join('')); let expectedHash = computeHash(expectedTextSource); let builder = new ModelBuilder(); @@ -30,7 +30,7 @@ export function testModelBuilder(chunks: string[], opts: ITextModelCreationOptio return expectedHash; } -function toTextSource(lines: string[]): ITextSource2 { +function toTextSource(lines: string[]): IRawTextSource { return { BOM: '', lines: lines, diff --git a/src/vs/workbench/api/node/extHost.protocol.ts b/src/vs/workbench/api/node/extHost.protocol.ts index 78b85143f77..f0fdb9bdfb0 100644 --- a/src/vs/workbench/api/node/extHost.protocol.ts +++ b/src/vs/workbench/api/node/extHost.protocol.ts @@ -27,6 +27,7 @@ import { IWorkspace } from 'vs/platform/workspace/common/workspace'; import * as editorCommon from 'vs/editor/common/editorCommon'; import * as modes from 'vs/editor/common/modes'; import { IResourceEdit } from 'vs/editor/common/services/bulkEdit'; +import { ITextSource } from 'vs/editor/common/model/textSource'; import { ConfigurationTarget } from 'vs/workbench/services/configuration/common/configurationEditing'; import { IWorkspaceConfigurationValues } from 'vs/workbench/services/configuration/common/configuration'; @@ -122,7 +123,7 @@ export abstract class MainThreadDocumentsShape { $tryCreateDocument(options?: { language: string; }): TPromise { throw ni(); } $tryOpenDocument(uri: URI): TPromise { throw ni(); } $registerTextContentProvider(handle: number, scheme: string): void { throw ni(); } - $onVirtualDocumentChange(uri: URI, value: editorCommon.ITextSource): void { throw ni(); } + $onVirtualDocumentChange(uri: URI, value: ITextSource): void { throw ni(); } $unregisterTextContentProvider(handle: number): void { throw ni(); } $trySaveDocument(uri: URI): TPromise { throw ni(); } } diff --git a/src/vs/workbench/api/node/extHostDocuments.ts b/src/vs/workbench/api/node/extHostDocuments.ts index 5ceea146fc5..3531ef3f3ab 100644 --- a/src/vs/workbench/api/node/extHostDocuments.ts +++ b/src/vs/workbench/api/node/extHostDocuments.ts @@ -20,6 +20,7 @@ import * as vscode from 'vscode'; import { asWinJsPromise } from 'vs/base/common/async'; import { getWordAtText, ensureValidWordDefinition } from 'vs/editor/common/model/wordHelper'; import { MainContext, MainThreadDocumentsShape, ExtHostDocumentsShape, IModelAddedData } from './extHost.protocol'; +import { ITextSource } from 'vs/editor/common/model/textSource'; const _modeId2WordDefinition = new Map(); @@ -263,7 +264,7 @@ export class ExtHostDocumentData extends MirrorModel2 { super.dispose(); } - equalLines({lines}: editorCommon.ITextSource): boolean { + equalLines({lines}: ITextSource): boolean { const len = lines.length; if (len !== this._lines.length) { return false; diff --git a/src/vs/workbench/api/node/mainThreadDocuments.ts b/src/vs/workbench/api/node/mainThreadDocuments.ts index 09af6f6293b..946dc3f5556 100644 --- a/src/vs/workbench/api/node/mainThreadDocuments.ts +++ b/src/vs/workbench/api/node/mainThreadDocuments.ts @@ -19,6 +19,7 @@ import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/un import { ExtHostContext, MainThreadDocumentsShape, ExtHostDocumentsShape } from './extHost.protocol'; import { ITextModelResolverService } from 'vs/editor/common/services/resolverService'; import { ICodeEditorService } from 'vs/editor/common/services/codeEditorService'; +import { ITextSource } from 'vs/editor/common/model/textSource'; export class MainThreadDocuments extends MainThreadDocumentsShape { private _modelService: IModelService; @@ -241,12 +242,12 @@ export class MainThreadDocuments extends MainThreadDocumentsShape { } } - $onVirtualDocumentChange(uri: URI, value: editorCommon.ITextSource): void { + $onVirtualDocumentChange(uri: URI, value: ITextSource): void { const model = this._modelService.getModel(uri); if (!model) { return; } - const raw: editorCommon.ITextSource = { + const raw: ITextSource = { lines: value.lines, length: value.length, BOM: value.BOM, diff --git a/src/vs/workbench/common/editor/textEditorModel.ts b/src/vs/workbench/common/editor/textEditorModel.ts index ec63d115ab7..37c60e19f44 100644 --- a/src/vs/workbench/common/editor/textEditorModel.ts +++ b/src/vs/workbench/common/editor/textEditorModel.ts @@ -13,7 +13,7 @@ import { ITextEditorModel } from 'vs/editor/common/services/resolverService'; import { IModeService } from 'vs/editor/common/services/modeService'; import { IModelService } from 'vs/editor/common/services/modelService'; import { IDisposable } from 'vs/base/common/lifecycle'; -import { ITextSource2 } from 'vs/editor/common/model/textSource'; +import { IRawTextSource } from 'vs/editor/common/model/textSource'; /** * The base text editor model leverages the code editor model. This class is only intended to be subclassed and not instantiated. @@ -67,7 +67,7 @@ export abstract class BaseTextEditorModel extends EditorModel implements ITextEd /** * Creates the text editor model with the provided value, modeId (can be comma separated for multiple values) and optional resource URL. */ - protected createTextEditorModel(value: string | ITextSource2, resource?: URI, modeId?: string): TPromise { + protected createTextEditorModel(value: string | IRawTextSource, resource?: URI, modeId?: string): TPromise { const firstLineText = this.getFirstLineText(value); const mode = this.getOrCreateMode(this.modeService, modeId, firstLineText); @@ -77,7 +77,7 @@ export abstract class BaseTextEditorModel extends EditorModel implements ITextEd }); } - private doCreateTextEditorModel(value: string | ITextSource2, mode: TPromise, resource: URI): EditorModel { + private doCreateTextEditorModel(value: string | IRawTextSource, mode: TPromise, resource: URI): EditorModel { let model = resource && this.modelService.getModel(resource); if (!model) { model = this.modelService.createModel(value, mode, resource); @@ -95,7 +95,7 @@ export abstract class BaseTextEditorModel extends EditorModel implements ITextEd return this; } - protected getFirstLineText(value: string | ITextSource2): string { + protected getFirstLineText(value: string | IRawTextSource): string { if (typeof value === 'string') { const firstLineText = value.substr(0, 100); @@ -127,7 +127,7 @@ export abstract class BaseTextEditorModel extends EditorModel implements ITextEd /** * Updates the text editor model with the provided value. If the value is the same as the model has, this is a no-op. */ - protected updateTextEditorModel(newValue: string | ITextSource2): void { + protected updateTextEditorModel(newValue: string | IRawTextSource): void { if (!this.textEditorModel) { return; } diff --git a/src/vs/workbench/parts/welcome/walkThrough/node/walkThroughContentProvider.ts b/src/vs/workbench/parts/welcome/walkThrough/node/walkThroughContentProvider.ts index c4f20dd7580..426918e274c 100644 --- a/src/vs/workbench/parts/welcome/walkThrough/node/walkThroughContentProvider.ts +++ b/src/vs/workbench/parts/welcome/walkThrough/node/walkThroughContentProvider.ts @@ -15,7 +15,7 @@ import { IModeService } from 'vs/editor/common/services/modeService'; import { IWorkbenchContribution } from 'vs/workbench/common/contributions'; import { marked } from 'vs/base/common/marked/marked'; import { Schemas } from 'vs/base/common/network'; -import { ITextSource2 } from 'vs/editor/common/model/textSource'; +import { IRawTextSource } from 'vs/editor/common/model/textSource'; export class WalkThroughContentProvider implements ITextModelContentProvider, IWorkbenchContribution { @@ -30,7 +30,7 @@ export class WalkThroughContentProvider implements ITextModelContentProvider, IW public provideTextContent(resource: URI): TPromise { const query = resource.query ? JSON.parse(resource.query) : {}; - const content: TPromise = (query.moduleId ? new TPromise((resolve, reject) => { + const content: TPromise = (query.moduleId ? new TPromise((resolve, reject) => { require([query.moduleId], content => { try { resolve(content.default()); diff --git a/src/vs/workbench/services/backup/common/backup.ts b/src/vs/workbench/services/backup/common/backup.ts index 7e8bb953ae9..f725e450087 100644 --- a/src/vs/workbench/services/backup/common/backup.ts +++ b/src/vs/workbench/services/backup/common/backup.ts @@ -9,7 +9,7 @@ import Uri from 'vs/base/common/uri'; import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; import { TPromise } from 'vs/base/common/winjs.base'; import { IResolveContentOptions, IUpdateContentOptions } from 'vs/platform/files/common/files'; -import { ITextSource2 } from 'vs/editor/common/model/textSource'; +import { IRawTextSource } from 'vs/editor/common/model/textSource'; export const IBackupFileService = createDecorator('backupFileService'); @@ -58,7 +58,7 @@ export interface IBackupFileService { * @param rawText The IRawTextProvider from a backup resource. * @return The backup file's backed up content. */ - parseBackupContent(textSource: ITextSource2): string; + parseBackupContent(textSource: IRawTextSource): string; /** * Discards the backup associated with a resource if it exists.. diff --git a/src/vs/workbench/services/backup/node/backupFileService.ts b/src/vs/workbench/services/backup/node/backupFileService.ts index ff27824d723..51e3feaa698 100644 --- a/src/vs/workbench/services/backup/node/backupFileService.ts +++ b/src/vs/workbench/services/backup/node/backupFileService.ts @@ -19,7 +19,7 @@ import { TPromise } from 'vs/base/common/winjs.base'; import { readToMatchingString } from 'vs/base/node/stream'; import { TextModel } from 'vs/editor/common/model/textModel'; import { IWindowService } from 'vs/platform/windows/common/windows'; -import { ITextSource2 } from 'vs/editor/common/model/textSource'; +import { IRawTextSource } from 'vs/editor/common/model/textSource'; export interface IBackupFilesModel { resolve(backupRoot: string): TPromise; @@ -239,7 +239,7 @@ export class BackupFileService implements IBackupFileService { }); } - public parseBackupContent(textSource: ITextSource2): string { + public parseBackupContent(textSource: IRawTextSource): string { return textSource.lines.slice(1).join(TextModel.getEndOfLine(textSource) || ''); // The first line of a backup text file is the file name } diff --git a/src/vs/workbench/services/backup/test/backupFileService.test.ts b/src/vs/workbench/services/backup/test/backupFileService.test.ts index 5e1c408741e..5bf8ba31b4f 100644 --- a/src/vs/workbench/services/backup/test/backupFileService.test.ts +++ b/src/vs/workbench/services/backup/test/backupFileService.test.ts @@ -19,9 +19,9 @@ import { FileService } from 'vs/workbench/services/files/node/fileService'; import { EnvironmentService } from 'vs/platform/environment/node/environmentService'; import { IBackupService } from 'vs/platform/backup/common/backup'; import { parseArgs } from 'vs/platform/environment/node/argv'; -import { TextModel } from 'vs/editor/common/model/textModel'; import { TPromise } from 'vs/base/common/winjs.base'; import { TestWindowService } from 'vs/workbench/test/workbenchTestServices'; +import { RawTextSource } from 'vs/editor/common/model/textSource'; class TestEnvironmentService extends EnvironmentService { @@ -252,7 +252,7 @@ suite('BackupFileService', () => { test('parseBackupContent', () => { test('should separate metadata from content', () => { - const textSource = TextModel.toTextSource('metadata\ncontent'); + const textSource = RawTextSource.fromString('metadata\ncontent'); assert.equal(service.parseBackupContent(textSource), 'content'); }); }); diff --git a/src/vs/workbench/services/textfile/common/textFileEditorModel.ts b/src/vs/workbench/services/textfile/common/textFileEditorModel.ts index f18d6b18bde..3a3addbb418 100644 --- a/src/vs/workbench/services/textfile/common/textFileEditorModel.ts +++ b/src/vs/workbench/services/textfile/common/textFileEditorModel.ts @@ -31,7 +31,7 @@ import { IModelService } from 'vs/editor/common/services/modelService'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { anonymize } from 'vs/platform/telemetry/common/telemetryUtils'; import { RunOnceScheduler } from 'vs/base/common/async'; -import { ITextSource2 } from 'vs/editor/common/model/textSource'; +import { IRawTextSource } from 'vs/editor/common/model/textSource'; /** * The text file editor model listens to changes to its underlying code editor model and saves these changes through the file service back to the disk. @@ -356,7 +356,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil return this.doCreateTextModel(content.resource, content.value, backup); } - private doUpdateTextModel(value: string | ITextSource2): TPromise { + private doUpdateTextModel(value: string | IRawTextSource): TPromise { diag('load() - updated text editor model', this.resource, new Date()); this.setDirty(false); // Ensure we are not tracking a stale state @@ -371,7 +371,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil return TPromise.as(this); } - private doCreateTextModel(resource: URI, value: string | ITextSource2, backup: URI): TPromise { + private doCreateTextModel(resource: URI, value: string | IRawTextSource, backup: URI): TPromise { diag('load() - created text editor model', this.resource, new Date()); this.createTextEditorModelPromise = this.doLoadBackup(backup).then(backupContent => { diff --git a/src/vs/workbench/services/textfile/common/textfiles.ts b/src/vs/workbench/services/textfile/common/textfiles.ts index e8dd79a3583..eb3b1a1b1c9 100644 --- a/src/vs/workbench/services/textfile/common/textfiles.ts +++ b/src/vs/workbench/services/textfile/common/textfiles.ts @@ -12,7 +12,7 @@ import { IEncodingSupport, ConfirmResult } from 'vs/workbench/common/editor'; import { IBaseStat, IResolveContentOptions } from 'vs/platform/files/common/files'; import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; import { ITextEditorModel } from 'vs/editor/common/services/resolverService'; -import { ITextSource2 } from 'vs/editor/common/model/textSource'; +import { IRawTextSource } from 'vs/editor/common/model/textSource'; /** * The save error handler can be installed on the text text file editor model to install code that executes when save errors occur. @@ -112,7 +112,7 @@ export interface IRawTextContent extends IBaseStat { /** * The line grouped content of a text file. */ - value: ITextSource2; + value: IRawTextSource; /** * The line grouped logical hash of a text file. diff --git a/src/vs/workbench/test/workbenchTestServices.ts b/src/vs/workbench/test/workbenchTestServices.ts index 9604d326982..9276d24beec 100644 --- a/src/vs/workbench/test/workbenchTestServices.ts +++ b/src/vs/workbench/test/workbenchTestServices.ts @@ -39,7 +39,6 @@ import { IModelService } from 'vs/editor/common/services/modelService'; import { ModeServiceImpl } from 'vs/editor/common/services/modeServiceImpl'; import { ModelServiceImpl } from 'vs/editor/common/services/modelServiceImpl'; import { IRawTextContent, ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; -import { TextModel } from 'vs/editor/common/model/textModel'; import { parseArgs } from 'vs/platform/environment/node/argv'; import { EnvironmentService } from 'vs/platform/environment/node/environmentService'; import { IModeService } from 'vs/editor/common/services/modeService'; @@ -49,7 +48,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService'; import { IWindowsService, IWindowService } from 'vs/platform/windows/common/windows'; import { TestWorkspace } from 'vs/platform/workspace/test/common/testWorkspace'; -import { ITextSource2 } from 'vs/editor/common/model/textSource'; +import { RawTextSource, IRawTextSource } from 'vs/editor/common/model/textSource'; export function createFileInput(instantiationService: IInstantiationService, resource: URI): FileEditorInput { return instantiationService.createInstance(FileEditorInput, resource, void 0); @@ -150,7 +149,7 @@ export class TestTextFileService extends TextFileService { } return this.fileService.resolveContent(resource, options).then((content) => { - const textSource = TextModel.toTextSource(content.value); + const textSource = RawTextSource.fromString(content.value); return { resource: content.resource, name: content.name, @@ -733,7 +732,7 @@ export class TestBackupFileService implements IBackupFileService { return TPromise.as([]); } - public parseBackupContent(rawText: ITextSource2): string { + public parseBackupContent(rawText: IRawTextSource): string { return rawText.lines.join('\n'); }