提交 668dc067 编写于 作者: A Alex Dima

Extract more code to textSource.ts

上级 220a10c2
......@@ -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
......
......@@ -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
......
......@@ -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,
......
......@@ -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
......
......@@ -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;
......
......@@ -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();
......
......@@ -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;
}
......@@ -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<IModelService>('modelService');
export interface IModelService {
_serviceBrand: any;
createModel(value: string | ITextSource2, modeOrPromise: TPromise<IMode> | IMode, resource: URI): IModel;
createModel(value: string | IRawTextSource, modeOrPromise: TPromise<IMode> | IMode, resource: URI): IModel;
updateModel(model: IModel, value: string | ITextSource2): void;
updateModel(model: IModel, value: string | IRawTextSource): void;
setMode(model: IModel, modeOrPromise: TPromise<IMode> | IMode): void;
......
......@@ -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> | IMode, resource: URI): editorCommon.IModel {
public createModel(value: string | IRawTextSource, modeOrPromise: TPromise<IMode> | IMode, resource: URI): editorCommon.IModel {
let modelData: ModelData;
if (!modeOrPromise || TPromise.is(modeOrPromise)) {
......
......@@ -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');
......
......@@ -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,
......
......@@ -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<any> { throw ni(); }
$tryOpenDocument(uri: URI): TPromise<any> { 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<boolean> { throw ni(); }
}
......
......@@ -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<string, RegExp>();
......@@ -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;
......
......@@ -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,
......
......@@ -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<EditorModel> {
protected createTextEditorModel(value: string | IRawTextSource, resource?: URI, modeId?: string): TPromise<EditorModel> {
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<IMode>, resource: URI): EditorModel {
private doCreateTextEditorModel(value: string | IRawTextSource, mode: TPromise<IMode>, 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;
}
......
......@@ -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<IModel> {
const query = resource.query ? JSON.parse(resource.query) : {};
const content: TPromise<string | ITextSource2> = (query.moduleId ? new TPromise<string>((resolve, reject) => {
const content: TPromise<string | IRawTextSource> = (query.moduleId ? new TPromise<string>((resolve, reject) => {
require([query.moduleId], content => {
try {
resolve(content.default());
......
......@@ -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<IBackupFileService>('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..
......
......@@ -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<IBackupFilesModel>;
......@@ -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
}
......
......@@ -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');
});
});
......
......@@ -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<EditorModel> {
private doUpdateTextModel(value: string | IRawTextSource): TPromise<EditorModel> {
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<EditorModel>(this);
}
private doCreateTextModel(resource: URI, value: string | ITextSource2, backup: URI): TPromise<EditorModel> {
private doCreateTextModel(resource: URI, value: string | IRawTextSource, backup: URI): TPromise<EditorModel> {
diag('load() - created text editor model', this.resource, new Date());
this.createTextEditorModelPromise = this.doLoadBackup(backup).then(backupContent => {
......
......@@ -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.
......
......@@ -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 <IRawTextContent>{
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');
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册