Skip to content

Commit bda864b

Browse files
committed
1 parent 32744a0 commit bda864b

File tree

5 files changed

+31
-11
lines changed

5 files changed

+31
-11
lines changed

src/vs/code/electron-browser/sharedProcess/sharedProcessMain.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ import { ipcSharedProcessTunnelChannelName, ISharedProcessTunnelService } from '
9494
import { SharedProcessTunnelService } from 'vs/platform/remote/node/sharedProcessTunnelService';
9595
import { ipcSharedProcessWorkerChannelName, ISharedProcessWorkerConfiguration, ISharedProcessWorkerService } from 'vs/platform/sharedProcess/common/sharedProcessWorkerService';
9696
import { SharedProcessWorkerService } from 'vs/platform/sharedProcess/electron-browser/sharedProcessWorkerService';
97+
import { IUserConfigurationFileService, UserConfigurationFileServiceId } from 'vs/platform/configuration/common/userConfigurationFileService';
9798

9899
class SharedProcessMain extends Disposable {
99100

@@ -218,6 +219,9 @@ class SharedProcessMain extends Disposable {
218219
storageService.initialize()
219220
]);
220221

222+
// User Configuration File
223+
services.set(IUserConfigurationFileService, ProxyChannel.toService<IUserConfigurationFileService>(mainProcessService.getChannel(UserConfigurationFileServiceId)));
224+
221225
// Request
222226
services.set(IRequestService, new SyncDescriptor(RequestService));
223227

