提交 493c5a1c 编写于 作者: A Alex Dima

Simplify model creation args

上级 ba1f8868
......@@ -14,7 +14,8 @@ 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 { ITextModelData, ITextSource } from 'vs/editor/common/model/textSource';
import { ITextSource, IRawTextSource, RawTextSource } from 'vs/editor/common/model/textSource';
import { TextModel } from 'vs/editor/common/model/textModel';
export interface IValidatedEditOperation {
sortIndex: number;
......@@ -32,6 +33,10 @@ interface IIdentifiedLineEdit extends ILineEdit {
export class EditableTextModel extends TextModelWithDecorations implements editorCommon.IEditableTextModel {
public static createFromString(text: string, options: editorCommon.ITextModelCreationOptions = TextModel.DEFAULT_CREATION_OPTIONS, languageIdentifier: LanguageIdentifier = null): EditableTextModel {
return new EditableTextModel([], RawTextSource.fromString(text), options, languageIdentifier);
}
public onDidChangeRawContent(listener: (e: editorCommon.IModelContentChangedEvent) => void): IDisposable {
return this.addListener2(editorCommon.EventType.ModelRawContentChanged, listener);
}
......@@ -51,9 +56,9 @@ export class EditableTextModel extends TextModelWithDecorations implements edito
private _trimAutoWhitespaceLines: number[];
constructor(allowedEventTypes: string[], textModelData: ITextModelData, languageIdentifier: LanguageIdentifier) {
constructor(allowedEventTypes: string[], rawTextSource: IRawTextSource, creationOptions: editorCommon.ITextModelCreationOptions, languageIdentifier: LanguageIdentifier) {
allowedEventTypes.push(editorCommon.EventType.ModelRawContentChanged);
super(allowedEventTypes, textModelData, languageIdentifier);
super(allowedEventTypes, rawTextSource, creationOptions, languageIdentifier);
this._commandManager = new EditStack(this);
......
......@@ -14,7 +14,7 @@ import { TextModel } from 'vs/editor/common/model/textModel';
import { IDisposable } from 'vs/base/common/lifecycle';
import { BulkListenerCallback } from 'vs/base/common/eventEmitter';
import { LanguageIdentifier } from 'vs/editor/common/modes';
import { ITextModelData, TextModelData } from 'vs/editor/common/model/textSource';
import { IRawTextSource, RawTextSource } from 'vs/editor/common/model/textSource';
// The hierarchy is:
// Model -> EditableTextModel -> TextModelWithDecorations -> TextModelWithTrackedRanges -> TextModelWithMarkers -> TextModelWithTokens -> TextModel
......@@ -41,7 +41,7 @@ export class Model extends EditableTextModel implements IModel {
}
public static createFromString(text: string, options: ITextModelCreationOptions = TextModel.DEFAULT_CREATION_OPTIONS, languageIdentifier: LanguageIdentifier = null, uri: URI = null): Model {
return new Model(TextModelData.fromString(text, options), languageIdentifier, uri);
return new Model(RawTextSource.fromString(text), options, languageIdentifier, uri);
}
public readonly id: string;
......@@ -49,8 +49,8 @@ export class Model extends EditableTextModel implements IModel {
private readonly _associatedResource: URI;
private _attachedEditorCount: number;
constructor(textModelData: ITextModelData, languageIdentifier: LanguageIdentifier, associatedResource: URI = null) {
super([EventType.ModelDispose], textModelData, languageIdentifier);
constructor(rawTextSource: IRawTextSource, creationOptions: ITextModelCreationOptions, languageIdentifier: LanguageIdentifier, associatedResource: URI = null) {
super([EventType.ModelDispose], rawTextSource, creationOptions, languageIdentifier);
// Generate a new unique model id
MODEL_ID++;
......
......@@ -15,11 +15,16 @@ 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 { ITextModelData, TextSource, ITextSource } from 'vs/editor/common/model/textSource';
import { TextSource, ITextSource, IRawTextSource, RawTextSource } from 'vs/editor/common/model/textSource';
const LIMIT_FIND_COUNT = 999;
export const LONG_LINE_BOUNDARY = 1000;
export interface ITextModelCreationData {
readonly text: ITextSource;
readonly options: editorCommon.TextModelResolvedOptions;
}
export class TextModel extends OrderGuaranteeEventEmitter implements editorCommon.ITextModel {
private static MODEL_SYNC_LIMIT = 5 * 1024 * 1024; // 5 MB
private static MODEL_TOKENIZATION_LIMIT = 20 * 1024 * 1024; // 20 MB
......@@ -32,6 +37,37 @@ export class TextModel extends OrderGuaranteeEventEmitter implements editorCommo
trimAutoWhitespace: DEFAULT_TRIM_AUTO_WHITESPACE,
};
public static createFromString(text: string, options: editorCommon.ITextModelCreationOptions = TextModel.DEFAULT_CREATION_OPTIONS): TextModel {
return new TextModel([], RawTextSource.fromString(text), options);
}
public static resolveCreationData(rawTextSource: IRawTextSource, options: editorCommon.ITextModelCreationOptions): ITextModelCreationData {
const textSource = TextSource.fromRawTextSource(rawTextSource, options.defaultEOL);
let resolvedOpts: editorCommon.TextModelResolvedOptions;
if (options.detectIndentation) {
const guessedIndentation = guessIndentation(textSource.lines, options.tabSize, options.insertSpaces);
resolvedOpts = new editorCommon.TextModelResolvedOptions({
tabSize: guessedIndentation.tabSize,
insertSpaces: guessedIndentation.insertSpaces,
trimAutoWhitespace: options.trimAutoWhitespace,
defaultEOL: options.defaultEOL
});
} else {
resolvedOpts = new editorCommon.TextModelResolvedOptions({
tabSize: options.tabSize,
insertSpaces: options.insertSpaces,
trimAutoWhitespace: options.trimAutoWhitespace,
defaultEOL: options.defaultEOL
});
}
return {
text: textSource,
options: resolvedOpts
};
}
/*protected*/ _lines: ModelLine[];
protected _EOL: string;
protected _isDisposed: boolean;
......@@ -52,10 +88,12 @@ export class TextModel extends OrderGuaranteeEventEmitter implements editorCommo
private _shouldSimplifyMode: boolean;
private _shouldDenyMode: boolean;
constructor(allowedEventTypes: string[], textModelData: ITextModelData) {
constructor(allowedEventTypes: string[], rawTextSource: IRawTextSource, creationOptions: editorCommon.ITextModelCreationOptions) {
allowedEventTypes.push(editorCommon.EventType.ModelRawContentChanged, editorCommon.EventType.ModelOptionsChanged, editorCommon.EventType.ModelContentChanged2);
super(allowedEventTypes);
const textModelData = TextModel.resolveCreationData(rawTextSource, creationOptions);
this._shouldSimplifyMode = (textModelData.text.length > TextModel.MODEL_SYNC_LIMIT);
this._shouldDenyMode = (textModelData.text.length > TextModel.MODEL_TOKENIZATION_LIMIT);
......
......@@ -14,7 +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 { ITextModelData, ITextSource } from 'vs/editor/common/model/textSource';
import { ITextSource, IRawTextSource } from 'vs/editor/common/model/textSource';
class DecorationsTracker {
......@@ -140,9 +140,9 @@ export class TextModelWithDecorations extends TextModelWithMarkers implements ed
private _internalDecorations: { [internalDecorationId: number]: InternalDecoration; };
private _multiLineDecorationsMap: { [key: string]: InternalDecoration; };
constructor(allowedEventTypes: string[], textModelData: ITextModelData, languageIdentifier: LanguageIdentifier) {
constructor(allowedEventTypes: string[], rawTextSource: IRawTextSource, creationOptions: editorCommon.ITextModelCreationOptions, languageIdentifier: LanguageIdentifier) {
allowedEventTypes.push(editorCommon.EventType.ModelDecorationsChanged);
super(allowedEventTypes, textModelData, languageIdentifier);
super(allowedEventTypes, rawTextSource, creationOptions, languageIdentifier);
this._instanceId = nextInstanceId();
this._lastDecorationId = 0;
......
......@@ -6,11 +6,11 @@
import { IdGenerator } from 'vs/base/common/idGenerator';
import { Position } from 'vs/editor/common/core/position';
import { ITextModelWithMarkers } from 'vs/editor/common/editorCommon';
import { ITextModelWithMarkers, ITextModelCreationOptions } 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 { ITextModelData, ITextSource } from 'vs/editor/common/model/textSource';
import { ITextSource, IRawTextSource } from 'vs/editor/common/model/textSource';
export interface IMarkerIdToMarkerMap {
[key: string]: LineMarker;
......@@ -29,8 +29,8 @@ export class TextModelWithMarkers extends TextModelWithTokens implements ITextMo
private _markerIdGenerator: IdGenerator;
protected _markerIdToMarker: IMarkerIdToMarkerMap;
constructor(allowedEventTypes: string[], textModelData: ITextModelData, languageIdentifier: LanguageIdentifier) {
super(allowedEventTypes, textModelData, languageIdentifier);
constructor(allowedEventTypes: string[], rawTextSource: IRawTextSource, creationOptions: ITextModelCreationOptions, languageIdentifier: LanguageIdentifier) {
super(allowedEventTypes, rawTextSource, creationOptions, languageIdentifier);
this._markerIdGenerator = new IdGenerator((++_INSTANCE_COUNT) + ';');
this._markerIdToMarker = Object.create(null);
}
......
......@@ -21,7 +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 { ITextModelData, ITextSource } from 'vs/editor/common/model/textSource';
import { ITextSource, IRawTextSource } from 'vs/editor/common/model/textSource';
class ModelTokensChangedEventBuilder {
......@@ -71,10 +71,10 @@ export class TextModelWithTokens extends TextModel implements editorCommon.IToke
private _revalidateTokensTimeout: number;
constructor(allowedEventTypes: string[], textModelData: ITextModelData, languageIdentifier: LanguageIdentifier) {
constructor(allowedEventTypes: string[], rawTextSource: IRawTextSource, creationOptions: editorCommon.ITextModelCreationOptions, languageIdentifier: LanguageIdentifier) {
allowedEventTypes.push(editorCommon.EventType.ModelTokensChanged);
allowedEventTypes.push(editorCommon.EventType.ModelLanguageChanged);
super(allowedEventTypes, textModelData);
super(allowedEventTypes, rawTextSource, creationOptions);
this._languageIdentifier = languageIdentifier || NULL_LANGUAGE_IDENTIFIER;
this._tokenizationListener = TokenizationRegistry.onDidChange((e) => {
......
......@@ -5,8 +5,7 @@
'use strict';
import * as strings from 'vs/base/common/strings';
import { DefaultEndOfLine, ITextModelCreationOptions, TextModelResolvedOptions } from 'vs/editor/common/editorCommon';
import { guessIndentation } from 'vs/editor/common/model/indentationGuesser';
import { DefaultEndOfLine } from 'vs/editor/common/editorCommon';
/**
* A processed string ready to be turned into an editor model.
......@@ -148,59 +147,3 @@ export class TextSource {
}
}
export interface ITextModelData {
readonly text: ITextSource;
readonly options: {
readonly tabSize: number;
readonly insertSpaces: boolean;
readonly defaultEOL: DefaultEndOfLine;
readonly trimAutoWhitespace: boolean;
};
}
export class TextModelData {
private static _fromTextSource(textSource: ITextSource, opts: ITextModelCreationOptions): ITextModelData {
let resolvedOpts: TextModelResolvedOptions;
if (opts.detectIndentation) {
const guessedIndentation = guessIndentation(textSource.lines, opts.tabSize, opts.insertSpaces);
resolvedOpts = new TextModelResolvedOptions({
tabSize: guessedIndentation.tabSize,
insertSpaces: guessedIndentation.insertSpaces,
trimAutoWhitespace: opts.trimAutoWhitespace,
defaultEOL: opts.defaultEOL
});
} else {
resolvedOpts = new TextModelResolvedOptions({
tabSize: opts.tabSize,
insertSpaces: opts.insertSpaces,
trimAutoWhitespace: opts.trimAutoWhitespace,
defaultEOL: opts.defaultEOL
});
}
return {
text: textSource,
options: resolvedOpts
};
}
public static fromRawTextSource(rawTextSource: IRawTextSource, opts: ITextModelCreationOptions): ITextModelData {
const textSource = TextSource.fromRawTextSource(rawTextSource, opts.defaultEOL);
return this._fromTextSource(textSource, opts);
}
public static fromString(text: string, opts: ITextModelCreationOptions): ITextModelData {
const textSource = TextSource.fromString(text, opts.defaultEOL);
return this._fromTextSource(textSource, opts);
}
public static create(source: string | IRawTextSource, opts: ITextModelCreationOptions): ITextModelData {
if (typeof source === 'string') {
return this.fromString(source, opts);
}
return this.fromRawTextSource(source, opts);
}
}
......@@ -23,7 +23,7 @@ import * as platform from 'vs/base/common/platform';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { DEFAULT_INDENTATION, DEFAULT_TRIM_AUTO_WHITESPACE } from 'vs/editor/common/config/defaultConfig';
import { PLAINTEXT_LANGUAGE_IDENTIFIER } from 'vs/editor/common/modes/modesRegistry';
import { IRawTextSource, TextModelData, TextSource } from 'vs/editor/common/model/textSource';
import { IRawTextSource, TextSource, RawTextSource } from 'vs/editor/common/model/textSource';
function MODEL_ID(resource: URI): string {
return resource.toString();
......@@ -341,7 +341,8 @@ export class ModelServiceImpl implements IModelService {
private _createModelData(value: string | IRawTextSource, languageIdentifier: LanguageIdentifier, resource: URI): ModelData {
// create & save the model
const options = this.getCreationOptions(languageIdentifier.language);
let model: Model = new Model(TextModelData.create(value, options), languageIdentifier, resource);
const rawTextSource = (typeof value === 'string' ? RawTextSource.fromString(value) : value);
let model: Model = new Model(rawTextSource, options, languageIdentifier, resource);
let modelId = MODEL_ID(model.uri);
if (this._models[modelId]) {
......
......@@ -9,12 +9,11 @@ import * as assert from 'assert';
import { SmartSnippetInserter } from 'vs/editor/contrib/defineKeybinding/common/smartSnippetInserter';
import { TextModel } from 'vs/editor/common/model/textModel';
import { Position } from 'vs/editor/common/core/position';
import { TextModelData } from 'vs/editor/common/model/textSource';
suite('SmartSnippetInserter', () => {
function testSmartSnippetInserter(text: string[], runner: (assert: (desiredPos: Position, pos: Position, prepend: string, append: string) => void) => void): void {
let model = new TextModel([], TextModelData.fromString(text.join('\n'), TextModel.DEFAULT_CREATION_OPTIONS));
let model = TextModel.createFromString(text.join('\n'));
runner((desiredPos, pos, prepend, append) => {
let actual = SmartSnippetInserter.insertSnippet(model, desiredPos);
let expected = {
......
......@@ -10,9 +10,7 @@ import { Range } from 'vs/editor/common/core/range';
import { EndOfLinePreference, EndOfLineSequence, IIdentifiedSingleEditOperation, IModelContentChangedEvent2 } from 'vs/editor/common/editorCommon';
import { EditableTextModel, IValidatedEditOperation } from 'vs/editor/common/model/editableTextModel';
import { MirrorModel2 } from 'vs/editor/common/model/mirrorModel2';
import { TextModel } from 'vs/editor/common/model/textModel';
import { assertSyncedModels, testApplyEditsWithSyncedModels } from 'vs/editor/test/common/model/editableTextModelTestUtils';
import { TextModelData } from 'vs/editor/common/model/textSource';
suite('EditorModel - EditableTextModel._getInverseEdits', () => {
......@@ -279,7 +277,7 @@ suite('EditorModel - EditableTextModel._toSingleEditOperation', () => {
}
function testSimpleApplyEdits(original: string[], edits: IValidatedEditOperation[], expected: IValidatedEditOperation): void {
let model = new EditableTextModel([], TextModelData.fromString(original.join('\n'), TextModel.DEFAULT_CREATION_OPTIONS), null);
let model = EditableTextModel.createFromString(original.join('\n'));
model.setEOL(EndOfLineSequence.LF);
let actual = model._toSingleEditOperation(edits);
......@@ -521,7 +519,7 @@ suite('EditorModel - EditableTextModel._toSingleEditOperation', () => {
suite('EditorModel - EditableTextModel.applyEdits updates mightContainRTL', () => {
function testApplyEdits(original: string[], edits: IIdentifiedSingleEditOperation[], before: boolean, after: boolean): void {
let model = new EditableTextModel([], TextModelData.fromString(original.join('\n'), TextModel.DEFAULT_CREATION_OPTIONS), null);
let model = EditableTextModel.createFromString(original.join('\n'));
model.setEOL(EndOfLineSequence.LF);
assert.equal(model.mightContainRTL(), before);
......@@ -569,7 +567,7 @@ suite('EditorModel - EditableTextModel.applyEdits updates mightContainRTL', () =
suite('EditorModel - EditableTextModel.applyEdits updates mightContainNonBasicASCII', () => {
function testApplyEdits(original: string[], edits: IIdentifiedSingleEditOperation[], before: boolean, after: boolean): void {
let model = new EditableTextModel([], TextModelData.fromString(original.join('\n'), TextModel.DEFAULT_CREATION_OPTIONS), null);
let model = EditableTextModel.createFromString(original.join('\n'));
model.setEOL(EndOfLineSequence.LF);
assert.equal(model.mightContainNonBasicASCII(), before);
......@@ -1364,7 +1362,7 @@ suite('EditorModel - EditableTextModel.applyEdits', () => {
});
function testApplyEditsFails(original: string[], edits: IIdentifiedSingleEditOperation[]): void {
let model = new EditableTextModel([], TextModelData.fromString(original.join('\n'), TextModel.DEFAULT_CREATION_OPTIONS), null);
let model = EditableTextModel.createFromString(original.join('\n'));
let hasThrown = false;
try {
......@@ -1552,7 +1550,7 @@ suite('EditorModel - EditableTextModel.applyEdits', () => {
});
test('issue #1580: Changes in line endings are not correctly reflected in the extension host, leading to invalid offsets sent to external refactoring tools', () => {
let model = new EditableTextModel([], TextModelData.fromString('Hello\nWorld!', TextModel.DEFAULT_CREATION_OPTIONS), null);
let model = EditableTextModel.createFromString('Hello\nWorld!');
assert.equal(model.getEOL(), '\n');
let mirrorModel2 = new MirrorModel2(null, model.getLinesContent(), model.getEOL(), model.getVersionId());
......@@ -1623,7 +1621,7 @@ suite('EditorModel - EditableTextModel.applyEdits & markers', () => {
// var expectedMarkersMap = toMarkersMap(expectedMarkers);
var markerId2ModelMarkerId = Object.create(null);
var model = new EditableTextModel([], TextModelData.fromString(textStr, TextModel.DEFAULT_CREATION_OPTIONS), null);
var model = EditableTextModel.createFromString(textStr);
model.setEOL(EndOfLineSequence.LF);
// Add markers
......
......@@ -10,7 +10,7 @@ import { EditableTextModel } from 'vs/editor/common/model/editableTextModel';
import { MirrorModel2 } from 'vs/editor/common/model/mirrorModel2';
import { TextModel } from 'vs/editor/common/model/textModel';
import { Position } from 'vs/editor/common/core/position';
import { TextModelData } from 'vs/editor/common/model/textSource';
import { RawTextSource } from 'vs/editor/common/model/textSource';
export function testApplyEditsWithSyncedModels(original: string[], edits: editorCommon.IIdentifiedSingleEditOperation[], expected: string[], inputEditsAreInvalid: boolean = false): void {
var originalStr = original.join('\n');
......@@ -81,7 +81,7 @@ function assertLineMapping(model: TextModel, msg: string): void {
export function assertSyncedModels(text: string, callback: (model: EditableTextModel, assertMirrorModels: () => void) => void, setup: (model: EditableTextModel) => void = null): void {
var model = new EditableTextModel([], TextModelData.fromString(text, TextModel.DEFAULT_CREATION_OPTIONS), null);
var model = new EditableTextModel([], RawTextSource.fromString(text), TextModel.DEFAULT_CREATION_OPTIONS, null);
model.setEOL(editorCommon.EndOfLineSequence.LF);
assertLineMapping(model, 'model');
......
......@@ -7,18 +7,21 @@
import * as assert from 'assert';
import { Position } from 'vs/editor/common/core/position';
import { Range } from 'vs/editor/common/core/range';
import { TextModel } from 'vs/editor/common/model/textModel';
import { DefaultEndOfLine } from 'vs/editor/common/editorCommon';
import { TextModelData, ITextModelData } from 'vs/editor/common/model/textSource';
import { TextModel, ITextModelCreationData } from 'vs/editor/common/model/textModel';
import { DefaultEndOfLine, TextModelResolvedOptions } from 'vs/editor/common/editorCommon';
import { RawTextSource } from 'vs/editor/common/model/textSource';
function testGuessIndentation(defaultInsertSpaces: boolean, defaultTabSize: number, expectedInsertSpaces: boolean, expectedTabSize: number, text: string[], msg?: string): void {
var m = new TextModel([], TextModelData.fromString(text.join('\n'), {
tabSize: defaultTabSize,
insertSpaces: defaultInsertSpaces,
detectIndentation: true,
defaultEOL: DefaultEndOfLine.LF,
trimAutoWhitespace: true
}));
var m = TextModel.createFromString(
text.join('\n'),
{
tabSize: defaultTabSize,
insertSpaces: defaultInsertSpaces,
detectIndentation: true,
defaultEOL: DefaultEndOfLine.LF,
trimAutoWhitespace: true
}
);
var r = m.getOptions();
m.dispose();
......@@ -54,8 +57,9 @@ function assertGuess(expectedInsertSpaces: boolean, expectedTabSize: number, tex
suite('TextModelData.fromString', () => {
function testTextModelDataFromString(text: string, expected: ITextModelData): void {
let actual = TextModelData.fromString(text, TextModel.DEFAULT_CREATION_OPTIONS);
function testTextModelDataFromString(text: string, expected: ITextModelCreationData): void {
const rawTextSource = RawTextSource.fromString(text);
const actual = TextModel.resolveCreationData(rawTextSource, TextModel.DEFAULT_CREATION_OPTIONS);
assert.deepEqual(actual, expected);
}
......@@ -71,12 +75,12 @@ suite('TextModelData.fromString', () => {
containsRTL: false,
isBasicASCII: true
},
options: {
options: new TextModelResolvedOptions({
defaultEOL: DefaultEndOfLine.LF,
insertSpaces: true,
tabSize: 4,
trimAutoWhitespace: true,
}
})
});
});
......@@ -96,12 +100,12 @@ suite('TextModelData.fromString', () => {
containsRTL: false,
isBasicASCII: true
},
options: {
options: new TextModelResolvedOptions({
defaultEOL: DefaultEndOfLine.LF,
insertSpaces: true,
tabSize: 4,
trimAutoWhitespace: true,
}
})
});
});
......@@ -118,12 +122,12 @@ suite('TextModelData.fromString', () => {
containsRTL: false,
isBasicASCII: false
},
options: {
options: new TextModelResolvedOptions({
defaultEOL: DefaultEndOfLine.LF,
insertSpaces: true,
tabSize: 4,
trimAutoWhitespace: true,
}
})
});
});
......@@ -140,12 +144,12 @@ suite('TextModelData.fromString', () => {
containsRTL: true,
isBasicASCII: false
},
options: {
options: new TextModelResolvedOptions({
defaultEOL: DefaultEndOfLine.LF,
insertSpaces: true,
tabSize: 4,
trimAutoWhitespace: true,
}
})
});
});
......@@ -162,12 +166,12 @@ suite('TextModelData.fromString', () => {
containsRTL: true,
isBasicASCII: false
},
options: {
options: new TextModelResolvedOptions({
defaultEOL: DefaultEndOfLine.LF,
insertSpaces: true,
tabSize: 4,
trimAutoWhitespace: true,
}
})
});
});
......@@ -177,7 +181,7 @@ suite('Editor Model - TextModel', () => {
test('getValueLengthInRange', () => {
var m = new TextModel([], TextModelData.fromString('My First Line\r\nMy Second Line\r\nMy Third Line', TextModel.DEFAULT_CREATION_OPTIONS));
var m = TextModel.createFromString('My First Line\r\nMy Second Line\r\nMy Third Line');
assert.equal(m.getValueLengthInRange(new Range(1, 1, 1, 1)), ''.length);
assert.equal(m.getValueLengthInRange(new Range(1, 1, 1, 2)), 'M'.length);
assert.equal(m.getValueLengthInRange(new Range(1, 2, 1, 3)), 'y'.length);
......@@ -190,7 +194,7 @@ suite('Editor Model - TextModel', () => {
assert.equal(m.getValueLengthInRange(new Range(1, 2, 3, 1000)), 'y First Line\r\nMy Second Line\r\nMy Third Line'.length);
assert.equal(m.getValueLengthInRange(new Range(1, 1, 1000, 1000)), 'My First Line\r\nMy Second Line\r\nMy Third Line'.length);
m = new TextModel([], TextModelData.fromString('My First Line\nMy Second Line\nMy Third Line', TextModel.DEFAULT_CREATION_OPTIONS));
m = TextModel.createFromString('My First Line\nMy Second Line\nMy Third Line');
assert.equal(m.getValueLengthInRange(new Range(1, 1, 1, 1)), ''.length);
assert.equal(m.getValueLengthInRange(new Range(1, 1, 1, 2)), 'M'.length);
assert.equal(m.getValueLengthInRange(new Range(1, 2, 1, 3)), 'y'.length);
......@@ -559,7 +563,7 @@ suite('Editor Model - TextModel', () => {
test('validatePosition', () => {
let m = new TextModel([], TextModelData.fromString('line one\nline two', TextModel.DEFAULT_CREATION_OPTIONS));
let m = TextModel.createFromString('line one\nline two');
assert.deepEqual(m.validatePosition(new Position(0, 0)), new Position(1, 1));
assert.deepEqual(m.validatePosition(new Position(0, 1)), new Position(1, 1));
......@@ -588,7 +592,7 @@ suite('Editor Model - TextModel', () => {
test('validatePosition around high-low surrogate pairs 1', () => {
let m = new TextModel([], TextModelData.fromString('a📚b', TextModel.DEFAULT_CREATION_OPTIONS));
let m = TextModel.createFromString('a📚b');
assert.deepEqual(m.validatePosition(new Position(0, 0)), new Position(1, 1));
assert.deepEqual(m.validatePosition(new Position(0, 1)), new Position(1, 1));
......@@ -615,7 +619,7 @@ suite('Editor Model - TextModel', () => {
test('validatePosition around high-low surrogate pairs 2', () => {
let m = new TextModel([], TextModelData.fromString('a📚📚b', TextModel.DEFAULT_CREATION_OPTIONS));
let m = TextModel.createFromString('a📚📚b');
assert.deepEqual(m.validatePosition(new Position(1, 1)), new Position(1, 1));
assert.deepEqual(m.validatePosition(new Position(1, 2)), new Position(1, 2));
......@@ -629,7 +633,7 @@ suite('Editor Model - TextModel', () => {
test('validateRange around high-low surrogate pairs 1', () => {
let m = new TextModel([], TextModelData.fromString('a📚b', TextModel.DEFAULT_CREATION_OPTIONS));
let m = TextModel.createFromString('a📚b');
assert.deepEqual(m.validateRange(new Range(0, 0, 0, 1)), new Range(1, 1, 1, 1));
assert.deepEqual(m.validateRange(new Range(0, 0, 0, 7)), new Range(1, 1, 1, 1));
......@@ -657,7 +661,7 @@ suite('Editor Model - TextModel', () => {
test('validateRange around high-low surrogate pairs 2', () => {
let m = new TextModel([], TextModelData.fromString('a📚📚b', TextModel.DEFAULT_CREATION_OPTIONS));
let m = TextModel.createFromString('a📚📚b');
assert.deepEqual(m.validateRange(new Range(0, 0, 0, 1)), new Range(1, 1, 1, 1));
assert.deepEqual(m.validateRange(new Range(0, 0, 0, 7)), new Range(1, 1, 1, 1));
......@@ -700,7 +704,7 @@ suite('Editor Model - TextModel', () => {
test('modifyPosition', () => {
var m = new TextModel([], TextModelData.fromString('line one\nline two', TextModel.DEFAULT_CREATION_OPTIONS));
var m = TextModel.createFromString('line one\nline two');
assert.deepEqual(m.modifyPosition(new Position(1, 1), 0), new Position(1, 1));
assert.deepEqual(m.modifyPosition(new Position(0, 0), 0), new Position(1, 1));
assert.deepEqual(m.modifyPosition(new Position(30, 1), 0), new Position(2, 9));
......@@ -729,22 +733,15 @@ suite('Editor Model - TextModel', () => {
});
test('normalizeIndentation 1', () => {
let model = new TextModel([], {
text: {
length: 0,
lines: [],
BOM: '',
EOL: '\n',
containsRTL: false,
isBasicASCII: true
},
options: {
let model = TextModel.createFromString('',
{
detectIndentation: false,
tabSize: 4,
insertSpaces: false,
trimAutoWhitespace: true,
defaultEOL: DefaultEndOfLine.LF
}
});
);
assert.equal(model.normalizeIndentation('\t'), '\t');
assert.equal(model.normalizeIndentation(' '), '\t');
......@@ -772,22 +769,15 @@ suite('Editor Model - TextModel', () => {
});
test('normalizeIndentation 2', () => {
let model = new TextModel([], {
text: {
length: 0,
lines: [],
BOM: '',
EOL: '\n',
containsRTL: false,
isBasicASCII: true
},
options: {
let model = TextModel.createFromString('',
{
detectIndentation: false,
tabSize: 4,
insertSpaces: true,
trimAutoWhitespace: true,
defaultEOL: DefaultEndOfLine.LF
}
});
);
assert.equal(model.normalizeIndentation('\ta'), ' a');
assert.equal(model.normalizeIndentation(' a'), ' a');
......@@ -807,24 +797,24 @@ suite('Editor Model - TextModel', () => {
suite('TextModel.mightContainRTL', () => {
test('nope', () => {
let model = new TextModel([], TextModelData.fromString('hello world!', TextModel.DEFAULT_CREATION_OPTIONS));
let model = TextModel.createFromString('hello world!');
assert.equal(model.mightContainRTL(), false);
});
test('yes', () => {
let model = new TextModel([], TextModelData.fromString('Hello,\nזוהי עובדה מבוססת שדעתו', TextModel.DEFAULT_CREATION_OPTIONS));
let model = TextModel.createFromString('Hello,\nזוהי עובדה מבוססת שדעתו');
assert.equal(model.mightContainRTL(), true);
});
test('setValue resets 1', () => {
let model = new TextModel([], TextModelData.fromString('hello world!', TextModel.DEFAULT_CREATION_OPTIONS));
let model = TextModel.createFromString('hello world!');
assert.equal(model.mightContainRTL(), false);
model.setValue('Hello,\nזוהי עובדה מבוססת שדעתו');
assert.equal(model.mightContainRTL(), true);
});
test('setValue resets 2', () => {
let model = new TextModel([], TextModelData.fromString('Hello,\nهناك حقيقة مثبتة منذ زمن طويل', TextModel.DEFAULT_CREATION_OPTIONS));
let model = TextModel.createFromString('Hello,\nهناك حقيقة مثبتة منذ زمن طويل');
assert.equal(model.mightContainRTL(), true);
model.setValue('hello world!');
assert.equal(model.mightContainRTL(), false);
......@@ -835,7 +825,7 @@ suite('TextModel.mightContainRTL', () => {
suite('TextModel.getLineIndentGuide', () => {
function assertIndentGuides(lines: [number, string][]): void {
let text = lines.map(l => l[1]).join('\n');
let model = new TextModel([], TextModelData.fromString(text, TextModel.DEFAULT_CREATION_OPTIONS));
let model = TextModel.createFromString(text);
let actual: [number, string][] = [];
for (let line = 1; line <= model.getLineCount(); line++) {
......
......@@ -10,7 +10,6 @@ import { FindMatch, EndOfLineSequence } from 'vs/editor/common/editorCommon';
import { Range } from 'vs/editor/common/core/range';
import { TextModel } from 'vs/editor/common/model/textModel';
import { TextModelSearch, SearchParams } from 'vs/editor/common/model/textModelSearch';
import { TextModelData } from 'vs/editor/common/model/textSource';
// --------- Find
suite('TextModelSearch', () => {
......@@ -49,12 +48,12 @@ suite('TextModelSearch', () => {
let expectedMatches = expectedRanges.map(entry => new FindMatch(entry, null));
let searchParams = new SearchParams(searchString, isRegex, matchCase, wholeWord);
let model = new TextModel([], TextModelData.fromString(text, TextModel.DEFAULT_CREATION_OPTIONS));
let model = TextModel.createFromString(text);
_assertFindMatches(model, searchParams, expectedMatches);
model.dispose();
let model2 = new TextModel([], TextModelData.fromString(text, TextModel.DEFAULT_CREATION_OPTIONS));
let model2 = TextModel.createFromString(text);
model2.setEOL(EndOfLineSequence.CRLF);
_assertFindMatches(model2, searchParams, expectedMatches);
model2.dispose();
......@@ -335,7 +334,7 @@ suite('TextModelSearch', () => {
});
test('findNextMatch without regex', () => {
let model = new TextModel([], TextModelData.fromString('line line one\nline two\nthree', TextModel.DEFAULT_CREATION_OPTIONS));
let model = TextModel.createFromString('line line one\nline two\nthree');
let searchParams = new SearchParams('line', false, false, false);
......@@ -358,7 +357,7 @@ suite('TextModelSearch', () => {
});
test('findNextMatch with beginning boundary regex', () => {
let model = new TextModel([], TextModelData.fromString('line one\nline two\nthree', TextModel.DEFAULT_CREATION_OPTIONS));
let model = TextModel.createFromString('line one\nline two\nthree');
let searchParams = new SearchParams('^line', true, false, false);
......@@ -378,7 +377,7 @@ suite('TextModelSearch', () => {
});
test('findNextMatch with beginning boundary regex and line has repetitive beginnings', () => {
let model = new TextModel([], TextModelData.fromString('line line one\nline two\nthree', TextModel.DEFAULT_CREATION_OPTIONS));
let model = TextModel.createFromString('line line one\nline two\nthree');
let searchParams = new SearchParams('^line', true, false, false);
......@@ -398,7 +397,7 @@ suite('TextModelSearch', () => {
});
test('findNextMatch with beginning boundary multiline regex and line has repetitive beginnings', () => {
let model = new TextModel([], TextModelData.fromString('line line one\nline two\nline three\nline four', TextModel.DEFAULT_CREATION_OPTIONS));
let model = TextModel.createFromString('line line one\nline two\nline three\nline four');
let searchParams = new SearchParams('^line.*\\nline', true, false, false);
......@@ -415,7 +414,7 @@ suite('TextModelSearch', () => {
});
test('findNextMatch with ending boundary regex', () => {
let model = new TextModel([], TextModelData.fromString('one line line\ntwo line\nthree', TextModel.DEFAULT_CREATION_OPTIONS));
let model = TextModel.createFromString('one line line\ntwo line\nthree');
let searchParams = new SearchParams('line$', true, false, false);
......@@ -435,7 +434,7 @@ suite('TextModelSearch', () => {
});
test('findMatches with capturing matches', () => {
let model = new TextModel([], TextModelData.fromString('one line line\ntwo line\nthree', TextModel.DEFAULT_CREATION_OPTIONS));
let model = TextModel.createFromString('one line line\ntwo line\nthree');
let searchParams = new SearchParams('(l(in)e)', true, false, false);
......@@ -450,7 +449,7 @@ suite('TextModelSearch', () => {
});
test('findMatches multiline with capturing matches', () => {
let model = new TextModel([], TextModelData.fromString('one line line\ntwo line\nthree', TextModel.DEFAULT_CREATION_OPTIONS));
let model = TextModel.createFromString('one line line\ntwo line\nthree');
let searchParams = new SearchParams('(l(in)e)\\n', true, false, false);
......@@ -464,7 +463,7 @@ suite('TextModelSearch', () => {
});
test('findNextMatch with capturing matches', () => {
let model = new TextModel([], TextModelData.fromString('one line line\ntwo line\nthree', TextModel.DEFAULT_CREATION_OPTIONS));
let model = TextModel.createFromString('one line line\ntwo line\nthree');
let searchParams = new SearchParams('(l(in)e)', true, false, false);
......@@ -475,7 +474,7 @@ suite('TextModelSearch', () => {
});
test('findNextMatch multiline with capturing matches', () => {
let model = new TextModel([], TextModelData.fromString('one line line\ntwo line\nthree', TextModel.DEFAULT_CREATION_OPTIONS));
let model = TextModel.createFromString('one line line\ntwo line\nthree');
let searchParams = new SearchParams('(l(in)e)\\n', true, false, false);
......@@ -486,7 +485,7 @@ suite('TextModelSearch', () => {
});
test('findPreviousMatch with capturing matches', () => {
let model = new TextModel([], TextModelData.fromString('one line line\ntwo line\nthree', TextModel.DEFAULT_CREATION_OPTIONS));
let model = TextModel.createFromString('one line line\ntwo line\nthree');
let searchParams = new SearchParams('(l(in)e)', true, false, false);
......@@ -497,7 +496,7 @@ suite('TextModelSearch', () => {
});
test('findPreviousMatch multiline with capturing matches', () => {
let model = new TextModel([], TextModelData.fromString('one line line\ntwo line\nthree', TextModel.DEFAULT_CREATION_OPTIONS));
let model = TextModel.createFromString('one line line\ntwo line\nthree');
let searchParams = new SearchParams('(l(in)e)\\n', true, false, false);
......@@ -508,7 +507,7 @@ suite('TextModelSearch', () => {
});
test('\\n matches \\r\\n', () => {
let model = new TextModel([], TextModelData.fromString('a\r\nb\r\nc\r\nd\r\ne\r\nf\r\ng\r\nh\r\ni', TextModel.DEFAULT_CREATION_OPTIONS));
let model = TextModel.createFromString('a\r\nb\r\nc\r\nd\r\ne\r\nf\r\ng\r\nh\r\ni');
assert.equal(model.getEOL(), '\r\n');
......@@ -531,7 +530,7 @@ suite('TextModelSearch', () => {
});
test('\\r can never be found', () => {
let model = new TextModel([], TextModelData.fromString('a\r\nb\r\nc\r\nd\r\ne\r\nf\r\ng\r\nh\r\ni', TextModel.DEFAULT_CREATION_OPTIONS));
let model = TextModel.createFromString('a\r\nb\r\nc\r\nd\r\ne\r\nf\r\ng\r\nh\r\ni');
assert.equal(model.getEOL(), '\r\n');
......
......@@ -18,7 +18,7 @@ import { TextModelWithTokens } from 'vs/editor/common/model/textModelWithTokens'
import { LanguageConfigurationRegistry } from 'vs/editor/common/modes/languageConfigurationRegistry';
import { NULL_STATE } from 'vs/editor/common/modes/nullMode';
import { TokenizationResult2 } from 'vs/editor/common/core/token';
import { TextModelData } from 'vs/editor/common/model/textSource';
import { RawTextSource } from 'vs/editor/common/model/textSource';
suite('TextModelWithTokens', () => {
......@@ -78,7 +78,8 @@ suite('TextModelWithTokens', () => {
let model = new TextModelWithTokens(
[],
TextModelData.fromString(contents.join('\n'), TextModel.DEFAULT_CREATION_OPTIONS),
RawTextSource.fromString(contents.join('\n')),
TextModel.DEFAULT_CREATION_OPTIONS,
languageIdentifier
);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册