提交 70d9efea 编写于 作者: S Sandeep Somavarapu

#75079 Use URI for settings

上级 50e1c61c
......@@ -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();
......
......@@ -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));
......
......@@ -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);
......
......@@ -97,7 +97,7 @@ export interface IEnvironmentService {
appNameLong: string;
appQuality?: string;
appSettingsHome: string;
appSettingsPath: string;
settingsResource: URI;
appKeybindingsPath: string;
machineSettingsHome: string;
......
......@@ -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'); }
......
......@@ -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 = {
......
......@@ -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;
......
......@@ -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) };
}
......
......@@ -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
});
......
......@@ -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);
......
......@@ -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;
......
......@@ -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', () => {
......@@ -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);
......
......@@ -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 }> {
......@@ -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)));
});
});
......@@ -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);
......@@ -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);
......@@ -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);
......@@ -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);
......@@ -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);
......@@ -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(() => {
......@@ -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(() => {
......@@ -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(() => {
......@@ -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');
......@@ -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);
......
......@@ -44,6 +44,7 @@ import { TestBackupFileService, TestContextService, TestEditorGroupsService, Tes
import { FileService } from 'vs/workbench/services/files/common/fileService';
import { Schemas } from 'vs/base/common/network';
import { DiskFileSystemProvider } from 'vs/workbench/services/files/node/diskFileSystemProvider';
import { URI } from 'vs/base/common/uri';
interface Modifiers {
metaKey?: boolean;
......@@ -65,7 +66,7 @@ suite('KeybindingsEditing', () => {
instantiationService = new TestInstantiationService();
instantiationService.stub(IEnvironmentService, <IEnvironmentService>{ appKeybindingsPath: keybindingsFile, appSettingsPath: path.join(testDir, 'settings.json') });
instantiationService.stub(IEnvironmentService, <IEnvironmentService>{ appKeybindingsPath: keybindingsFile, settingsResource: URI.file(path.join(testDir, 'settings.json')) });
instantiationService.stub(IConfigurationService, ConfigurationService);
instantiationService.stub(IConfigurationService, 'getValue', { 'eol': '\n' });
instantiationService.stub(IConfigurationService, 'onDidUpdateConfiguration', () => { });
......
......@@ -524,9 +524,9 @@ export class PreferencesService extends Disposable implements IPreferencesServic
switch (configurationTarget) {
case ConfigurationTarget.USER:
case ConfigurationTarget.USER_LOCAL:
return URI.file(this.environmentService.appSettingsPath);
return this.environmentService.settingsResource;
case ConfigurationTarget.USER_REMOTE:
return URI.file(this.environmentService.appSettingsPath);
return this.environmentService.settingsResource;
case ConfigurationTarget.WORKSPACE:
if (this.contextService.getWorkbenchState() === WorkbenchState.EMPTY) {
return null;
......
......@@ -783,7 +783,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
}
// Check for global settings file
if (isEqual(this.resource, URI.file(this.environmentService.appSettingsPath), !isLinux)) {
if (isEqual(this.resource, this.environmentService.settingsResource, !isLinux)) {
return 'global-settings';
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册