Revert "Merge from vscode 81d7885dc2e9dc617e1522697a2966bc4025a45d (#5949)" (#5983)

This reverts commit d15a3fcc98.
This commit is contained in:
Karl Burtram
2019-06-11 12:35:58 -07:00
committed by GitHub
parent 95a50b7892
commit 5a7562a37b
926 changed files with 11394 additions and 19540 deletions

View File

@@ -21,8 +21,8 @@ import { extname, join } from 'vs/base/common/path';
import { equals } from 'vs/base/common/objects';
import { Schemas } from 'vs/base/common/network';
import { IConfigurationModel, compare } from 'vs/platform/configuration/common/configuration';
import { createSHA1 } from 'vs/base/browser/hash';
import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
import { hash } from 'vs/base/common/hash';
export class RemoteUserConfiguration extends Disposable {
@@ -672,7 +672,7 @@ class CachedFolderConfiguration extends Disposable implements IFolderConfigurati
readonly onDidChange: Event<void> = this._onDidChange.event;
private configurationModel: ConfigurationModel;
private readonly key: ConfigurationKey;
private readonly key: Thenable<ConfigurationKey>;
constructor(
folder: URI,
@@ -680,13 +680,14 @@ class CachedFolderConfiguration extends Disposable implements IFolderConfigurati
private readonly configurationCache: IConfigurationCache
) {
super();
this.key = { type: 'folder', key: hash(join(folder.path, configFolderRelativePath)).toString(16) };
this.key = createSHA1(join(folder.path, configFolderRelativePath)).then(key => ({ type: 'folder', key }));
this.configurationModel = new ConfigurationModel();
}
async loadConfiguration(): Promise<ConfigurationModel> {
try {
const contents = await this.configurationCache.read(this.key);
const key = await this.key;
const contents = await this.configurationCache.read(key);
const parsed: IConfigurationModel = JSON.parse(contents.toString());
this.configurationModel = new ConfigurationModel(parsed.contents, parsed.keys, parsed.overrides);
} catch (e) {
@@ -695,10 +696,11 @@ class CachedFolderConfiguration extends Disposable implements IFolderConfigurati
}
async updateConfiguration(configurationModel: ConfigurationModel): Promise<void> {
const key = await this.key;
if (configurationModel.keys.length) {
await this.configurationCache.write(this.key, JSON.stringify(configurationModel.toJSON()));
await this.configurationCache.write(key, JSON.stringify(configurationModel.toJSON()));
} else {
await this.configurationCache.remove(this.key);
await this.configurationCache.remove(key);
}
}

View File

@@ -1,22 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IConfigurationCache, ConfigurationKey } from 'vs/workbench/services/configuration/common/configuration';
export class ConfigurationCache implements IConfigurationCache {
constructor() {
}
async read(key: ConfigurationKey): Promise<string> {
return '';
}
async write(key: ConfigurationKey, content: string): Promise<void> {
}
async remove(key: ConfigurationKey): Promise<void> {
}
}

View File

@@ -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 this.environmentService.settingsResource;
return URI.file(this.environmentService.appSettingsPath);
}
if (target === EditableConfigurationTarget.USER_REMOTE) {
return this.remoteSettingsResource;

View File

@@ -39,11 +39,10 @@ export class JSONEditingService implements IJSONEditingService {
return Promise.resolve(this.queue.queue(() => this.doWriteConfiguration(resource, value, save))); // queue up writes to prevent race conditions
}
private async doWriteConfiguration(resource: URI, value: IJSONValue, save: boolean): Promise<void> {
const reference = await this.resolveAndValidate(resource, save);
await this.writeToBuffer(reference.object.textEditorModel, value);
reference.dispose();
private doWriteConfiguration(resource: URI, value: IJSONValue, save: boolean): Promise<void> {
return this.resolveAndValidate(resource, save)
.then(reference => this.writeToBuffer(reference.object.textEditorModel, value)
.then(() => reference.dispose()));
}
private async writeToBuffer(model: ITextModel, value: IJSONValue): Promise<any> {
@@ -98,21 +97,21 @@ export class JSONEditingService implements IJSONEditingService {
return parseErrors.length > 0;
}
private async resolveAndValidate(resource: URI, checkDirty: boolean): Promise<IReference<IResolvedTextEditorModel>> {
const reference = await this.resolveModelReference(resource);
private resolveAndValidate(resource: URI, checkDirty: boolean): Promise<IReference<IResolvedTextEditorModel>> {
return this.resolveModelReference(resource)
.then(reference => {
const model = reference.object.textEditorModel;
const model = reference.object.textEditorModel;
if (this.hasParseErrors(model)) {
return this.reject<IReference<IResolvedTextEditorModel>>(JSONEditingErrorCode.ERROR_INVALID_FILE);
}
if (this.hasParseErrors(model)) {
return this.reject<IReference<IResolvedTextEditorModel>>(JSONEditingErrorCode.ERROR_INVALID_FILE);
}
// Target cannot be dirty if not writing into buffer
if (checkDirty && this.textFileService.isDirty(resource)) {
return this.reject<IReference<IResolvedTextEditorModel>>(JSONEditingErrorCode.ERROR_FILE_DIRTY);
}
return reference;
// Target cannot be dirty if not writing into buffer
if (checkDirty && this.textFileService.isDirty(resource)) {
return this.reject<IReference<IResolvedTextEditorModel>>(JSONEditingErrorCode.ERROR_FILE_DIRTY);
}
return reference;
});
}
private reject<T>(code: JSONEditingErrorCode): Promise<T> {

View File

@@ -47,7 +47,7 @@ class SettingsTestEnvironmentService extends EnvironmentService {
super(args, _execPath);
}
get settingsResource(): URI { return URI.file(this.customAppSettingsHome); }
get appSettingsPath(): string { return this.customAppSettingsHome; }
}
suite('ConfigurationEditingService', () => {
@@ -106,7 +106,7 @@ suite('ConfigurationEditingService', () => {
instantiationService.stub(IEnvironmentService, environmentService);
const remoteAgentService = instantiationService.createInstance(RemoteAgentService, {});
instantiationService.stub(IRemoteAgentService, remoteAgentService);
const workspaceService = new WorkspaceService({ userSettingsResource: environmentService.settingsResource, configurationCache: new ConfigurationCache(environmentService) }, new ConfigurationFileService(), remoteAgentService);
const workspaceService = new WorkspaceService({ userSettingsResource: URI.file(environmentService.appSettingsPath), 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);
@@ -187,7 +187,7 @@ suite('ConfigurationEditingService', () => {
test('do not notify error', () => {
instantiationService.stub(ITextFileService, 'isDirty', true);
const target = sinon.stub();
instantiationService.stub(INotificationService, <INotificationService>{ prompt: target, _serviceBrand: null!, notify: null!, error: null!, info: null!, warn: null!, status: null! });
instantiationService.stub(INotificationService, <INotificationService>{ prompt: target, _serviceBrand: null, notify: null!, error: null!, info: null!, warn: null! });
return testObject.writeConfiguration(EditableConfigurationTarget.USER_LOCAL, { key: 'configurationEditing.service.testSetting', value: 'value' }, { donotNotifyError: true })
.then(() => assert.fail('Should fail with ERROR_CONFIGURATION_FILE_DIRTY error.'),
(error: ConfigurationEditingError) => {

View File

@@ -44,7 +44,6 @@ import { ConfigurationCache } from 'vs/workbench/services/configuration/node/con
import { ConfigurationFileService } from 'vs/workbench/services/configuration/node/configurationFileService';
import { IRemoteAgentEnvironment } from 'vs/platform/remote/common/remoteAgentEnvironment';
import { IConfigurationCache } from 'vs/workbench/services/configuration/common/configuration';
import { VSBuffer } from 'vs/base/common/buffer';
class SettingsTestEnvironmentService extends EnvironmentService {
@@ -52,7 +51,7 @@ class SettingsTestEnvironmentService extends EnvironmentService {
super(args, _execPath);
}
get settingsResource(): URI { return URI.file(this.customAppSettingsHome); }
get appSettingsPath(): string { return this.customAppSettingsHome; }
}
function setUpFolderWorkspace(folderName: string): Promise<{ parentDir: string, folderDir: string }> {
@@ -154,7 +153,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: environmentService.settingsResource, configurationCache, remoteAuthority }, configurationFileService, remoteAgentService);
testObject = new WorkspaceService({ userSettingsResource: URI.file(environmentService.appSettingsPath), configurationCache, remoteAuthority }, configurationFileService, remoteAgentService);
instantiationService.stub(IWorkspaceContextService, testObject);
instantiationService.stub(IConfigurationService, testObject);
instantiationService.stub(IEnvironmentService, environmentService);
@@ -248,26 +247,26 @@ suite('WorkspaceConfigurationService - Remote Folder', () => {
return promise;
});
test('update remote settings', async () => {
registerRemoteFileSystemProvider();
resolveRemoteEnvironment();
await initialize();
assert.equal(testObject.getValue('configurationService.remote.machineSetting'), 'isSet');
const promise = new Promise((c, e) => {
testObject.onDidChangeConfiguration(event => {
try {
assert.equal(event.source, ConfigurationTarget.USER);
assert.deepEqual(event.affectedKeys, ['configurationService.remote.machineSetting']);
assert.equal(testObject.getValue('configurationService.remote.machineSetting'), 'remoteValue');
c();
} catch (error) {
e(error);
}
});
});
await instantiationService.get(IFileService).writeFile(URI.file(remoteSettingsFile), VSBuffer.fromString('{ "configurationService.remote.machineSetting": "remoteValue" }'));
return promise;
});
// test('update remote settings', async () => {
// registerRemoteFileSystemProvider();
// resolveRemoteEnvironment();
// await initialize();
// assert.equal(testObject.getValue('configurationService.remote.machineSetting'), 'isSet');
// const promise = new Promise((c, e) => {
// testObject.onDidChangeConfiguration(event => {
// try {
// assert.equal(event.source, ConfigurationTarget.USER);
// assert.deepEqual(event.affectedKeys, ['configurationService.remote.machineSetting']);
// assert.equal(testObject.getValue('configurationService.remote.machineSetting'), 'remoteValue');
// c();
// } catch (error) {
// e(error);
// }
// });
// });
// fs.writeFileSync(remoteSettingsFile, '{ "configurationService.remote.machineSetting": "remoteValue" }');
// return promise;
// });
test('machine settings in local user settings does not override defaults', async () => {
fs.writeFileSync(globalSettingsFile, '{ "configurationService.remote.machineSetting": "globalValue" }');