提交 e4f0dec7 编写于 作者: D Daniel Imms

Remove usage of fs in common/ layer

上级 701fe8cf
...@@ -19,9 +19,6 @@ import { IDisposable, dispose } from 'vs/base/common/lifecycle'; ...@@ -19,9 +19,6 @@ import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import Event, { Emitter } from 'vs/base/common/event'; import Event, { Emitter } from 'vs/base/common/event';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
// TODO: This file cannot depend on native node modules
import fs = require('fs');
/** /**
* An editor input to be used for untitled text buffers. * An editor input to be used for untitled text buffers.
*/ */
...@@ -50,7 +47,6 @@ export class UntitledEditorInput extends AbstractUntitledEditorInput { ...@@ -50,7 +47,6 @@ export class UntitledEditorInput extends AbstractUntitledEditorInput {
@ITextFileService private textFileService: ITextFileService @ITextFileService private textFileService: ITextFileService
) { ) {
super(); super();
console.log('UntitledEditorInput constructor', resource, hasAssociatedFilePath, modeId);
this.resource = resource; this.resource = resource;
this.hasAssociatedFilePath = hasAssociatedFilePath; this.hasAssociatedFilePath = hasAssociatedFilePath;
this.modeId = modeId; this.modeId = modeId;
...@@ -138,21 +134,25 @@ export class UntitledEditorInput extends AbstractUntitledEditorInput { ...@@ -138,21 +134,25 @@ export class UntitledEditorInput extends AbstractUntitledEditorInput {
return TPromise.as(this.cachedModel); return TPromise.as(this.cachedModel);
} }
// Otherwise Create Model and load // Otherwise Create Model and load, restoring from backup if necessary
const model = this.createModel(); let restorePromise: TPromise<string>;
return model.load().then((resolvedModel: UntitledEditorModel) => { if (this.restoreResource) {
this.cachedModel = resolvedModel; restorePromise = this.textFileService.resolveTextContent(this.restoreResource).then(rawTextContent => rawTextContent.value.lines.join('\n'));
} else {
restorePromise = TPromise.as('');
}
return restorePromise.then(content => {
const model = this.createModel(content);
return model.load().then((resolvedModel: UntitledEditorModel) => {
this.cachedModel = resolvedModel;
return this.cachedModel; return this.cachedModel;
});
}); });
} }
private createModel(): UntitledEditorModel { private createModel(content: string): UntitledEditorModel {
let content = '';
if (this.restoreResource) {
// TODO: This loading should probably go through fileService, fs cannot be a dependency in common/
content = fs.readFileSync(this.restoreResource.fsPath, 'utf8');
}
const model = this.instantiationService.createInstance(UntitledEditorModel, content, this.modeId, this.resource, this.hasAssociatedFilePath); const model = this.instantiationService.createInstance(UntitledEditorModel, content, this.modeId, this.resource, this.hasAssociatedFilePath);
// re-emit some events from the model // re-emit some events from the model
......
...@@ -177,7 +177,7 @@ export class Workbench implements IPartService { ...@@ -177,7 +177,7 @@ export class Workbench implements IPartService {
return { resource: Uri.file(filePath), options: { pinned: true } }; return { resource: Uri.file(filePath), options: { pinned: true } };
}); });
options.untitledFilesToRestore = this.backupService.getBackupUntitledFiles(workspace.resource.fsPath).map(untitledFilePath => { options.untitledFilesToRestore = this.backupService.getBackupUntitledFiles(workspace.resource.fsPath).map(untitledFilePath => {
return { resource: Uri.from({ path: untitledFilePath, scheme: 'untitled' }), options: { pinned: true } }; return { resource: Uri.file(untitledFilePath), options: { pinned: true } };
}); });
this.hasFilesToCreateOpenOrDiff = this.hasFilesToCreateOpenOrDiff =
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册