提交 6a4016f1 编写于 作者: S Sandeep Somavarapu

#19511 Adopt to language based settings for model configurations

上级 25af6cd6
......@@ -339,7 +339,7 @@ export class TextModel extends OrderGuaranteeEventEmitter implements editorCommo
this.setValueFromRawText(rawText);
}
public setValueFromRawText(newValue: editorCommon.IRawText): void {
public setValueFromRawText(newValue: editorCommon.ITextSource): void {
this._assertNotDisposed();
if (newValue === null) {
// There's nothing to do
......
......@@ -15,15 +15,16 @@ export var IModelService = createDecorator<IModelService>('modelService');
export interface IRawTextProvider {
getFirstLine(): string;
getEntireContent(): string;
toRawText(opts: ITextModelCreationOptions): IRawText;
}
export interface IModelService {
_serviceBrand: any;
createModel(value: string | IRawText, modeOrPromise: TPromise<IMode> | IMode, resource: URI): IModel;
createModel(value: string | IRawTextProvider, modeOrPromise: TPromise<IMode> | IMode, resource: URI): IModel;
createRawText(provider: IRawTextProvider): IRawText;
updateModel(model: IModel, value: string | IRawTextProvider): void;
setMode(model: IModel, modeOrPromise: TPromise<IMode> | IMode): void;
......@@ -31,7 +32,7 @@ export interface IModelService {
getModels(): IModel[];
getCreationOptions(): ITextModelCreationOptions;
getCreationOptions(language: string): ITextModelCreationOptions;
getModel(resource: URI): IModel;
......
......@@ -23,6 +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 { RawText } from 'vs/editor/common/model/textModel';
function MODEL_ID(resource: URI): string {
return resource.toString();
......@@ -172,6 +173,8 @@ interface IRawConfig {
};
}
const DEFAULT_EOL = (platform.isLinux || platform.isMacintosh) ? editorCommon.DefaultEndOfLine.LF : editorCommon.DefaultEndOfLine.CRLF;
export class ModelServiceImpl implements IModelService {
public _serviceBrand: any;
......@@ -184,7 +187,9 @@ export class ModelServiceImpl implements IModelService {
private _onModelRemoved: Emitter<editorCommon.IModel>;
private _onModelModeChanged: Emitter<{ model: editorCommon.IModel; oldModeId: string; }>;
private _modelCreationOptions: editorCommon.ITextModelCreationOptions;
private _modelCreationOptionsByLanguage: {
[language: string]: editorCommon.ITextModelCreationOptions;
};
/**
* All the models known in the system.
......@@ -195,18 +200,10 @@ export class ModelServiceImpl implements IModelService {
@IMarkerService markerService: IMarkerService,
@IConfigurationService configurationService: IConfigurationService,
) {
this._modelCreationOptions = {
tabSize: DEFAULT_INDENTATION.tabSize,
insertSpaces: DEFAULT_INDENTATION.insertSpaces,
detectIndentation: DEFAULT_INDENTATION.detectIndentation,
defaultEOL: (platform.isLinux || platform.isMacintosh) ? editorCommon.DefaultEndOfLine.LF : editorCommon.DefaultEndOfLine.CRLF,
trimAutoWhitespace: DEFAULT_TRIM_AUTO_WHITESPACE
};
this._markerService = markerService;
this._configurationService = configurationService;
this._models = {};
this._modelCreationOptionsByLanguage = Object.create(null);
this._onModelAdded = new Emitter<editorCommon.IModel>();
this._onModelRemoved = new Emitter<editorCommon.IModel>();
this._onModelModeChanged = new Emitter<{ model: editorCommon.IModel; oldModeId: string; }>();
......@@ -215,89 +212,98 @@ export class ModelServiceImpl implements IModelService {
this._markerServiceSubscription = this._markerService.onMarkerChanged(this._handleMarkerChange, this);
}
let readConfig = (config: IRawConfig) => {
this._configurationServiceSubscription = this._configurationService.onDidUpdateConfiguration(e => this._updateModelOptions());
this._updateModelOptions();
}
let tabSize = DEFAULT_INDENTATION.tabSize;
if (config.editor && typeof config.editor.tabSize !== 'undefined') {
let parsedTabSize = parseInt(config.editor.tabSize, 10);
if (!isNaN(parsedTabSize)) {
tabSize = parsedTabSize;
}
private static _readModelOptions(config: IRawConfig): editorCommon.ITextModelCreationOptions {
let tabSize = DEFAULT_INDENTATION.tabSize;
if (config.editor && typeof config.editor.tabSize !== 'undefined') {
let parsedTabSize = parseInt(config.editor.tabSize, 10);
if (!isNaN(parsedTabSize)) {
tabSize = parsedTabSize;
}
}
let insertSpaces = DEFAULT_INDENTATION.insertSpaces;
if (config.editor && typeof config.editor.insertSpaces !== 'undefined') {
insertSpaces = (config.editor.insertSpaces === 'false' ? false : Boolean(config.editor.insertSpaces));
}
let insertSpaces = DEFAULT_INDENTATION.insertSpaces;
if (config.editor && typeof config.editor.insertSpaces !== 'undefined') {
insertSpaces = (config.editor.insertSpaces === 'false' ? false : Boolean(config.editor.insertSpaces));
}
let newDefaultEOL = this._modelCreationOptions.defaultEOL;
const eol = config.files && config.files.eol;
if (eol === '\r\n') {
newDefaultEOL = editorCommon.DefaultEndOfLine.CRLF;
} else if (eol === '\n') {
newDefaultEOL = editorCommon.DefaultEndOfLine.LF;
}
let newDefaultEOL = DEFAULT_EOL;
const eol = config.files && config.files.eol;
if (eol === '\r\n') {
newDefaultEOL = editorCommon.DefaultEndOfLine.CRLF;
} else if (eol === '\n') {
newDefaultEOL = editorCommon.DefaultEndOfLine.LF;
}
let trimAutoWhitespace = this._modelCreationOptions.trimAutoWhitespace;
if (config.editor && typeof config.editor.trimAutoWhitespace !== 'undefined') {
trimAutoWhitespace = (config.editor.trimAutoWhitespace === 'false' ? false : Boolean(config.editor.trimAutoWhitespace));
}
let trimAutoWhitespace = DEFAULT_TRIM_AUTO_WHITESPACE;
if (config.editor && typeof config.editor.trimAutoWhitespace !== 'undefined') {
trimAutoWhitespace = (config.editor.trimAutoWhitespace === 'false' ? false : Boolean(config.editor.trimAutoWhitespace));
}
let detectIndentation = DEFAULT_INDENTATION.detectIndentation;
if (config.editor && typeof config.editor.detectIndentation !== 'undefined') {
detectIndentation = (config.editor.detectIndentation === 'false' ? false : Boolean(config.editor.detectIndentation));
}
let detectIndentation = DEFAULT_INDENTATION.detectIndentation;
if (config.editor && typeof config.editor.detectIndentation !== 'undefined') {
detectIndentation = (config.editor.detectIndentation === 'false' ? false : Boolean(config.editor.detectIndentation));
}
this._setModelOptions({
tabSize: tabSize,
insertSpaces: insertSpaces,
detectIndentation: detectIndentation,
defaultEOL: newDefaultEOL,
trimAutoWhitespace: trimAutoWhitespace
});
return {
tabSize: tabSize,
insertSpaces: insertSpaces,
detectIndentation: detectIndentation,
defaultEOL: newDefaultEOL,
trimAutoWhitespace: trimAutoWhitespace
};
this._configurationServiceSubscription = this._configurationService.onDidUpdateConfiguration(e => {
readConfig(e.config);
});
readConfig(this._configurationService.getConfiguration());
}
public getCreationOptions(): editorCommon.ITextModelCreationOptions {
return this._modelCreationOptions;
public getCreationOptions(language: string): editorCommon.ITextModelCreationOptions {
let creationOptions = this._modelCreationOptionsByLanguage[language];
if (!creationOptions) {
creationOptions = ModelServiceImpl._readModelOptions(this._configurationService.getConfiguration({ overrideIdentifier: language }));
this._modelCreationOptionsByLanguage[language] = creationOptions;
}
return creationOptions;
}
private _setModelOptions(newOpts: editorCommon.ITextModelCreationOptions): void {
if (
(this._modelCreationOptions.detectIndentation === newOpts.detectIndentation)
&& (this._modelCreationOptions.insertSpaces === newOpts.insertSpaces)
&& (this._modelCreationOptions.tabSize === newOpts.tabSize)
&& (this._modelCreationOptions.trimAutoWhitespace === newOpts.trimAutoWhitespace)
) {
// Same indent opts, no need to touch created models
this._modelCreationOptions = newOpts;
return;
}
this._modelCreationOptions = newOpts;
private _updateModelOptions(): void {
let oldOptionsByLanguage = this._modelCreationOptionsByLanguage;
this._modelCreationOptionsByLanguage = Object.create(null);
// Update options on all models
let keys = Object.keys(this._models);
for (let i = 0, len = keys.length; i < len; i++) {
let modelId = keys[i];
let modelData = this._models[modelId];
const language = modelData.model.getLanguageIdentifier().language;
const oldOptions = oldOptionsByLanguage[language];
const newOptions = this.getCreationOptions(language);
ModelServiceImpl._setModelOptionsForModel(modelData.model, newOptions, oldOptions);
}
}
if (this._modelCreationOptions.detectIndentation) {
modelData.model.detectIndentation(this._modelCreationOptions.insertSpaces, this._modelCreationOptions.tabSize);
modelData.model.updateOptions({
trimAutoWhitespace: this._modelCreationOptions.trimAutoWhitespace
});
} else {
modelData.model.updateOptions({
insertSpaces: this._modelCreationOptions.insertSpaces,
tabSize: this._modelCreationOptions.tabSize,
trimAutoWhitespace: this._modelCreationOptions.trimAutoWhitespace
});
}
private static _setModelOptionsForModel(model: editorCommon.IModel, newOptions: editorCommon.ITextModelCreationOptions, currentOptions: editorCommon.ITextModelCreationOptions): void {
if (currentOptions
&& (currentOptions.detectIndentation === newOptions.detectIndentation)
&& (currentOptions.insertSpaces === newOptions.insertSpaces)
&& (currentOptions.tabSize === newOptions.tabSize)
&& (currentOptions.trimAutoWhitespace === newOptions.trimAutoWhitespace)
) {
// Same indent opts, no need to touch the model
return;
}
if (newOptions.detectIndentation) {
model.detectIndentation(newOptions.insertSpaces, newOptions.tabSize);
model.updateOptions({
trimAutoWhitespace: newOptions.trimAutoWhitespace
});
} else {
model.updateOptions({
insertSpaces: newOptions.insertSpaces,
tabSize: newOptions.tabSize,
trimAutoWhitespace: newOptions.trimAutoWhitespace
});
}
}
......@@ -332,13 +338,15 @@ export class ModelServiceImpl implements IModelService {
// --- begin IModelService
private _createModelData(value: string | editorCommon.IRawText, languageIdentifier: LanguageIdentifier, resource: URI): ModelData {
private _createModelData(value: string | IRawTextProvider, languageIdentifier: LanguageIdentifier, resource: URI): ModelData {
// create & save the model
const options = this.getCreationOptions(languageIdentifier.language);
let model: Model;
if (typeof value === 'string') {
model = Model.createFromString(value, this._modelCreationOptions, languageIdentifier, resource);
model = Model.createFromString(value, options, languageIdentifier, resource);
} else {
model = new Model(value, languageIdentifier, resource);
model = new Model(value.toRawText(options), languageIdentifier, resource);
}
let modelId = MODEL_ID(model.uri);
......@@ -353,12 +361,25 @@ export class ModelServiceImpl implements IModelService {
return modelData;
}
public createRawText(provider: IRawTextProvider): editorCommon.IRawText {
let creationOptions = this.getCreationOptions();
return provider.toRawText(creationOptions);
public updateModel(model: editorCommon.IModel, value: string | IRawTextProvider): void {
let rawText: editorCommon.IRawText;
if (typeof value === 'string') {
rawText = RawText.fromStringWithModelOptions(value, model);
} else {
let creationOptions = this.getCreationOptions(model.getLanguageIdentifier().language);
rawText = value.toRawText(creationOptions);
}
// Return early if the text is already set in that form
if (model.equals(rawText)) {
return;
}
// Otherwise update model
model.setValueFromRawText(rawText);
}
public createModel(value: string | editorCommon.IRawText, modeOrPromise: TPromise<IMode> | IMode, resource: URI): editorCommon.IModel {
public createModel(value: string | IRawTextProvider, modeOrPromise: TPromise<IMode> | IMode, resource: URI): editorCommon.IModel {
let modelData: ModelData;
if (!modeOrPromise || TPromise.is(modeOrPromise)) {
......@@ -464,10 +485,13 @@ export class ModelServiceImpl implements IModelService {
for (let i = 0, len = events.length; i < len; i++) {
let e = events[i];
if (e.getType() === editorCommon.EventType.ModelLanguageChanged) {
this._onModelModeChanged.fire({
model: modelData.model,
oldModeId: (<editorCommon.IModelLanguageChangedEvent>e.getData()).oldLanguage
});
const model = modelData.model;
const oldModeId = (<editorCommon.IModelLanguageChangedEvent>e.getData()).oldLanguage;
const newModeId = model.getLanguageIdentifier().language;
const oldOptions = this.getCreationOptions(oldModeId);
const newOptions = this.getCreationOptions(newModeId);
ModelServiceImpl._setModelOptionsForModel(model, newOptions, oldOptions);
this._onModelModeChanged.fire({ model, oldModeId });
}
}
}
......
......@@ -212,7 +212,7 @@ export class ChangeIndentationSizeAction extends EditorAction {
return;
}
let creationOpts = modelService.getCreationOptions();
let creationOpts = modelService.getCreationOptions(model.getLanguageIdentifier().language);
const picks = [1, 2, 3, 4, 5, 6, 7, 8].map(n => ({
id: n.toString(),
label: n.toString(),
......@@ -288,7 +288,7 @@ export class DetectIndentation extends EditorAction {
return;
}
let creationOpts = modelService.getCreationOptions();
let creationOpts = modelService.getCreationOptions(model.getLanguageIdentifier().language);
model.detectIndentation(creationOpts.insertSpaces, creationOpts.tabSize);
}
}
......
......@@ -87,6 +87,24 @@ export class ModelBuilderResult implements IRawTextProvider {
this.hash = hash;
}
public getEntireContent(): string {
let lineFeedCnt = this.lines.length - 1;
if (lineFeedCnt === 0) {
// Just one line, EOL does not matter
return this.lines[0];
}
let EOL = '';
if (this.carriageReturnCnt > lineFeedCnt / 2) {
// More than half of the file contains \r\n ending lines
EOL = '\r\n';
} else {
// At least one line more ends in \n
EOL = '\n';
}
return this.lines.join(EOL);
}
public getFirstLine(): string {
return this.lines[0];
}
......
......@@ -210,7 +210,7 @@ export class MainThreadTextEditor {
if (newConfiguration.tabSize === 'auto' || newConfiguration.insertSpaces === 'auto') {
// one of the options was set to 'auto' => detect indentation
let creationOpts = this._modelService.getCreationOptions();
let creationOpts = this._modelService.getCreationOptions(this._model.getLanguageIdentifier().language);
let insertSpaces = creationOpts.insertSpaces;
let tabSize = creationOpts.tabSize;
......
......@@ -5,14 +5,13 @@
'use strict';
import { TPromise } from 'vs/base/common/winjs.base';
import { EndOfLinePreference, IModel, IRawText } 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';
import { ITextEditorModel } from 'vs/editor/common/services/resolverService';
import { IModeService } from 'vs/editor/common/services/modeService';
import { IRawTextProvider, IModelService } from 'vs/editor/common/services/modelService';
import { RawText } from 'vs/editor/common/model/textModel';
import { IDisposable } from 'vs/base/common/lifecycle';
/**
......@@ -80,24 +79,13 @@ export abstract class BaseTextEditorModel extends EditorModel implements ITextEd
private doCreateTextEditorModel(value: string | IRawTextProvider, mode: TPromise<IMode>, resource: URI): EditorModel {
let model = resource && this.modelService.getModel(resource);
if (!model) {
if (typeof value === 'string') {
model = this.modelService.createModel(value, mode, resource);
} else {
let rawText = this.modelService.createRawText(value);
model = this.modelService.createModel(rawText, mode, resource);
}
model = this.modelService.createModel(value, mode, resource);
this.createdEditorModel = true;
// Make sure we clean up when this model gets disposed
this.registerModelDisposeListener(model);
} else {
if (typeof value === 'string') {
model.setValue(value);
} else {
let rawText = this.modelService.createRawText(value);
model.setValueFromRawText(rawText);
}
this.modelService.updateModel(model, value);
this.modelService.setMode(model, mode);
}
......@@ -143,20 +131,7 @@ export abstract class BaseTextEditorModel extends EditorModel implements ITextEd
return;
}
let rawText: IRawText;
if (typeof newValue === 'string') {
rawText = RawText.fromStringWithModelOptions(newValue, this.textEditorModel);
} else {
rawText = this.modelService.createRawText(newValue);
}
// Return early if the text is already set in that form
if (this.textEditorModel.equals(rawText)) {
return;
}
// Otherwise update model
this.textEditorModel.setValueFromRawText(rawText);
this.modelService.updateModel(this.textEditorModel, newValue);
}
/**
......
......@@ -161,8 +161,7 @@ export class UntitledEditorModel extends BaseTextEditorModel implements IEncodin
return this.backupFileService.loadBackupResource(this.resource).then(backupResource => {
if (backupResource) {
return this.textFileService.resolveTextContent(backupResource, BACKUP_FILE_RESOLVE_OPTIONS).then(rawTextContent => {
let rawText = this.modelService.createRawText(rawTextContent.value);
return this.backupFileService.parseBackupContent(rawText);
return this.backupFileService.parseBackupContent(rawTextContent.value);
});
}
......
......@@ -62,11 +62,10 @@ export class SaveErrorHandler implements ISaveErrorHandler, IWorkbenchContributi
// Make sure our file from disk is resolved up to date
return this.textFileService.resolveTextContent(URI.file(resource.fsPath)).then(content => {
let codeEditorModel = this.modelService.getModel(resource);
let rawText = this.modelService.createRawText(content.value);
if (!codeEditorModel) {
codeEditorModel = this.modelService.createModel(rawText, this.modeService.getOrCreateModeByFilenameOrFirstLine(resource.fsPath), resource);
codeEditorModel = this.modelService.createModel(content.value, this.modeService.getOrCreateModeByFilenameOrFirstLine(resource.fsPath), resource);
} else {
codeEditorModel.setValueFromRawText(rawText);
this.modelService.updateModel(codeEditorModel, content.value);
}
return codeEditorModel;
......
......@@ -30,11 +30,10 @@ export class WalkThroughContentProvider implements ITextModelContentProvider, IW
public provideTextContent(resource: URI): TPromise<IModel> {
return this.textFileService.resolveTextContent(URI.file(resource.fsPath)).then(content => {
let codeEditorModel = this.modelService.getModel(resource);
let rawText = this.modelService.createRawText(content.value);
if (!codeEditorModel) {
codeEditorModel = this.modelService.createModel(rawText, this.modeService.getOrCreateModeByFilenameOrFirstLine(resource.fsPath), resource);
codeEditorModel = this.modelService.createModel(content.value, this.modeService.getOrCreateModeByFilenameOrFirstLine(resource.fsPath), resource);
} else {
codeEditorModel.setValueFromRawText(rawText);
this.modelService.updateModel(codeEditorModel, content.value);
}
return codeEditorModel;
......@@ -60,7 +59,6 @@ export class WalkThroughSnippetContentProvider implements ITextModelContentProvi
public provideTextContent(resource: URI): TPromise<IModel> {
return this.textFileService.resolveTextContent(URI.file(resource.fsPath)).then(content => {
let codeEditorModel = this.modelService.getModel(resource);
let rawText = this.modelService.createRawText(content.value);
if (!codeEditorModel) {
const j = parseInt(resource.fragment);
......@@ -76,14 +74,14 @@ export class WalkThroughSnippetContentProvider implements ITextModelContentProvi
return '';
};
const markdown = rawText.lines.join('\n');
const markdown = content.value.getEntireContent().replace(/\r\n/g, '\n'); // TODO: Can marked digest \r\n ?
marked(markdown, { renderer });
const modeId = this.modeService.getModeIdForLanguageName(languageName);
const mode = this.modeService.getOrCreateMode(modeId);
codeEditorModel = this.modelService.createModel(codeSnippet, mode, resource);
} else {
codeEditorModel.setValueFromRawText(rawText);
this.modelService.updateModel(codeEditorModel, content.value);
}
return codeEditorModel;
......
......@@ -8,7 +8,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 { IRawText } from 'vs/editor/common/editorCommon';
import { IRawTextProvider } from 'vs/editor/common/services/modelService';
import { IResolveContentOptions, IUpdateContentOptions } from 'vs/platform/files/common/files';
export const IBackupFileService = createDecorator<IBackupFileService>('backupFileService');
......@@ -55,10 +55,10 @@ export interface IBackupFileService {
* Parses backup raw text content into the content, removing the metadata that is also stored
* in the file.
*
* @param rawText The IRawText from a backup resource.
* @param rawText The IRawTextProvider from a backup resource.
* @return The backup file's backed up content.
*/
parseBackupContent(rawText: IRawText): string;
parseBackupContent(rawText: IRawTextProvider): string;
/**
* Discards the backup associated with a resource if it exists..
......
......@@ -16,7 +16,7 @@ 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 { IRawText } from 'vs/editor/common/editorCommon';
import { IRawTextProvider } from 'vs/editor/common/services/modelService';
import { IWindowService } from 'vs/platform/windows/common/windows';
export interface IBackupFilesModel {
......@@ -219,8 +219,15 @@ export class BackupFileService implements IBackupFileService {
});
}
public parseBackupContent(rawText: IRawText): string {
return rawText.lines.slice(1).join(rawText.EOL); // The first line of a backup text file is the file name
public parseBackupContent(rawTextProvider: IRawTextProvider): string {
let text = rawTextProvider.getEntireContent();
// The first line of a backup text file is the file name
let firstLineIndex = text.indexOf('\n');
if (firstLineIndex === -1) {
return '';
}
return text.substr(firstLineIndex + 1);
}
protected getBackupResource(resource: Uri): Uri {
......
......@@ -22,6 +22,9 @@ 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 { IRawTextProvider } from 'vs/editor/common/services/modelService';
import { IRawText, ITextModelCreationOptions } from 'vs/editor/common/editorCommon';
class TestEnvironmentService extends EnvironmentService {
constructor(private _backupHome: string, private _backupWorkspacesPath: string) {
......@@ -252,7 +255,18 @@ suite('BackupFileService', () => {
test('parseBackupContent', () => {
test('should separate metadata from content', () => {
const rawText = TextModel.toRawText('metadata\ncontent', TextModel.DEFAULT_CREATION_OPTIONS);
assert.equal(service.parseBackupContent(rawText), 'content');
const rawTextProvider: IRawTextProvider = {
getEntireContent: (): string => {
return rawText.lines.join(rawText.EOL);
},
getFirstLine: (): string => {
return rawText.lines[0];
},
toRawText: (opts: ITextModelCreationOptions): IRawText => {
return rawText;
}
};
assert.equal(service.parseBackupContent(rawTextProvider), 'content');
});
});
});
......
......@@ -413,8 +413,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
}
return this.textFileService.resolveTextContent(backup, BACKUP_FILE_RESOLVE_OPTIONS).then(backup => {
let rawText = this.modelService.createRawText(backup.value);
return this.backupFileService.parseBackupContent(rawText);
return this.backupFileService.parseBackupContent(backup.value);
}, error => null /* ignore errors */);
}
......
......@@ -77,8 +77,8 @@ suite('ExtHostLanguageFeatureCommands', function () {
instantiationService.stub(IModelService, <IModelService>{
_serviceBrand: IModelService,
getModel(): any { return model; },
createRawText(): any { throw new Error(); },
createModel(): any { throw new Error(); },
updateModel(): any { throw new Error(); },
setMode(): any { throw new Error(); },
destroyModel(): any { throw new Error(); },
getModels(): any { throw new Error(); },
......
......@@ -152,6 +152,9 @@ export class TestTextFileService extends TextFileService {
return this.fileService.resolveContent(resource, options).then((content) => {
const raw = RawText.fromString(content.value, { defaultEOL: 1, detectIndentation: false, insertSpaces: false, tabSize: 4, trimAutoWhitespace: false });
const rawTextProvider: IRawTextProvider = {
getEntireContent: (): string => {
return raw.lines.join(raw.EOL);
},
getFirstLine: (): string => {
return raw.lines[0];
},
......@@ -723,8 +726,8 @@ export class TestBackupFileService implements IBackupFileService {
return TPromise.as([]);
}
public parseBackupContent(rawText: IRawText): string {
return rawText.lines.join('\n');
public parseBackupContent(rawText: IRawTextProvider): string {
return rawText.getEntireContent();
}
public discardResourceBackup(resource: URI): TPromise<void> {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册