Skip to content

Commit

Permalink
#75079 Use URI for settings
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 committed Jun 7, 2019
1 parent 50e1c61 commit 70d9efe
Show file tree
Hide file tree
Showing 16 changed files with 34 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ async function main(server: Server, initData: ISharedProcessInitData, configurat
disposables.push(logService);
logService.info('main', JSON.stringify(configuration));

const configurationService = new ConfigurationService(environmentService.appSettingsPath);
const configurationService = new ConfigurationService(environmentService.settingsResource.path);
disposables.push(configurationService);
await configurationService.initialize();

Expand Down
2 changes: 1 addition & 1 deletion src/vs/code/electron-main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class CodeMain {
process.once('exit', () => logService.dispose());
services.set(ILogService, logService);

services.set(IConfigurationService, new ConfigurationService(environmentService.appSettingsPath));
services.set(IConfigurationService, new ConfigurationService(environmentService.settingsResource.path));
services.set(ILifecycleService, new SyncDescriptor(LifecycleService));
services.set(IStateService, new SyncDescriptor(StateService));
services.set(IRequestService, new SyncDescriptor(RequestService));
Expand Down
2 changes: 1 addition & 1 deletion src/vs/code/node/cliProcessMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ export async function main(argv: ParsedArgs): Promise<void> {

await Promise.all([environmentService.appSettingsHome, environmentService.extensionsPath].map(p => mkdirp(p)));

const configurationService = new ConfigurationService(environmentService.appSettingsPath);
const configurationService = new ConfigurationService(environmentService.settingsResource.path);
await configurationService.initialize();

services.set(IEnvironmentService, environmentService);
Expand Down
2 changes: 1 addition & 1 deletion src/vs/platform/environment/common/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export interface IEnvironmentService {
appNameLong: string;
appQuality?: string;
appSettingsHome: string;
appSettingsPath: string;
settingsResource: URI;
appKeybindingsPath: string;

machineSettingsHome: string;
Expand Down
2 changes: 1 addition & 1 deletion src/vs/platform/environment/node/environmentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class EnvironmentService implements IEnvironmentService {
get appSettingsHome(): string { return path.join(this.userDataPath, 'User'); }

@memoize
get appSettingsPath(): string { return path.join(this.appSettingsHome, 'settings.json'); }
get settingsResource(): URI { return URI.file(path.join(this.appSettingsHome, 'settings.json')); }

@memoize
get machineSettingsHome(): string { return path.join(this.userDataPath, 'Machine'); }
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/browser/web.main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class CodeRendererMain extends Disposable {
environmentService.appRoot = '/web/';
environmentService.args = { _: [] };
environmentService.appSettingsHome = '/web/settings';
environmentService.appSettingsPath = this.configuration.settingsUri.path;
environmentService.settingsResource = this.configuration.settingsUri;
environmentService.appKeybindingsPath = '/web/settings/keybindings.json';
environmentService.logsPath = '/web/logs';
environmentService.debugExtensionHost = {
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/browser/web.simpleservices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export class SimpleWorkbenchEnvironmentService implements IWorkbenchEnvironmentS
appNameLong: string;
appQuality?: string;
appSettingsHome: string;
appSettingsPath: string;
settingsResource: URI;
appKeybindingsPath: string;
machineSettingsHome: string;
machineSettingsPath: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class PreferencesContribution implements IWorkbenchContribution {
}

// Global User Settings File
if (isEqual(resource, URI.file(this.environmentService.appSettingsPath), !isLinux)) {
if (isEqual(resource, this.environmentService.settingsResource, !isLinux)) {
return { override: this.preferencesService.openGlobalSettings(true, options, group) };
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ class PreferencesActionsContribution extends Disposable implements IWorkbenchCon
dark: URI.parse(require.toUrl(`vs/workbench/contrib/preferences/electron-browser/media/preferences-editor-inverse.svg`))
}
},
when: ResourceContextKey.Resource.isEqualTo(URI.file(environmentService.appSettingsPath).toString()),
when: ResourceContextKey.Resource.isEqualTo(environmentService.settingsResource.toString()),
group: 'navigation',
order: 1
});
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/electron-browser/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ class CodeRendererMain extends Disposable {
const configurationFileService = new ConfigurationFileService();
configurationFileService.fileService = fileService;

const workspaceService = new WorkspaceService({ userSettingsResource: URI.file(environmentService.appSettingsPath), remoteAuthority: this.configuration.remoteAuthority, configurationCache: new ConfigurationCache(environmentService) }, configurationFileService, remoteAgentService);
const workspaceService = new WorkspaceService({ userSettingsResource: environmentService.settingsResource, remoteAuthority: this.configuration.remoteAuthority, configurationCache: new ConfigurationCache(environmentService) }, configurationFileService, remoteAgentService);

try {
await workspaceService.initialize(payload);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ export class ConfigurationEditingService {

private getConfigurationFileResource(target: EditableConfigurationTarget, config: IConfigurationValue, relativePath: string, resource: URI | null | undefined): URI | null {
if (target === EditableConfigurationTarget.USER_LOCAL) {
return URI.file(this.environmentService.appSettingsPath);
return this.environmentService.settingsResource;
}
if (target === EditableConfigurationTarget.USER_REMOTE) {
return this.remoteSettingsResource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class SettingsTestEnvironmentService extends EnvironmentService {
super(args, _execPath);
}

get appSettingsPath(): string { return this.customAppSettingsHome; }
get settingsResource(): URI { return URI.file(this.customAppSettingsHome); }
}

suite('ConfigurationEditingService', () => {
Expand Down Expand Up @@ -105,7 +105,7 @@ suite('ConfigurationEditingService', () => {
instantiationService.stub(IEnvironmentService, environmentService);
const remoteAgentService = instantiationService.createInstance(RemoteAgentService, {});
instantiationService.stub(IRemoteAgentService, remoteAgentService);
const workspaceService = new WorkspaceService({ userSettingsResource: URI.file(environmentService.appSettingsPath), configurationCache: new ConfigurationCache(environmentService) }, new ConfigurationFileService(), remoteAgentService);
const workspaceService = new WorkspaceService({ userSettingsResource: environmentService.settingsResource, configurationCache: new ConfigurationCache(environmentService) }, new ConfigurationFileService(), remoteAgentService);
instantiationService.stub(IWorkspaceContextService, workspaceService);
return workspaceService.initialize(noWorkspace ? { id: '' } : { folder: URI.file(workspaceDir), id: createHash('md5').update(URI.file(workspaceDir).toString()).digest('hex') }).then(() => {
instantiationService.stub(IConfigurationService, workspaceService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class SettingsTestEnvironmentService extends EnvironmentService {
super(args, _execPath);
}

get appSettingsPath(): string { return this.customAppSettingsHome; }
get settingsResource(): URI { return URI.file(this.customAppSettingsHome); }
}

function setUpFolderWorkspace(folderName: string): Promise<{ parentDir: string, folderDir: string }> {
Expand Down Expand Up @@ -103,7 +103,7 @@ suite('WorkspaceContextService - Folder', () => {
workspaceResource = folderDir;
const globalSettingsFile = path.join(parentDir, 'settings.json');
const environmentService = new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, globalSettingsFile);
workspaceContextService = new WorkspaceService({ userSettingsResource: URI.file(environmentService.appSettingsPath), configurationCache: new ConfigurationCache(environmentService) }, new ConfigurationFileService(), new RemoteAgentService(<IWindowConfiguration>{}, environmentService, new RemoteAuthorityResolverService()));
workspaceContextService = new WorkspaceService({ userSettingsResource: environmentService.settingsResource, configurationCache: new ConfigurationCache(environmentService) }, new ConfigurationFileService(), new RemoteAgentService(<IWindowConfiguration>{}, environmentService, new RemoteAuthorityResolverService()));
return (<WorkspaceService>workspaceContextService).initialize(convertToWorkspacePayload(URI.file(folderDir)));
});
});
Expand Down Expand Up @@ -165,7 +165,7 @@ suite('WorkspaceContextService - Workspace', () => {
const environmentService = new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, path.join(parentDir, 'settings.json'));
const remoteAgentService = instantiationService.createInstance(RemoteAgentService, {});
instantiationService.stub(IRemoteAgentService, remoteAgentService);
const workspaceService = new WorkspaceService({ userSettingsResource: URI.file(environmentService.appSettingsPath), configurationCache: new ConfigurationCache(environmentService) }, new ConfigurationFileService(), remoteAgentService);
const workspaceService = new WorkspaceService({ userSettingsResource: environmentService.settingsResource, configurationCache: new ConfigurationCache(environmentService) }, new ConfigurationFileService(), remoteAgentService);

instantiationService.stub(IWorkspaceContextService, workspaceService);
instantiationService.stub(IConfigurationService, workspaceService);
Expand Down Expand Up @@ -225,7 +225,7 @@ suite('WorkspaceContextService - Workspace Editing', () => {
fileService.registerProvider(Schemas.file, new DiskFileSystemProvider(new NullLogService()));
const configurationFileService = new ConfigurationFileService();
configurationFileService.fileService = fileService;
const workspaceService = new WorkspaceService({ userSettingsResource: URI.file(environmentService.appSettingsPath), configurationCache: new ConfigurationCache(environmentService) }, configurationFileService, remoteAgentService);
const workspaceService = new WorkspaceService({ userSettingsResource: environmentService.settingsResource, configurationCache: new ConfigurationCache(environmentService) }, configurationFileService, remoteAgentService);

instantiationService.stub(IWorkspaceContextService, workspaceService);
instantiationService.stub(IConfigurationService, workspaceService);
Expand Down Expand Up @@ -486,7 +486,7 @@ suite('WorkspaceService - Initialization', () => {
fileService.registerProvider(Schemas.file, new DiskFileSystemProvider(new NullLogService()));
const configurationFileService = new ConfigurationFileService();
configurationFileService.fileService = fileService;
const workspaceService = new WorkspaceService({ userSettingsResource: URI.file(environmentService.appSettingsPath), configurationCache: new ConfigurationCache(environmentService) }, configurationFileService, remoteAgentService);
const workspaceService = new WorkspaceService({ userSettingsResource: environmentService.settingsResource, configurationCache: new ConfigurationCache(environmentService) }, configurationFileService, remoteAgentService);
instantiationService.stub(IWorkspaceContextService, workspaceService);
instantiationService.stub(IConfigurationService, workspaceService);
instantiationService.stub(IEnvironmentService, environmentService);
Expand Down Expand Up @@ -750,7 +750,7 @@ suite('WorkspaceConfigurationService - Folder', () => {
fileService.registerProvider(Schemas.file, new DiskFileSystemProvider(new NullLogService()));
const configurationFileService = new ConfigurationFileService();
configurationFileService.fileService = fileService;
const workspaceService = new WorkspaceService({ userSettingsResource: URI.file(environmentService.appSettingsPath), configurationCache: new ConfigurationCache(environmentService) }, configurationFileService, remoteAgentService);
const workspaceService = new WorkspaceService({ userSettingsResource: environmentService.settingsResource, configurationCache: new ConfigurationCache(environmentService) }, configurationFileService, remoteAgentService);
instantiationService.stub(IWorkspaceContextService, workspaceService);
instantiationService.stub(IConfigurationService, workspaceService);
instantiationService.stub(IEnvironmentService, environmentService);
Expand Down Expand Up @@ -1078,7 +1078,7 @@ suite('WorkspaceConfigurationService-Multiroot', () => {
fileService.registerProvider(Schemas.file, new DiskFileSystemProvider(new NullLogService()));
const configurationFileService = new ConfigurationFileService();
configurationFileService.fileService = fileService;
const workspaceService = new WorkspaceService({ userSettingsResource: URI.file(environmentService.appSettingsPath), configurationCache: new ConfigurationCache(environmentService) }, configurationFileService, remoteAgentService);
const workspaceService = new WorkspaceService({ userSettingsResource: environmentService.settingsResource, configurationCache: new ConfigurationCache(environmentService) }, configurationFileService, remoteAgentService);

instantiationService.stub(IWorkspaceContextService, workspaceService);
instantiationService.stub(IConfigurationService, workspaceService);
Expand Down Expand Up @@ -1108,21 +1108,21 @@ suite('WorkspaceConfigurationService-Multiroot', () => {
});

test('application settings are not read from workspace', () => {
fs.writeFileSync(environmentService.appSettingsPath, '{ "configurationService.workspace.applicationSetting": "userValue" }');
fs.writeFileSync(environmentService.settingsResource.fsPath, '{ "configurationService.workspace.applicationSetting": "userValue" }');
return jsonEditingServce.write(workspaceContextService.getWorkspace().configuration!, { key: 'settings', value: { 'configurationService.workspace.applicationSetting': 'workspaceValue' } }, true)
.then(() => testObject.reloadConfiguration())
.then(() => assert.equal(testObject.getValue('configurationService.workspace.applicationSetting'), 'userValue'));
});

test('machine settings are not read from workspace', () => {
fs.writeFileSync(environmentService.appSettingsPath, '{ "configurationService.workspace.machineSetting": "userValue" }');
fs.writeFileSync(environmentService.settingsResource.fsPath, '{ "configurationService.workspace.machineSetting": "userValue" }');
return jsonEditingServce.write(workspaceContextService.getWorkspace().configuration!, { key: 'settings', value: { 'configurationService.workspace.machineSetting': 'workspaceValue' } }, true)
.then(() => testObject.reloadConfiguration())
.then(() => assert.equal(testObject.getValue('configurationService.workspace.machineSetting'), 'userValue'));
});

test('workspace settings override user settings after defaults are registered ', () => {
fs.writeFileSync(environmentService.appSettingsPath, '{ "configurationService.workspace.newSetting": "userValue" }');
fs.writeFileSync(environmentService.settingsResource.fsPath, '{ "configurationService.workspace.newSetting": "userValue" }');
return jsonEditingServce.write(workspaceContextService.getWorkspace().configuration!, { key: 'settings', value: { 'configurationService.workspace.newSetting': 'workspaceValue' } }, true)
.then(() => testObject.reloadConfiguration())
.then(() => {
Expand All @@ -1141,21 +1141,21 @@ suite('WorkspaceConfigurationService-Multiroot', () => {
});

test('application settings are not read from workspace folder', () => {
fs.writeFileSync(environmentService.appSettingsPath, '{ "configurationService.workspace.applicationSetting": "userValue" }');
fs.writeFileSync(environmentService.settingsResource.fsPath, '{ "configurationService.workspace.applicationSetting": "userValue" }');
fs.writeFileSync(workspaceContextService.getWorkspace().folders[0].toResource('.vscode/settings.json').fsPath, '{ "configurationService.workspace.applicationSetting": "workspaceFolderValue" }');
return testObject.reloadConfiguration()
.then(() => assert.equal(testObject.getValue('configurationService.workspace.applicationSetting'), 'userValue'));
});

test('machine settings are not read from workspace folder', () => {
fs.writeFileSync(environmentService.appSettingsPath, '{ "configurationService.workspace.machineSetting": "userValue" }');
fs.writeFileSync(environmentService.settingsResource.fsPath, '{ "configurationService.workspace.machineSetting": "userValue" }');
fs.writeFileSync(workspaceContextService.getWorkspace().folders[0].toResource('.vscode/settings.json').fsPath, '{ "configurationService.workspace.machineSetting": "workspaceFolderValue" }');
return testObject.reloadConfiguration()
.then(() => assert.equal(testObject.getValue('configurationService.workspace.machineSetting'), 'userValue'));
});

test('application settings are not read from workspace folder after defaults are registered', () => {
fs.writeFileSync(environmentService.appSettingsPath, '{ "configurationService.workspace.testNewApplicationSetting": "userValue" }');
fs.writeFileSync(environmentService.settingsResource.fsPath, '{ "configurationService.workspace.testNewApplicationSetting": "userValue" }');
fs.writeFileSync(workspaceContextService.getWorkspace().folders[0].toResource('.vscode/settings.json').fsPath, '{ "configurationService.workspace.testNewApplicationSetting": "workspaceFolderValue" }');
return testObject.reloadConfiguration()
.then(() => {
Expand All @@ -1175,7 +1175,7 @@ suite('WorkspaceConfigurationService-Multiroot', () => {
});

test('application settings are not read from workspace folder after defaults are registered', () => {
fs.writeFileSync(environmentService.appSettingsPath, '{ "configurationService.workspace.testNewMachineSetting": "userValue" }');
fs.writeFileSync(environmentService.settingsResource.fsPath, '{ "configurationService.workspace.testNewMachineSetting": "userValue" }');
fs.writeFileSync(workspaceContextService.getWorkspace().folders[0].toResource('.vscode/settings.json').fsPath, '{ "configurationService.workspace.testNewMachineSetting": "workspaceFolderValue" }');
return testObject.reloadConfiguration()
.then(() => {
Expand Down Expand Up @@ -1229,7 +1229,7 @@ suite('WorkspaceConfigurationService-Multiroot', () => {
assert.equal(actual.workspaceFolder, undefined);
assert.equal(actual.value, 'isSet');

fs.writeFileSync(environmentService.appSettingsPath, '{ "configurationService.workspace.testResourceSetting": "userValue" }');
fs.writeFileSync(environmentService.settingsResource.fsPath, '{ "configurationService.workspace.testResourceSetting": "userValue" }');
return testObject.reloadConfiguration()
.then(() => {
actual = testObject.inspect('configurationService.workspace.testResourceSetting');
Expand Down Expand Up @@ -1481,7 +1481,7 @@ suite('WorkspaceConfigurationService - Remote Folder', () => {
const configurationFileService = new ConfigurationFileService();
configurationFileService.fileService = fileService;
const configurationCache: IConfigurationCache = { read: () => Promise.resolve(''), write: () => Promise.resolve(), remove: () => Promise.resolve() };
testObject = new WorkspaceService({ userSettingsResource: URI.file(environmentService.appSettingsPath), configurationCache, remoteAuthority }, configurationFileService, remoteAgentService);
testObject = new WorkspaceService({ userSettingsResource: environmentService.settingsResource, configurationCache, remoteAuthority }, configurationFileService, remoteAgentService);
instantiationService.stub(IWorkspaceContextService, testObject);
instantiationService.stub(IConfigurationService, testObject);
instantiationService.stub(IEnvironmentService, environmentService);
Expand Down

0 comments on commit 70d9efe

Please sign in to comment.