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

files2 - 💄

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