提交 47372d50 编写于 作者: B Benjamin Pasero

files2 - 💄

上级 d8b9a524
......@@ -576,7 +576,7 @@ class Launch extends AbstractLaunch implements ILaunch {
}
created = true; // pin only if config file is created #8727
return this.textFileService.update(resource, content).then(() => {
return this.textFileService.write(resource, content).then(() => {
// convert string into IContent; see #32135
return content;
});
......
......@@ -2134,7 +2134,7 @@ export abstract class AbstractConfigureRecommendedExtensionsAction extends Actio
return Promise.resolve(this.fileService.resolveContent(extensionsFileResource)).then(content => {
return { created: false, extensionsFileResource, content: content.value };
}, err => {
return this.textFileService.update(extensionsFileResource, ExtensionsConfigurationInitialContent).then(() => {
return this.textFileService.write(extensionsFileResource, ExtensionsConfigurationInitialContent).then(() => {
return { created: true, extensionsFileResource, content: ExtensionsConfigurationInitialContent };
});
});
......
......@@ -139,7 +139,7 @@ async function createSnippetFile(scope: string, defaultPath: URI, windowService:
return undefined;
}
await textFileService.update(resource, [
await textFileService.write(resource, [
'{',
'\t// Place your ' + scope + ' snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and ',
'\t// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope ',
......@@ -185,7 +185,7 @@ async function createLanguageSnippetFile(pick: ISnippetPick, fileService: IFileS
'\t// }',
'}'
].join('\n');
await textFileService.update(URI.file(pick.filepath), contents);
await textFileService.write(URI.file(pick.filepath), contents);
}
CommandsRegistry.registerCommand(id, async (accessor): Promise<any> => {
......
......@@ -78,7 +78,7 @@ class PartsSplash {
sideBarWidth: getTotalWidth(this._layoutService.getContainer(Parts.SIDEBAR_PART)),
statusBarHeight: getTotalHeight(this._layoutService.getContainer(Parts.STATUSBAR_PART)),
};
this._textFileService.update(
this._textFileService.write(
URI.file(join(this._envService.userDataPath, 'rapid_render.json')),
JSON.stringify({
id: PartsSplash._splashElementId,
......
......@@ -29,7 +29,6 @@ import { INotificationService, Severity } from 'vs/platform/notification/common/
import { IPreferencesService } from 'vs/workbench/services/preferences/common/preferences';
import { withUndefinedAsNull, withNullAsUndefined } from 'vs/base/common/types';
import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
import { VSBuffer } from 'vs/base/common/buffer';
export const enum ConfigurationEditingErrorCode {
......@@ -376,7 +375,7 @@ export class ConfigurationEditingService {
private async resolveModelReference(resource: URI): Promise<IReference<IResolvedTextEditorModel>> {
const exists = await this.fileService.exists(resource);
if (!exists) {
await this.fileService.writeFile(resource, VSBuffer.fromString('{}'));
await this.textFileService.write(resource, '{}');
}
return this.textModelResolverService.createModelReference(resource);
}
......
......@@ -20,7 +20,6 @@ import { ITextModelService, IResolvedTextEditorModel } from 'vs/editor/common/se
import { IJSONEditingService, IJSONValue, JSONEditingError, JSONEditingErrorCode } from 'vs/workbench/services/configuration/common/jsonEditing';
import { ITextModel } from 'vs/editor/common/model';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { VSBuffer } from 'vs/base/common/buffer';
export class JSONEditingService implements IJSONEditingService {
......@@ -87,7 +86,7 @@ export class JSONEditingService implements IJSONEditingService {
private async resolveModelReference(resource: URI): Promise<IReference<IResolvedTextEditorModel>> {
const exists = await this.fileService.exists(resource);
if (!exists) {
await this.fileService.writeFile(resource, VSBuffer.fromString('{}'));
await this.textFileService.write(resource, '{}');
}
return this.textModelResolverService.createModelReference(resource);
}
......
......@@ -43,7 +43,6 @@ import { NullLogService } from 'vs/platform/log/common/log';
import { DiskFileSystemProvider } from 'vs/workbench/services/files2/node/diskFileSystemProvider';
import { ConfigurationCache } from 'vs/workbench/services/configuration/node/configurationCache';
import { ConfigurationFileService } from 'vs/workbench/services/configuration/node/configurationFileService';
import { VSBuffer } from 'vs/base/common/buffer';
class SettingsTestEnvironmentService extends EnvironmentService {
......@@ -367,7 +366,7 @@ suite('WorkspaceContextService - Workspace Editing', () => {
});
const workspace = { folders: [{ path: folders[0].uri.fsPath }, { path: folders[1].uri.fsPath }] };
await instantiationService.get(IFileService).writeFile(testObject.getWorkspace().configuration!, VSBuffer.fromString(JSON.stringify(workspace, null, '\t')));
await instantiationService.get(ITextFileService).write(testObject.getWorkspace().configuration!, JSON.stringify(workspace, null, '\t'));
});
test('update folders (remove last and add to end)', () => {
......
......@@ -211,7 +211,7 @@ export class KeybindingsEditingService extends Disposable implements IKeybinding
return this.fileService.exists(this.resource)
.then(exists => {
const EOL = this.configurationService.getValue('files', { overrideIdentifier: 'json' })['eol'];
const result: Promise<any> = exists ? Promise.resolve(null) : this.textFileService.update(this.resource, this.getEmptyContent(EOL));
const result: Promise<any> = exists ? Promise.resolve(null) : this.textFileService.write(this.resource, this.getEmptyContent(EOL));
return result.then(() => this.textModelResolverService.createModelReference(this.resource));
});
}
......
......@@ -557,7 +557,7 @@ export class PreferencesService extends Disposable implements IPreferencesServic
private createIfNotExists(resource: URI, contents: string): Promise<any> {
return this.fileService.resolveContent(resource, { acceptTextOnly: true }).then(undefined, error => {
if ((<FileOperationError>error).fileOperationResult === FileOperationResult.FILE_NOT_FOUND) {
return this.textFileService.update(resource, contents).then(undefined, error => {
return this.textFileService.write(resource, contents).then(undefined, error => {
return Promise.reject(new Error(nls.localize('fail.createSettings', "Unable to create '{0}' ({1}).", this.labelService.getUriLabel(resource, { relative: true }), error)));
});
}
......
......@@ -703,12 +703,12 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
// Save to Disk
// mark the save operation as currently pending with the versionId (it might have changed from a save participant triggering)
this.logService.trace(`doSave(${versionId}) - before updateContent()`, this.resource);
this.logService.trace(`doSave(${versionId}) - before write()`, this.resource);
const snapshot = this.createSnapshot();
if (!snapshot) {
throw new Error('Invalid snapshot');
}
return this.saveSequentializer.setPending(newVersionId, this.textFileService.update(this.lastResolvedDiskStat.resource, snapshot, {
return this.saveSequentializer.setPending(newVersionId, this.textFileService.write(this.lastResolvedDiskStat.resource, snapshot, {
overwriteReadonly: options.overwriteReadonly,
overwriteEncoding: options.overwriteEncoding,
mtime: this.lastResolvedDiskStat.mtime,
......@@ -716,7 +716,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
etag: this.lastResolvedDiskStat.etag,
writeElevated: options.writeElevated
}).then(stat => {
this.logService.trace(`doSave(${versionId}) - after updateContent()`, this.resource);
this.logService.trace(`doSave(${versionId}) - after write()`, this.resource);
// Update dirty state unless model has changed meanwhile
if (versionId === this.versionId) {
......@@ -849,7 +849,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
throw new Error('invalid snapshot');
}
return this.saveSequentializer.setPending(versionId, this.textFileService.update(this.lastResolvedDiskStat.resource, snapshot, {
return this.saveSequentializer.setPending(versionId, this.textFileService.write(this.lastResolvedDiskStat.resource, snapshot, {
mtime: this.lastResolvedDiskStat.mtime,
encoding: this.getEncoding(),
etag: this.lastResolvedDiskStat.etag
......
......@@ -399,8 +399,10 @@ export class TextFileService extends Disposable implements ITextFileService {
return stat;
}
update(resource: URI, value: string | ITextSnapshot, options?: IUpdateContentOptions): Promise<IFileStatWithMetadata> {
return this.fileService.updateContent(resource, value, options);
async write(resource: URI, value: string | ITextSnapshot, options?: IUpdateContentOptions): Promise<IFileStatWithMetadata> {
const stat = await this.fileService.updateContent(resource, value, options);
return stat;
}
async delete(resource: URI, options?: { useTrash?: boolean, recursive?: boolean }): Promise<void> {
......@@ -802,7 +804,7 @@ export class TextFileService extends Disposable implements ITextFileService {
// create target model adhoc if file does not exist yet
if (!targetExists) {
await this.update(target, '');
await this.create(target, '');
}
targetModel = await this.models.loadOrCreate(target);
......
......@@ -355,7 +355,7 @@ export interface ITextFileService extends IDisposable {
/**
* Update a file with given contents.
*/
update(resource: URI, value: string | ITextSnapshot, options?: IUpdateContentOptions): Promise<IFileStatWithMetadata>;
write(resource: URI, value: string | ITextSnapshot, options?: IUpdateContentOptions): Promise<IFileStatWithMetadata>;
/**
* Delete a file. If the file is dirty, it will get reverted and then deleted from disk.
......
......@@ -31,7 +31,7 @@ import { mnemonicButtonLabel } from 'vs/base/common/labels';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { ILabelService } from 'vs/platform/label/common/label';
import { VSBuffer } from 'vs/base/common/buffer';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
export class WorkspaceEditingService implements IWorkspaceEditingService {
......@@ -47,7 +47,8 @@ export class WorkspaceEditingService implements IWorkspaceEditingService {
@IBackupFileService private readonly backupFileService: IBackupFileService,
@INotificationService private readonly notificationService: INotificationService,
@ICommandService private readonly commandService: ICommandService,
@IFileService private readonly fileSystemService: IFileService,
@IFileService private readonly fileService: IFileService,
@ITextFileService private readonly textFileService: ITextFileService,
@IWindowsService private readonly windowsService: IWindowsService,
@IWorkspacesService private readonly workspaceService: IWorkspacesService,
@IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService,
......@@ -297,9 +298,9 @@ export class WorkspaceEditingService implements IWorkspaceEditingService {
}
// Read the contents of the workspace file, update it to new location and save it.
const raw = await this.fileSystemService.resolveContent(configPathURI);
const raw = await this.fileService.resolveContent(configPathURI);
const newRawWorkspaceContents = rewriteWorkspaceFileForNewLocation(raw.value, configPathURI, targetConfigPathURI);
await this.fileSystemService.createFile2(targetConfigPathURI, VSBuffer.fromString(newRawWorkspaceContents), { overwrite: true });
await this.textFileService.create(targetConfigPathURI, newRawWorkspaceContents, { overwrite: true });
}
private handleWorkspaceConfigurationEditingError(error: JSONEditingError): Promise<void> {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册