提交 220a10c2 编写于 作者: A Alex Dima

Move ITextSource2 out of editorCommon

上级 bff93542
......@@ -2488,37 +2488,6 @@ export interface ITextSource {
readonly isBasicASCII: boolean;
}
/**
* The text source
* @internal
*/
export interface ITextSource2 {
/**
* 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 number of lines ending with '\r\n'
*/
readonly totalCRCount: number;
/**
* 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
......
......@@ -20,19 +20,6 @@ import { LanguageIdentifier } from 'vs/editor/common/modes';
var MODEL_ID = 0;
var aliveModels: { [modelId: string]: boolean; } = {};
// var LAST_CNT = 0;
// setInterval(() => {
// var cnt = Object.keys(aliveModels).length;
// if (cnt === LAST_CNT) {
// return;
// }
// console.warn('ALIVE MODELS:');
// console.log(Object.keys(aliveModels).join('\n'));
// LAST_CNT = cnt;
// }, 100);
export class Model extends EditableTextModel implements IModel {
public onDidChangeDecorations(listener: (e: IModelDecorationsChangedEvent) => void): IDisposable {
......@@ -57,24 +44,11 @@ export class Model extends EditableTextModel implements IModel {
return new Model(rawText, languageIdentifier, uri);
}
public id: string;
public readonly id: string;
private _associatedResource: URI;
private readonly _associatedResource: URI;
private _attachedEditorCount: number;
/**
* Instantiates a new model
* @param rawText
* The raw text buffer. It may start with a UTF-16 BOM, which can be
* optionally preserved when doing a getValue call. The lines may be
* separated by different EOL combinations, such as \n or \r\n. These
* can also be preserved when doing a getValue call.
* @param mode
* The language service name this model is bound to.
* @param associatedResource
* The resource associated with this model. If the value is not provided an
* unique in memory URL is constructed as the associated resource.
*/
constructor(rawText: IRawText, languageIdentifier: LanguageIdentifier, associatedResource: URI = null) {
super([EventType.ModelDispose], rawText, languageIdentifier);
......@@ -88,15 +62,7 @@ export class Model extends EditableTextModel implements IModel {
this._associatedResource = associatedResource;
}
if (aliveModels[String(this._associatedResource)]) {
throw new Error('Cannot instantiate a second Model with the same URI');
}
this._attachedEditorCount = 0;
aliveModels[String(this._associatedResource)] = true;
// console.log('ALIVE MODELS: ' + Object.keys(aliveModels).join('\n'));
}
public destroy(): void {
......@@ -105,24 +71,19 @@ export class Model extends EditableTextModel implements IModel {
public dispose(): void {
this._isDisposing = true;
delete aliveModels[String(this._associatedResource)];
this.emit(EventType.ModelDispose);
super.dispose();
this._isDisposing = false;
// console.log('ALIVE MODELS: ' + Object.keys(aliveModels).join('\n'));
}
public onBeforeAttached(): void {
this._attachedEditorCount++;
// Warm up tokens for the editor
this._warmUpTokens();
}
public onBeforeDetached(): void {
this._attachedEditorCount--;
// Intentional empty (for now)
}
protected _shouldAutoTokenize(): boolean {
......
......@@ -15,6 +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';
const LIMIT_FIND_COUNT = 999;
export const LONG_LINE_BOUNDARY = 1000;
......@@ -749,7 +750,7 @@ export class TextModel extends OrderGuaranteeEventEmitter implements editorCommo
}
}
public static toTextSource(rawText: string): editorCommon.ITextSource2 {
public static toTextSource(rawText: string): ITextSource2 {
// Count the number of lines that end with \r\n
let carriageReturnCnt = 0;
let lastCarriageReturnIndex = -1;
......@@ -785,7 +786,7 @@ export class TextModel extends OrderGuaranteeEventEmitter implements editorCommo
* 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: editorCommon.ITextSource2): string {
public static getEndOfLine(textSource: ITextSource2): string {
const lineFeedCnt = textSource.lines.length - 1;
if (lineFeedCnt === 0) {
// This is an empty file or a file with precisely one line
......@@ -804,7 +805,7 @@ export class TextModel extends OrderGuaranteeEventEmitter implements editorCommo
return TextModel.toRawTextFromTextSource(textSource, opts);
}
public static toRawTextFromTextSource(textSource: editorCommon.ITextSource2, opts: editorCommon.ITextModelCreationOptions): editorCommon.IRawText {
public static toRawTextFromTextSource(textSource: ITextSource2, opts: editorCommon.ITextModelCreationOptions): editorCommon.IRawText {
let EOL = TextModel.getEndOfLine(textSource);
if (!EOL) {
// This is an empty file or a file with precisely one line
......@@ -897,7 +898,7 @@ export class TextModel extends OrderGuaranteeEventEmitter implements editorCommo
export class RawText {
public static toRawText(textSourceOrString: editorCommon.ITextSource2 | string, opts: editorCommon.ITextModelCreationOptions): editorCommon.IRawText {
public static toRawText(textSourceOrString: ITextSource2 | string, opts: editorCommon.ITextModelCreationOptions): editorCommon.IRawText {
if (typeof textSourceOrString === 'string') {
return RawText.fromString(textSourceOrString, opts);
} else {
......@@ -905,7 +906,7 @@ export class RawText {
}
}
public static toRawTextWithModelOptions(textSourceOrString: editorCommon.ITextSource2 | string, model: editorCommon.IModel): editorCommon.IRawText {
public static toRawTextWithModelOptions(textSourceOrString: ITextSource2 | string, model: editorCommon.IModel): editorCommon.IRawText {
if (typeof textSourceOrString === 'string') {
return RawText.fromStringWithModelOptions(textSourceOrString, model);
} else {
......@@ -917,7 +918,7 @@ export class RawText {
return TextModel.toRawText(rawText, opts);
}
public static fromTextSource(textSource: editorCommon.ITextSource2, opts: editorCommon.ITextModelCreationOptions): editorCommon.IRawText {
public static fromTextSource(textSource: ITextSource2, opts: editorCommon.ITextModelCreationOptions): editorCommon.IRawText {
return TextModel.toRawTextFromTextSource(textSource, opts);
}
......@@ -932,7 +933,7 @@ export class RawText {
});
}
public static fromTextSourceWithModelOptions(textSource: editorCommon.ITextSource2, model: editorCommon.IModel): editorCommon.IRawText {
public static fromTextSourceWithModelOptions(textSource: ITextSource2, model: editorCommon.IModel): editorCommon.IRawText {
let opts = model.getOptions();
return TextModel.toRawTextFromTextSource(textSource, {
tabSize: opts.tabSize,
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
/**
* The text source
*/
export interface ITextSource2 {
/**
* 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 number of lines ending with '\r\n'
*/
readonly totalCRCount: number;
/**
* 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;
}
......@@ -8,8 +8,9 @@ import Event from 'vs/base/common/event';
import URI from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { IModel, ITextSource2, ITextModelCreationOptions } from 'vs/editor/common/editorCommon';
import { IModel, ITextModelCreationOptions } from 'vs/editor/common/editorCommon';
import { IMode } from 'vs/editor/common/modes';
import { ITextSource2 } from 'vs/editor/common/model/textSource';
export var IModelService = createDecorator<IModelService>('modelService');
......
......@@ -24,6 +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';
function MODEL_ID(resource: URI): string {
return resource.toString();
......@@ -338,7 +339,7 @@ export class ModelServiceImpl implements IModelService {
// --- begin IModelService
private _createModelData(value: string | editorCommon.ITextSource2, languageIdentifier: LanguageIdentifier, resource: URI): ModelData {
private _createModelData(value: string | ITextSource2, languageIdentifier: LanguageIdentifier, resource: URI): ModelData {
// create & save the model
const options = this.getCreationOptions(languageIdentifier.language);
......@@ -357,7 +358,7 @@ export class ModelServiceImpl implements IModelService {
return modelData;
}
public updateModel(model: editorCommon.IModel, value: string | editorCommon.ITextSource2): void {
public updateModel(model: editorCommon.IModel, value: string | ITextSource2): void {
let options = this.getCreationOptions(model.getLanguageIdentifier().language);
let rawText: editorCommon.IRawText = RawText.toRawText(value, options);
......@@ -370,7 +371,7 @@ export class ModelServiceImpl implements IModelService {
model.setValueFromRawText(rawText);
}
public createModel(value: string | editorCommon.ITextSource2, modeOrPromise: TPromise<IMode> | IMode, resource: URI): editorCommon.IModel {
public createModel(value: string | ITextSource2, modeOrPromise: TPromise<IMode> | IMode, resource: URI): editorCommon.IModel {
let modelData: ModelData;
if (!modeOrPromise || TPromise.is(modeOrPromise)) {
......
......@@ -6,10 +6,10 @@
import { IStringStream } from 'vs/platform/files/common/files';
import * as crypto from 'crypto';
import { ITextSource2 } from 'vs/editor/common/editorCommon';
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';
export interface ModelBuilderResult {
readonly hash: string;
......
......@@ -6,9 +6,10 @@
import * as assert from 'assert';
import { ModelBuilder, computeHash } from 'vs/editor/node/model/modelBuilder';
import { ITextModelCreationOptions, ITextSource2 } from 'vs/editor/common/editorCommon';
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';
export function testModelBuilder(chunks: string[], opts: ITextModelCreationOptions = TextModel.DEFAULT_CREATION_OPTIONS): string {
let expectedTextSource = TextModel.toTextSource(chunks.join(''));
......
......@@ -5,7 +5,7 @@
'use strict';
import { TPromise } from 'vs/base/common/winjs.base';
import { EndOfLinePreference, IModel, ITextSource2 } from 'vs/editor/common/editorCommon';
import { EndOfLinePreference, IModel } from 'vs/editor/common/editorCommon';
import { IMode } from 'vs/editor/common/modes';
import { EditorModel } from 'vs/workbench/common/editor';
import URI from 'vs/base/common/uri';
......@@ -13,6 +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';
/**
* The base text editor model leverages the code editor model. This class is only intended to be subclassed and not instantiated.
......
......@@ -10,11 +10,12 @@ import URI from 'vs/base/common/uri';
import { ITextModelResolverService, ITextModelContentProvider } from 'vs/editor/common/services/resolverService';
import { IModelService } from 'vs/editor/common/services/modelService';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { IModel, ITextSource2 } from 'vs/editor/common/editorCommon';
import { IModel } from 'vs/editor/common/editorCommon';
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';
export class WalkThroughContentProvider implements ITextModelContentProvider, IWorkbenchContribution {
......
......@@ -8,8 +8,8 @@
import Uri from 'vs/base/common/uri';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { TPromise } from 'vs/base/common/winjs.base';
import { ITextSource2 } from 'vs/editor/common/editorCommon';
import { IResolveContentOptions, IUpdateContentOptions } from 'vs/platform/files/common/files';
import { ITextSource2 } from 'vs/editor/common/model/textSource';
export const IBackupFileService = createDecorator<IBackupFileService>('backupFileService');
......
......@@ -17,9 +17,9 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment'
import { IFileService } from 'vs/platform/files/common/files';
import { TPromise } from 'vs/base/common/winjs.base';
import { readToMatchingString } from 'vs/base/node/stream';
import { ITextSource2 } from 'vs/editor/common/editorCommon';
import { TextModel } from 'vs/editor/common/model/textModel';
import { IWindowService } from 'vs/platform/windows/common/windows';
import { ITextSource2 } from 'vs/editor/common/model/textSource';
export interface IBackupFilesModel {
resolve(backupRoot: string): TPromise<IBackupFilesModel>;
......
......@@ -16,7 +16,7 @@ import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import paths = require('vs/base/common/paths');
import diagnostics = require('vs/base/common/diagnostics');
import types = require('vs/base/common/types');
import { IModelContentChangedEvent, ITextSource2 } from 'vs/editor/common/editorCommon';
import { IModelContentChangedEvent } from 'vs/editor/common/editorCommon';
import { IMode } from 'vs/editor/common/modes';
import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle';
import { ITextFileService, IAutoSaveConfiguration, ModelState, ITextFileEditorModel, IModelSaveOptions, ISaveErrorHandler, ISaveParticipant, StateChange, SaveReason, IRawTextContent } from 'vs/workbench/services/textfile/common/textfiles';
......@@ -31,6 +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';
/**
* 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.
......
......@@ -7,12 +7,12 @@
import { TPromise } from 'vs/base/common/winjs.base';
import URI from 'vs/base/common/uri';
import Event from 'vs/base/common/event';
import { ITextSource2 } from 'vs/editor/common/editorCommon';
import { IDisposable } from 'vs/base/common/lifecycle';
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';
/**
* The save error handler can be installed on the text text file editor model to install code that executes when save errors occur.
......
......@@ -49,7 +49,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/editorCommon';
import { ITextSource2 } from 'vs/editor/common/model/textSource';
export function createFileInput(instantiationService: IInstantiationService, resource: URI): FileEditorInput {
return instantiationService.createInstance(FileEditorInput, resource, void 0);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册