src/vs/code/electron-main/app.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,8 +567,10 @@ export class CodeApplication extends Disposable {
567567
const fileSystemProviderChannel = new DiskFileSystemProviderChannel(diskFileSystemProvider, this.logService);
568568
mainProcessElectronServer.registerChannel('localFilesystem', fileSystemProviderChannel);
569569

570-
// Configuration
571-
mainProcessElectronServer.registerChannel(UserConfigurationFileServiceId, ProxyChannel.fromService(new UserConfigurationFileService(this.environmentMainService, this.fileService, this.logService)));
570+
// User Configuration File
571+
const userConfigurationFileService = new UserConfigurationFileService(this.environmentMainService, this.fileService, this.logService);
572+
mainProcessElectronServer.registerChannel(UserConfigurationFileServiceId, ProxyChannel.fromService(userConfigurationFileService));
573+
sharedProcessClient.then(client => client.registerChannel(UserConfigurationFileServiceId, ProxyChannel.fromService(userConfigurationFileService)));
572574

573575
// Update
574576
const updateChannel = new UpdateChannel(accessor.get(IUpdateService));

src/vs/platform/configuration/common/userConfigurationFileService.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ import { VSBuffer } from 'vs/base/common/buffer';
88
import { JSONPath, parse, ParseError } from 'vs/base/common/json';
99
import { setProperty } from 'vs/base/common/jsonEdit';
1010
import { Edit, FormattingOptions } from 'vs/base/common/jsonFormatter';
11-
import { URI } from 'vs/base/common/uri';
1211
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
13-
import { FileOperationError, FileOperationResult, IFileService } from 'vs/platform/files/common/files';
12+
import { FileOperationError, FileOperationResult, IFileService, IWriteFileOptions } from 'vs/platform/files/common/files';
1413
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
1514
import { ILogService } from 'vs/platform/log/common/log';
1615

@@ -31,6 +30,7 @@ export interface IUserConfigurationFileService {
3130
readonly _serviceBrand: undefined;
3231

3332
updateSettings(value: IJSONValue, formattingOptions: FormattingOptions): Promise<void>;
33+
write(value: VSBuffer, options?: IWriteFileOptions): Promise<void>;
3434
}
3535

3636
export class UserConfigurationFileService implements IUserConfigurationFileService {
@@ -48,12 +48,12 @@ export class UserConfigurationFileService implements IUserConfigurationFileServi
4848
}
4949

5050
async updateSettings(value: IJSONValue, formattingOptions: FormattingOptions): Promise<void> {
51-
return this.queue.queue(() => this.doWrite(this.environmentService.settingsResource, value, formattingOptions)); // queue up writes to prevent race conditions
51+
return this.queue.queue(() => this.doWrite(value, formattingOptions)); // queue up writes to prevent race conditions
5252
}
5353

54-
private async doWrite(resource: URI, jsonValue: IJSONValue, formattingOptions: FormattingOptions): Promise<void> {
55-
this.logService.trace(`${UserConfigurationFileServiceId}#write`, resource.toString(), jsonValue);
56-
const { value, mtime, etag } = await this.fileService.readFile(resource, { atomic: true });
54+
private async doWrite(jsonValue: IJSONValue, formattingOptions: FormattingOptions): Promise<void> {
55+
this.logService.trace(`${UserConfigurationFileServiceId}#write`, this.environmentService.settingsResource.toString(), jsonValue);
56+
const { value, mtime, etag } = await this.fileService.readFile(this.environmentService.settingsResource, { atomic: true });
5757
let content = value.toString();
5858

5959
const parseErrors: ParseError[] = [];
@@ -66,7 +66,7 @@ export class UserConfigurationFileService implements IUserConfigurationFileServi
6666
if (edit) {
6767
content = content.substring(0, edit.offset) + edit.content + content.substring(edit.offset + edit.length);
6868
try {
69-
await this.fileService.writeFile(resource, VSBuffer.fromString(content), { etag, mtime });
69+
await this.write(VSBuffer.fromString(content), { etag, mtime });
7070
} catch (error) {
7171
if ((<FileOperationError>error).fileOperationResult === FileOperationResult.FILE_MODIFIED_SINCE) {
7272
throw new Error(UserConfigurationErrorCode.ERROR_FILE_MODIFIED_SINCE);
@@ -75,6 +75,10 @@ export class UserConfigurationFileService implements IUserConfigurationFileServi
7575
}
7676
}
7777

78+
async write(content: VSBuffer, options?: IWriteFileOptions): Promise<void> {
79+
await this.fileService.writeFile(this.environmentService.settingsResource, content, options);
80+
}
81+
7882
private getEdits({ value, path }: IJSONValue, modelContent: string, formattingOptions: FormattingOptions): Edit[] {
7983
if (path.length) {
8084
return setProperty(modelContent, path, value, formattingOptions);

src/vs/platform/userDataSync/common/abstractSynchronizer.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ export abstract class AbstractFileSynchroniser extends AbstractSynchroniser {
760760
try {
761761
if (oldContent) {
762762
// file exists already
763-
await this.fileService.writeFile(this.file, VSBuffer.fromString(newContent), force ? undefined : oldContent);
763+
await this.writeFileContent(newContent, oldContent, force);
764764
} else {
765765
// file does not exist
766766
await this.fileService.createFile(this.file, VSBuffer.fromString(newContent), { overwrite: force });
@@ -775,6 +775,10 @@ export abstract class AbstractFileSynchroniser extends AbstractSynchroniser {
775775
}
776776
}
777777

778+
protected async writeFileContent(newContent: string, oldContent: IFileContent, force: boolean): Promise<void> {
779+
await this.fileService.writeFile(this.file, VSBuffer.fromString(newContent), force ? undefined : oldContent);
780+
}
781+
778782
private onFileChanges(e: FileChangesEvent): void {
779783
if (!e.contains(this.file)) {
780784
return;

src/vs/platform/userDataSync/common/settingsSync.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ import { URI } from 'vs/base/common/uri';
1212
import { localize } from 'vs/nls';
1313
import { ConfigurationTarget, IConfigurationService } from 'vs/platform/configuration/common/configuration';
1414
import { ConfigurationModelParser } from 'vs/platform/configuration/common/configurationModels';
15+
import { IUserConfigurationFileService } from 'vs/platform/configuration/common/userConfigurationFileService';
1516
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
1617
import { IExtensionManagementService } from 'vs/platform/extensionManagement/common/extensionManagement';
17-
import { FileOperationError, FileOperationResult, IFileService } from 'vs/platform/files/common/files';
18+
import { FileOperationError, FileOperationResult, IFileContent, IFileService } from 'vs/platform/files/common/files';
1819
import { IStorageService } from 'vs/platform/storage/common/storage';
1920
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
2021
import { AbstractInitializer, AbstractJsonFileSynchroniser, IAcceptResult, IFileResourcePreview, IMergeResult } from 'vs/platform/userDataSync/common/abstractSynchronizer';
@@ -62,6 +63,7 @@ export class SettingsSynchroniser extends AbstractJsonFileSynchroniser implement
6263
@IUserDataSyncResourceEnablementService userDataSyncResourceEnablementService: IUserDataSyncResourceEnablementService,
6364
@ITelemetryService telemetryService: ITelemetryService,
6465
@IExtensionManagementService private readonly extensionManagementService: IExtensionManagementService,
66+
@IUserConfigurationFileService private readonly userConfigurationFileService: IUserConfigurationFileService,
6567
) {
6668
super(environmentService.settingsResource, SyncResource.Settings, fileService, environmentService, storageService, userDataSyncStoreService, userDataSyncBackupStoreService, userDataSyncResourceEnablementService, telemetryService, logService, userDataSyncUtilService, configurationService);
6769
}
@@ -325,6 +327,10 @@ export class SettingsSynchroniser extends AbstractJsonFileSynchroniser implement
325327
return getIgnoredSettings(defaultIgnoredSettings, this.configurationService, content);
326328
}
327329

330+
protected override async writeFileContent(newContent: string, oldContent: IFileContent, force: boolean): Promise<void> {
331+
await this.userConfigurationFileService.write(VSBuffer.fromString(newContent), force ? undefined : { etag: oldContent.etag, mtime: oldContent.mtime });
332+
}
333+
328334
private validateContent(content: string): void {
329335
if (this.hasErrors(content)) {
330336
throw new UserDataSyncError(localize('errorInvalidSettings', "Unable to sync settings as there are errors/warning in settings file."), UserDataSyncErrorCode.LocalInvalidContent, this.resource);

0 commit comments

Comments
 (0)