提交 619dc7bd 编写于 作者: B Benjamin Pasero

textfiles - do not have VSBuffer on the layer of ITextFiles

上级 c7ea388c
......@@ -14,7 +14,6 @@ import { IWorkspaceUndoRedoElement, UndoRedoElementType, IUndoRedoService } from
import { URI } from 'vs/base/common/uri';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ILogService } from 'vs/platform/log/common/log';
import { VSBuffer } from 'vs/base/common/buffer';
interface IFileOperation {
uris: URI[];
......@@ -55,7 +54,7 @@ class CreateOperation implements IFileOperation {
constructor(
readonly newUri: URI,
readonly options: WorkspaceFileEditOptions,
readonly contents: VSBuffer | undefined,
readonly contents: string | undefined,
@IFileService private readonly _fileService: IFileService,
@ITextFileService private readonly _textFileService: ITextFileService,
@IInstantiationService private readonly _instaService: IInstantiationService,
......@@ -82,9 +81,10 @@ class DeleteOperation implements IFileOperation {
readonly options: WorkspaceFileEditOptions,
@IWorkingCopyFileService private readonly _workingCopyFileService: IWorkingCopyFileService,
@IFileService private readonly _fileService: IFileService,
@ITextFileService private readonly _textFileService: ITextFileService,
@IConfigurationService private readonly _configurationService: IConfigurationService,
@IInstantiationService private readonly _instaService: IInstantiationService,
@ILogService private readonly _logService: ILogService,
@ILogService private readonly _logService: ILogService
) { }
get uris() {
......@@ -100,9 +100,9 @@ class DeleteOperation implements IFileOperation {
return new Noop();
}
let contents: VSBuffer | undefined;
let contents: string | undefined;
try {
contents = (await this._fileService.readFile(this.oldUri)).value;
contents = (await this._textFileService.read(this.oldUri)).value;
} catch (err) {
this._logService.critical(err);
}
......
......@@ -152,7 +152,7 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
}
}
async create(resource: URI, value?: string | ITextSnapshot | VSBuffer, options?: ICreateFileOptions): Promise<IFileStatWithMetadata> {
async create(resource: URI, value?: string | ITextSnapshot, options?: ICreateFileOptions): Promise<IFileStatWithMetadata> {
// file operation participation
await this.workingCopyFileService.runFileOperationParticipants([{ target: resource, source: undefined }], FileOperation.CREATE);
......@@ -175,8 +175,8 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
return stat;
}
protected doCreate(resource: URI, value?: string | ITextSnapshot | VSBuffer, options?: ICreateFileOptions): Promise<IFileStatWithMetadata> {
return this.fileService.createFile(resource, value instanceof VSBuffer ? value : toBufferOrReadable(value), options);
protected doCreate(resource: URI, value?: string | ITextSnapshot, options?: ICreateFileOptions): Promise<IFileStatWithMetadata> {
return this.fileService.createFile(resource, toBufferOrReadable(value), options);
}
async write(resource: URI, value: string | ITextSnapshot, options?: IWriteTextFileOptions): Promise<IFileStatWithMetadata> {
......
......@@ -104,7 +104,7 @@ export interface ITextFileService extends IDisposable {
* Create a file. If the file exists it will be overwritten with the contents if
* the options enable to overwrite.
*/
create(resource: URI, contents?: string | ITextSnapshot | VSBuffer, options?: { overwrite?: boolean }): Promise<IFileStatWithMetadata>;
create(resource: URI, contents?: string | ITextSnapshot, options?: { overwrite?: boolean }): Promise<IFileStatWithMetadata>;
}
export interface IReadTextFileOptions extends IReadFileOptions {
......
......@@ -27,7 +27,6 @@ import { isWindows } from 'vs/base/common/platform';
import { readFileSync, statSync } from 'fs';
import { detectEncodingByBOM } from 'vs/workbench/services/textfile/test/node/encoding/encoding.test';
import { workbenchInstantiationService, TestNativeTextFileServiceWithEncodingOverrides } from 'vs/workbench/test/electron-browser/workbenchTestServices';
import { VSBuffer } from 'vs/base/common/buffer';
suite('Files - TextFileService i/o', function () {
const parentDir = getRandomTestPath(tmpdir(), 'vsctests', 'textfileservice');
......@@ -101,15 +100,6 @@ suite('Files - TextFileService i/o', function () {
assert.equal((await readFile(resource.fsPath)).toString(), 'Hello World');
});
test('create - no encoding - content provided (VSBuffer)', async () => {
const resource = URI.file(join(testDir, 'small_new.txt'));
await service.create(resource, VSBuffer.fromString('Hello World'));
assert.equal(await exists(resource.fsPath), true);
assert.equal((await readFile(resource.fsPath)).toString(), 'Hello World');
});
test('create - UTF 16 LE - no content', async () => {
const resource = URI.file(join(testDir, 'small_new.utf16le'));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册