Merge from vscode 8e0f348413f4f616c23a88ae30030efa85811973 (#6381)

* Merge from vscode 8e0f348413f4f616c23a88ae30030efa85811973

* disable strict null check
This commit is contained in:
Anthony Dresser
2019-07-15 22:35:46 -07:00
committed by GitHub
parent f720ec642f
commit 0b7e7ddbf9
2406 changed files with 59140 additions and 35464 deletions

View File

@@ -9,10 +9,10 @@ import { Event, Emitter } from 'vs/base/common/event';
import * as errors from 'vs/base/common/errors';
import { Disposable, IDisposable, dispose, toDisposable } from 'vs/base/common/lifecycle';
import { RunOnceScheduler } from 'vs/base/common/async';
import { FileChangeType, FileChangesEvent } from 'vs/platform/files/common/files';
import { FileChangeType, FileChangesEvent, IFileService } from 'vs/platform/files/common/files';
import { ConfigurationModel, ConfigurationModelParser } from 'vs/platform/configuration/common/configurationModels';
import { WorkspaceConfigurationModelParser, StandaloneConfigurationModelParser } from 'vs/workbench/services/configuration/common/configurationModels';
import { FOLDER_SETTINGS_PATH, TASKS_CONFIGURATION_KEY, FOLDER_SETTINGS_NAME, LAUNCH_CONFIGURATION_KEY, IConfigurationCache, ConfigurationKey, IConfigurationFileService, REMOTE_MACHINE_SCOPES, FOLDER_SCOPES, WORKSPACE_SCOPES } from 'vs/workbench/services/configuration/common/configuration';
import { FOLDER_SETTINGS_PATH, TASKS_CONFIGURATION_KEY, FOLDER_SETTINGS_NAME, LAUNCH_CONFIGURATION_KEY, IConfigurationCache, ConfigurationKey, REMOTE_MACHINE_SCOPES, FOLDER_SCOPES, WORKSPACE_SCOPES, ConfigurationFileService } from 'vs/workbench/services/configuration/common/configuration';
import { IStoredWorkspaceFolder, IWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
import { JSONEditingService } from 'vs/workbench/services/configuration/common/jsonEditingService';
import { WorkbenchState, IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
@@ -20,15 +20,54 @@ import { ConfigurationScope } from 'vs/platform/configuration/common/configurati
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 { IConfigurationModel } from 'vs/platform/configuration/common/configuration';
import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
import { hash } from 'vs/base/common/hash';
export class UserConfiguration extends Disposable {
private readonly parser: ConfigurationModelParser;
private readonly reloadConfigurationScheduler: RunOnceScheduler;
protected readonly _onDidChangeConfiguration: Emitter<ConfigurationModel> = this._register(new Emitter<ConfigurationModel>());
readonly onDidChangeConfiguration: Event<ConfigurationModel> = this._onDidChangeConfiguration.event;
constructor(
private readonly userSettingsResource: URI,
private readonly scopes: ConfigurationScope[] | undefined,
private readonly fileService: IFileService
) {
super();
this.parser = new ConfigurationModelParser(this.userSettingsResource.toString(), this.scopes);
this.reloadConfigurationScheduler = this._register(new RunOnceScheduler(() => this.reload().then(configurationModel => this._onDidChangeConfiguration.fire(configurationModel)), 50));
this._register(Event.filter(this.fileService.onFileChanges, e => e.contains(this.userSettingsResource))(() => this.reloadConfigurationScheduler.schedule()));
}
async initialize(): Promise<ConfigurationModel> {
return this.reload();
}
async reload(): Promise<ConfigurationModel> {
try {
const content = await this.fileService.readFile(this.userSettingsResource);
this.parser.parseContent(content.value.toString() || '{}');
return this.parser.configurationModel;
} catch (e) {
return new ConfigurationModel();
}
}
reprocess(): ConfigurationModel {
this.parser.parse();
return this.parser.configurationModel;
}
}
export class RemoteUserConfiguration extends Disposable {
private readonly _cachedConfiguration: CachedUserConfiguration;
private readonly _configurationFileService: IConfigurationFileService;
private _userConfiguration: UserConfiguration | CachedUserConfiguration;
private readonly _cachedConfiguration: CachedRemoteUserConfiguration;
private readonly _configurationFileService: ConfigurationFileService;
private _userConfiguration: FileServiceBasedRemoteUserConfiguration | CachedRemoteUserConfiguration;
private _userConfigurationInitializationPromise: Promise<ConfigurationModel> | null = null;
private readonly _onDidChangeConfiguration: Emitter<ConfigurationModel> = this._register(new Emitter<ConfigurationModel>());
@@ -37,15 +76,15 @@ export class RemoteUserConfiguration extends Disposable {
constructor(
remoteAuthority: string,
configurationCache: IConfigurationCache,
configurationFileService: IConfigurationFileService,
configurationFileService: ConfigurationFileService,
remoteAgentService: IRemoteAgentService
) {
super();
this._configurationFileService = configurationFileService;
this._userConfiguration = this._cachedConfiguration = new CachedUserConfiguration(remoteAuthority, configurationCache);
this._userConfiguration = this._cachedConfiguration = new CachedRemoteUserConfiguration(remoteAuthority, configurationCache);
remoteAgentService.getEnvironment().then(async environment => {
if (environment) {
const userConfiguration = this._register(new UserConfiguration(environment.settingsPath, REMOTE_MACHINE_SCOPES, this._configurationFileService));
const userConfiguration = this._register(new FileServiceBasedRemoteUserConfiguration(environment.settingsPath, REMOTE_MACHINE_SCOPES, this._configurationFileService));
this._register(userConfiguration.onDidChangeConfiguration(configurationModel => this.onDidUserConfigurationChange(configurationModel)));
this._userConfigurationInitializationPromise = userConfiguration.initialize();
const configurationModel = await this._userConfigurationInitializationPromise;
@@ -57,7 +96,7 @@ export class RemoteUserConfiguration extends Disposable {
}
async initialize(): Promise<ConfigurationModel> {
if (this._userConfiguration instanceof UserConfiguration) {
if (this._userConfiguration instanceof FileServiceBasedRemoteUserConfiguration) {
return this._userConfiguration.initialize();
}
@@ -90,7 +129,7 @@ export class RemoteUserConfiguration extends Disposable {
}
}
export class UserConfiguration extends Disposable {
class FileServiceBasedRemoteUserConfiguration extends Disposable {
private readonly parser: ConfigurationModelParser;
private readonly reloadConfigurationScheduler: RunOnceScheduler;
@@ -103,7 +142,7 @@ export class UserConfiguration extends Disposable {
constructor(
private readonly configurationResource: URI,
private readonly scopes: ConfigurationScope[] | undefined,
private readonly configurationFileService: IConfigurationFileService
private readonly configurationFileService: ConfigurationFileService
) {
super();
@@ -138,11 +177,7 @@ export class UserConfiguration extends Disposable {
async initialize(): Promise<ConfigurationModel> {
const exists = await this.configurationFileService.exists(this.configurationResource);
this.onResourceExists(exists);
const configuraitonModel = await this.reload();
if (!this.configurationFileService.isWatching) {
this.configurationFileService.whenWatchingStarted.then(() => this.onWatchStarted(configuraitonModel));
}
return configuraitonModel;
return this.reload();
}
async reload(): Promise<ConfigurationModel> {
@@ -160,14 +195,6 @@ export class UserConfiguration extends Disposable {
return this.parser.configurationModel;
}
private async onWatchStarted(currentModel: ConfigurationModel): Promise<void> {
const configuraitonModel = await this.reload();
const { added, removed, updated } = compare(currentModel, configuraitonModel);
if (added.length || removed.length || updated.length) {
this._onDidChangeConfiguration.fire(configuraitonModel);
}
}
private async handleFileEvents(event: FileChangesEvent): Promise<void> {
const events = event.changes;
@@ -202,7 +229,7 @@ export class UserConfiguration extends Disposable {
}
}
class CachedUserConfiguration extends Disposable {
class CachedRemoteUserConfiguration extends Disposable {
private readonly _onDidChange: Emitter<ConfigurationModel> = this._register(new Emitter<ConfigurationModel>());
readonly onDidChange: Event<ConfigurationModel> = this._onDidChange.event;
@@ -252,7 +279,7 @@ class CachedUserConfiguration extends Disposable {
export class WorkspaceConfiguration extends Disposable {
private readonly _configurationFileService: IConfigurationFileService;
private readonly _configurationFileService: ConfigurationFileService;
private readonly _cachedConfiguration: CachedWorkspaceConfiguration;
private _workspaceConfiguration: IWorkspaceConfiguration;
private _workspaceConfigurationChangeDisposable: IDisposable = Disposable.None;
@@ -266,7 +293,7 @@ export class WorkspaceConfiguration extends Disposable {
constructor(
configurationCache: IConfigurationCache,
configurationFileService: IConfigurationFileService
configurationFileService: ConfigurationFileService
) {
super();
this._configurationFileService = configurationFileService;
@@ -369,7 +396,7 @@ class FileServiceBasedWorkspaceConfiguration extends Disposable implements IWork
protected readonly _onDidChange: Emitter<void> = this._register(new Emitter<void>());
readonly onDidChange: Event<void> = this._onDidChange.event;
constructor(private configurationFileService: IConfigurationFileService) {
constructor(private configurationFileService: ConfigurationFileService) {
super();
this.workspaceConfigurationModelParser = new WorkspaceConfigurationModelParser('');
@@ -378,10 +405,6 @@ class FileServiceBasedWorkspaceConfiguration extends Disposable implements IWork
this._register(configurationFileService.onFileChanges(e => this.handleWorkspaceFileEvents(e)));
this.reloadConfigurationScheduler = this._register(new RunOnceScheduler(() => this._onDidChange.fire(), 50));
this.workspaceConfigWatcher = this._register(this.watchWorkspaceConfigurationFile());
if (!this.configurationFileService.isWatching) {
this.configurationFileService.whenWatchingStarted.then(() => this.onWatchStarted());
}
}
get workspaceIdentifier(): IWorkspaceIdentifier | null {
@@ -426,18 +449,6 @@ class FileServiceBasedWorkspaceConfiguration extends Disposable implements IWork
return this.getWorkspaceSettings();
}
private async onWatchStarted(): Promise<void> {
if (this.workspaceIdentifier) {
const currentModel = this.getConfigurationModel();
await this.load(this.workspaceIdentifier);
const newModel = this.getConfigurationModel();
const { added, removed, updated } = compare(currentModel, newModel);
if (added.length || removed.length || updated.length) {
this._onDidChange.fire();
}
}
}
private consolidate(): void {
this.workspaceSettings = this.workspaceConfigurationModelParser.settingsModel.merge(this.workspaceConfigurationModelParser.launchModel);
}
@@ -546,7 +557,7 @@ class FileServiceBasedFolderConfiguration extends Disposable implements IFolderC
protected readonly _onDidChange: Emitter<void> = this._register(new Emitter<void>());
readonly onDidChange: Event<void> = this._onDidChange.event;
constructor(protected readonly configurationFolder: URI, workbenchState: WorkbenchState, private configurationFileService: IConfigurationFileService) {
constructor(protected readonly configurationFolder: URI, workbenchState: WorkbenchState, private configurationFileService: ConfigurationFileService) {
super();
this.configurationNames = [FOLDER_SETTINGS_NAME /*First one should be settings */, TASKS_CONFIGURATION_KEY, LAUNCH_CONFIGURATION_KEY];
@@ -557,9 +568,6 @@ class FileServiceBasedFolderConfiguration extends Disposable implements IFolderC
this.changeEventTriggerScheduler = this._register(new RunOnceScheduler(() => this._onDidChange.fire(), 50));
this._register(configurationFileService.onFileChanges(e => this.handleWorkspaceFileEvents(e)));
if (!this.configurationFileService.isWatching) {
this.configurationFileService.whenWatchingStarted.then(() => this.onWatchStarted());
}
}
async loadConfiguration(): Promise<ConfigurationModel> {
@@ -611,15 +619,6 @@ class FileServiceBasedFolderConfiguration extends Disposable implements IFolderC
this._cache = this._folderSettingsModelParser.configurationModel.merge(...this._standAloneConfigurations);
}
private async onWatchStarted(): Promise<void> {
const currentModel = this._cache;
const newModel = await this.loadConfiguration();
const { added, removed, updated } = compare(currentModel, newModel);
if (added.length || removed.length || updated.length) {
this._onDidChange.fire();
}
}
private handleWorkspaceFileEvents(event: FileChangesEvent): void {
const events = event.changes;
let affectedByChanges = false;
@@ -672,7 +671,7 @@ class CachedFolderConfiguration extends Disposable implements IFolderConfigurati
readonly onDidChange: Event<void> = this._onDidChange.event;
private configurationModel: ConfigurationModel;
private readonly key: Thenable<ConfigurationKey>;
private readonly key: ConfigurationKey;
constructor(
folder: URI,
@@ -680,14 +679,13 @@ class CachedFolderConfiguration extends Disposable implements IFolderConfigurati
private readonly configurationCache: IConfigurationCache
) {
super();
this.key = createSHA1(join(folder.path, configFolderRelativePath)).then(key => ({ type: 'folder', key }));
this.key = { type: 'folder', key: hash(join(folder.path, configFolderRelativePath)).toString(16) };
this.configurationModel = new ConfigurationModel();
}
async loadConfiguration(): Promise<ConfigurationModel> {
try {
const key = await this.key;
const contents = await this.configurationCache.read(key);
const contents = await this.configurationCache.read(this.key);
const parsed: IConfigurationModel = JSON.parse(contents.toString());
this.configurationModel = new ConfigurationModel(parsed.contents, parsed.keys, parsed.overrides);
} catch (e) {
@@ -696,11 +694,10 @@ 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(key, JSON.stringify(configurationModel.toJSON()));
await this.configurationCache.write(this.key, JSON.stringify(configurationModel.toJSON()));
} else {
await this.configurationCache.remove(key);
await this.configurationCache.remove(this.key);
}
}
@@ -727,7 +724,7 @@ export class FolderConfiguration extends Disposable implements IFolderConfigurat
readonly workspaceFolder: IWorkspaceFolder,
configFolderRelativePath: string,
private readonly workbenchState: WorkbenchState,
configurationFileService: IConfigurationFileService,
configurationFileService: ConfigurationFileService,
configurationCache: IConfigurationCache
) {
super();

View File

@@ -0,0 +1,22 @@
/*---------------------------------------------------------------------------------------------
* 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

@@ -11,11 +11,10 @@ import { Disposable } from 'vs/base/common/lifecycle';
import { Queue, Barrier } from 'vs/base/common/async';
import { IJSONContributionRegistry, Extensions as JSONExtensions } from 'vs/platform/jsonschemas/common/jsonContributionRegistry';
import { IWorkspaceContextService, Workspace, WorkbenchState, IWorkspaceFolder, toWorkspaceFolders, IWorkspaceFoldersChangeEvent, WorkspaceFolder, toWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
import { isLinux } from 'vs/base/common/platform';
import { ConfigurationChangeEvent, ConfigurationModel, DefaultConfigurationModel } from 'vs/platform/configuration/common/configurationModels';
import { IConfigurationChangeEvent, ConfigurationTarget, IConfigurationOverrides, keyFromOverrideIdentifier, isConfigurationOverrides, IConfigurationData, IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { Configuration, WorkspaceConfigurationChangeEvent, AllKeysConfigurationChangeEvent } from 'vs/workbench/services/configuration/common/configurationModels';
import { FOLDER_CONFIG_FOLDER_NAME, defaultSettingsSchemaId, userSettingsSchemaId, workspaceSettingsSchemaId, folderSettingsSchemaId, IConfigurationCache, IConfigurationFileService, machineSettingsSchemaId, LOCAL_MACHINE_SCOPES } from 'vs/workbench/services/configuration/common/configuration';
import { FOLDER_CONFIG_FOLDER_NAME, defaultSettingsSchemaId, userSettingsSchemaId, workspaceSettingsSchemaId, folderSettingsSchemaId, IConfigurationCache, machineSettingsSchemaId, LOCAL_MACHINE_SCOPES, ConfigurationFileService } from 'vs/workbench/services/configuration/common/configuration';
import { Registry } from 'vs/platform/registry/common/platform';
import { IConfigurationRegistry, Extensions, allSettings, windowSettings, resourceSettings, applicationSettings, machineSettings } from 'vs/platform/configuration/common/configurationRegistry';
import { IWorkspaceIdentifier, isWorkspaceIdentifier, IStoredWorkspaceFolder, isStoredWorkspaceFolder, IWorkspaceFolderCreationData, ISingleFolderWorkspaceIdentifier, isSingleFolderWorkspaceIdentifier, IWorkspaceInitializationPayload, isSingleFolderWorkspaceInitializationPayload, ISingleFolderWorkspaceInitializationPayload, IEmptyWorkspaceInitializationPayload, useSlashForPath, getStoredWorkspaceFolder } from 'vs/platform/workspaces/common/workspaces';
@@ -28,6 +27,8 @@ import { localize } from 'vs/nls';
import { isEqual, dirname } from 'vs/base/common/resources';
import { mark } from 'vs/base/common/performance';
import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
import { IFileService } from 'vs/platform/files/common/files';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
export class WorkspaceService extends Disposable implements IConfigurationService, IWorkspaceContextService {
@@ -37,14 +38,16 @@ export class WorkspaceService extends Disposable implements IConfigurationServic
private completeWorkspaceBarrier: Barrier;
private readonly configurationCache: IConfigurationCache;
private _configuration: Configuration;
private initialized: boolean = false;
private defaultConfiguration: DefaultConfigurationModel;
private localUserConfiguration: UserConfiguration | null = null;
private localUserConfiguration: UserConfiguration;
private remoteUserConfiguration: RemoteUserConfiguration | null = null;
private workspaceConfiguration: WorkspaceConfiguration;
private cachedFolderConfigs: ResourceMap<FolderConfiguration>;
private workspaceEditingQueue: Queue<void>;
private readonly configurationFileService: ConfigurationFileService;
protected readonly _onDidChangeConfiguration: Emitter<IConfigurationChangeEvent> = this._register(new Emitter<IConfigurationChangeEvent>());
public readonly onDidChangeConfiguration: Event<IConfigurationChangeEvent> = this._onDidChangeConfiguration.event;
@@ -64,21 +67,23 @@ export class WorkspaceService extends Disposable implements IConfigurationServic
private cyclicDependency = new Promise<void>(resolve => this.cyclicDependencyReady = resolve);
constructor(
{ userSettingsResource, remoteAuthority, configurationCache }: { userSettingsResource?: URI, remoteAuthority?: string, configurationCache: IConfigurationCache },
private readonly configurationFileService: IConfigurationFileService,
remoteAgentService: IRemoteAgentService,
{ remoteAuthority, configurationCache }: { remoteAuthority?: string, configurationCache: IConfigurationCache },
environmentService: IWorkbenchEnvironmentService,
fileService: IFileService,
remoteAgentService: IRemoteAgentService
) {
super();
this.completeWorkspaceBarrier = new Barrier();
this.defaultConfiguration = new DefaultConfigurationModel();
this.configurationCache = configurationCache;
if (userSettingsResource) {
this.localUserConfiguration = this._register(new UserConfiguration(userSettingsResource, remoteAuthority ? LOCAL_MACHINE_SCOPES : undefined, configurationFileService));
this._register(this.localUserConfiguration.onDidChangeConfiguration(userConfiguration => this.onLocalUserConfigurationChanged(userConfiguration)));
}
this.configurationFileService = new ConfigurationFileService(fileService);
this._configuration = new Configuration(this.defaultConfiguration, new ConfigurationModel(), new ConfigurationModel(), new ConfigurationModel(), new ResourceMap(), new ConfigurationModel(), new ResourceMap<ConfigurationModel>(), this.workspace);
this.cachedFolderConfigs = new ResourceMap<FolderConfiguration>();
this.localUserConfiguration = this._register(new UserConfiguration(environmentService.settingsResource, remoteAuthority ? LOCAL_MACHINE_SCOPES : undefined, fileService));
this._register(this.localUserConfiguration.onDidChangeConfiguration(userConfiguration => this.onLocalUserConfigurationChanged(userConfiguration)));
if (remoteAuthority) {
this.remoteUserConfiguration = this._register(new RemoteUserConfiguration(remoteAuthority, configurationCache, configurationFileService, remoteAgentService));
this.remoteUserConfiguration = this._register(new RemoteUserConfiguration(remoteAuthority, configurationCache, this.configurationFileService, remoteAgentService));
this._register(this.remoteUserConfiguration.onDidChangeConfiguration(userConfiguration => this.onRemoteUserConfigurationChanged(userConfiguration)));
}
this.workspaceConfiguration = this._register(new WorkspaceConfiguration(configurationCache, this.configurationFileService));
@@ -225,13 +230,7 @@ export class WorkspaceService extends Disposable implements IConfigurationServic
}
private contains(resources: URI[], toCheck: URI): boolean {
return resources.some(resource => {
if (isLinux) {
return resource.toString() === toCheck.toString();
}
return resource.toString().toLowerCase() === toCheck.toString().toLowerCase();
});
return resources.some(resource => isEqual(resource, toCheck));
}
// Workspace Configuration Service Impl
@@ -420,7 +419,7 @@ export class WorkspaceService extends Disposable implements IConfigurationServic
}
private initializeUserConfiguration(): Promise<{ local: ConfigurationModel, remote: ConfigurationModel }> {
return Promise.all([this.localUserConfiguration ? this.localUserConfiguration.initialize() : Promise.resolve(new ConfigurationModel()), this.remoteUserConfiguration ? this.remoteUserConfiguration.initialize() : Promise.resolve(new ConfigurationModel())])
return Promise.all([this.localUserConfiguration.initialize(), this.remoteUserConfiguration ? this.remoteUserConfiguration.initialize() : Promise.resolve(new ConfigurationModel())])
.then(([local, remote]) => ({ local, remote }));
}
@@ -429,7 +428,7 @@ export class WorkspaceService extends Disposable implements IConfigurationServic
}
private reloadLocalUserConfiguration(key?: string): Promise<ConfigurationModel> {
return this.localUserConfiguration ? this.localUserConfiguration.reload() : Promise.resolve(new ConfigurationModel());
return this.localUserConfiguration.reload();
}
private reloadRemoeUserConfiguration(key?: string): Promise<ConfigurationModel> {
@@ -466,11 +465,12 @@ export class WorkspaceService extends Disposable implements IConfigurationServic
const currentConfiguration = this._configuration;
this._configuration = new Configuration(this.defaultConfiguration, userConfigurationModel, remoteUserConfigurationModel, workspaceConfiguration, folderConfigurationModels, new ConfigurationModel(), new ResourceMap<ConfigurationModel>(), this.workspace);
if (currentConfiguration) {
if (this.initialized) {
const changedKeys = this._configuration.compare(currentConfiguration);
this.triggerConfigurationChange(new ConfigurationChangeEvent().change(changedKeys), ConfigurationTarget.WORKSPACE);
} else {
this._onDidChangeConfiguration.fire(new AllKeysConfigurationChangeEvent(this._configuration, ConfigurationTarget.WORKSPACE, this.getTargetConfiguration(ConfigurationTarget.WORKSPACE)));
this.initialized = true;
}
});
}
@@ -489,7 +489,7 @@ export class WorkspaceService extends Disposable implements IConfigurationServic
private onDefaultConfigurationChanged(keys: string[]): void {
this.defaultConfiguration = new DefaultConfigurationModel();
this.registerConfigurationSchemas();
if (this.workspace && this._configuration) {
if (this.workspace) {
this._configuration.updateDefaultConfiguration(this.defaultConfiguration);
if (this.remoteUserConfiguration) {
this._configuration.updateRemoteUserConfiguration(this.remoteUserConfiguration.reprocess());
@@ -545,14 +545,12 @@ export class WorkspaceService extends Disposable implements IConfigurationServic
}
private onRemoteUserConfigurationChanged(userConfiguration: ConfigurationModel): void {
if (this._configuration) {
const keys = this._configuration.compareAndUpdateRemoteUserConfiguration(userConfiguration);
this.triggerConfigurationChange(keys, ConfigurationTarget.USER);
}
const keys = this._configuration.compareAndUpdateRemoteUserConfiguration(userConfiguration);
this.triggerConfigurationChange(keys, ConfigurationTarget.USER);
}
private onWorkspaceConfigurationChanged(): Promise<void> {
if (this.workspace && this.workspace.configuration && this._configuration) {
if (this.workspace && this.workspace.configuration) {
const workspaceConfigurationChangeEvent = this._configuration.compareAndUpdateWorkspaceConfiguration(this.workspaceConfiguration.getConfiguration());
let configuredFolders = toWorkspaceFolders(this.workspaceConfiguration.getFolders(), this.workspace.configuration);
const changes = this.compareFolders(this.workspace.folders, configuredFolders);

View File

@@ -5,8 +5,7 @@
import { URI } from 'vs/base/common/uri';
import { IDisposable } from 'vs/base/common/lifecycle';
import { Event } from 'vs/base/common/event';
import { FileChangesEvent, IFileService } from 'vs/platform/files/common/files';
import { IFileService } from 'vs/platform/files/common/files';
import { ConfigurationScope } from 'vs/platform/configuration/common/configurationRegistry';
export const FOLDER_CONFIG_FOLDER_NAME = '.azuredatastudio';
@@ -42,24 +41,11 @@ export interface IConfigurationCache {
}
export interface IConfigurationFileService {
fileService: IFileService | null;
readonly onFileChanges: Event<FileChangesEvent>;
readonly isWatching: boolean;
readonly whenWatchingStarted: Promise<void>;
whenProviderRegistered(scheme: string): Promise<void>;
watch(resource: URI): IDisposable;
exists(resource: URI): Promise<boolean>;
readFile(resource: URI): Promise<string>;
}
export class ConfigurationFileService {
export class ConfigurationFileService implements IConfigurationFileService {
constructor(public fileService: IFileService) { }
constructor(private readonly fileService: IFileService) { }
get onFileChanges() { return this.fileService.onFileChanges; }
readonly whenWatchingStarted: Promise<void> = Promise.resolve();
readonly isWatching: boolean = true;
whenProviderRegistered(scheme: string): Promise<void> {
if (this.fileService.canHandleResource(URI.from({ scheme }))) {

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

View File

@@ -39,10 +39,11 @@ export class JSONEditingService implements IJSONEditingService {
return Promise.resolve(this.queue.queue(() => this.doWriteConfiguration(resource, value, save))); // queue up writes to prevent race conditions
}
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 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 async writeToBuffer(model: ITextModel, value: IJSONValue): Promise<any> {
@@ -97,21 +98,21 @@ export class JSONEditingService implements IJSONEditingService {
return parseErrors.length > 0;
}
private resolveAndValidate(resource: URI, checkDirty: boolean): Promise<IReference<IResolvedTextEditorModel>> {
return this.resolveModelReference(resource)
.then(reference => {
const model = reference.object.textEditorModel;
private async resolveAndValidate(resource: URI, checkDirty: boolean): Promise<IReference<IResolvedTextEditorModel>> {
const reference = await this.resolveModelReference(resource);
if (this.hasParseErrors(model)) {
return this.reject<IReference<IResolvedTextEditorModel>>(JSONEditingErrorCode.ERROR_INVALID_FILE);
}
const model = reference.object.textEditorModel;
// 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;
});
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;
}
private reject<T>(code: JSONEditingErrorCode): Promise<T> {

View File

@@ -7,12 +7,13 @@ import * as pfs from 'vs/base/node/pfs';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { join } from 'vs/base/common/path';
import { IConfigurationCache, ConfigurationKey } from 'vs/workbench/services/configuration/common/configuration';
import { IWorkbenchEnvironmentService } from '../../environment/common/environmentService';
export class ConfigurationCache implements IConfigurationCache {
private readonly cachedConfigurations: Map<string, CachedConfiguration> = new Map<string, CachedConfiguration>();
constructor(private readonly environmentService: IEnvironmentService) {
constructor(private readonly environmentService: IWorkbenchEnvironmentService) {
}
read(key: ConfigurationKey): Promise<string> {

View File

@@ -1,79 +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 * as pfs from 'vs/base/node/pfs';
import { IConfigurationFileService, ConfigurationFileService as FileServiceBasedConfigurationFileService } from 'vs/workbench/services/configuration/common/configuration';
import { URI } from 'vs/base/common/uri';
import { Event, Emitter } from 'vs/base/common/event';
import { FileChangesEvent, IFileService } from 'vs/platform/files/common/files';
import { Disposable, IDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { Schemas } from 'vs/base/common/network';
export class ConfigurationFileService extends Disposable implements IConfigurationFileService {
private _fileServiceBasedConfigurationFileService: FileServiceBasedConfigurationFileService | null = null;
private _fileServiceBasedConfigurationFileServiceCallback: (fileServiceBasedConfigurationFileService: FileServiceBasedConfigurationFileService) => void;
private _whenFileServiceBasedConfigurationFileServiceAvailable: Promise<FileServiceBasedConfigurationFileService> = new Promise((c) => this._fileServiceBasedConfigurationFileServiceCallback = c);
private _watchResources: { resource: URI, disposable: { disposable: IDisposable | null } }[] = [];
readonly whenWatchingStarted: Promise<void> = this._whenFileServiceBasedConfigurationFileServiceAvailable.then(() => undefined);
private readonly _onFileChanges: Emitter<FileChangesEvent> = this._register(new Emitter<FileChangesEvent>());
readonly onFileChanges: Event<FileChangesEvent> = this._onFileChanges.event;
get isWatching(): boolean {
return this._fileServiceBasedConfigurationFileService ? this._fileServiceBasedConfigurationFileService.isWatching : false;
}
watch(resource: URI): IDisposable {
if (this._fileServiceBasedConfigurationFileService) {
return this._fileServiceBasedConfigurationFileService.watch(resource);
}
const disposable: { disposable: IDisposable | null } = { disposable: null };
this._watchResources.push({ resource, disposable });
return toDisposable(() => {
if (disposable.disposable) {
disposable.disposable.dispose();
}
});
}
whenProviderRegistered(scheme: string): Promise<void> {
if (scheme === Schemas.file) {
return Promise.resolve();
}
return this._whenFileServiceBasedConfigurationFileServiceAvailable
.then(fileServiceBasedConfigurationFileService => fileServiceBasedConfigurationFileService.whenProviderRegistered(scheme));
}
exists(resource: URI): Promise<boolean> {
return this._fileServiceBasedConfigurationFileService ? this._fileServiceBasedConfigurationFileService.exists(resource) : pfs.exists(resource.fsPath);
}
async readFile(resource: URI): Promise<string> {
if (this._fileServiceBasedConfigurationFileService) {
return this._fileServiceBasedConfigurationFileService.readFile(resource);
} else {
const contents = await pfs.readFile(resource.fsPath);
return contents.toString();
}
}
private _fileService: IFileService | null;
get fileService(): IFileService | null {
return this._fileService;
}
set fileService(fileService: IFileService | null) {
if (fileService && !this._fileServiceBasedConfigurationFileService) {
this._fileServiceBasedConfigurationFileService = new FileServiceBasedConfigurationFileService(fileService);
this._fileService = fileService;
this._register(this._fileServiceBasedConfigurationFileService.onFileChanges(e => this._onFileChanges.fire(e)));
for (const { resource, disposable } of this._watchResources) {
disposable.disposable = this._fileServiceBasedConfigurationFileService.watch(resource);
}
this._fileServiceBasedConfigurationFileServiceCallback(this._fileServiceBasedConfigurationFileService);
}
}
}

View File

@@ -10,10 +10,9 @@ import * as path from 'vs/base/common/path';
import * as fs from 'fs';
import * as json from 'vs/base/common/json';
import { Registry } from 'vs/platform/registry/common/platform';
import { ParsedArgs, IEnvironmentService } from 'vs/platform/environment/common/environment';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { parseArgs } from 'vs/platform/environment/node/argv';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { EnvironmentService } from 'vs/platform/environment/node/environmentService';
import { TestTextFileService, workbenchInstantiationService } from 'vs/workbench/test/workbenchTestServices';
import * as uuid from 'vs/base/common/uuid';
import { IConfigurationRegistry, Extensions as ConfigurationExtensions } from 'vs/platform/configuration/common/configurationRegistry';
@@ -33,21 +32,25 @@ import { URI } from 'vs/base/common/uri';
import { createHash } from 'crypto';
import { RemoteAgentService } from 'vs/workbench/services/remote/electron-browser/remoteAgentServiceImpl';
import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
import { FileService } from 'vs/workbench/services/files/common/fileService';
import { FileService } from 'vs/platform/files/common/fileService';
import { NullLogService } from 'vs/platform/log/common/log';
import { Schemas } from 'vs/base/common/network';
import { DiskFileSystemProvider } from 'vs/workbench/services/files/node/diskFileSystemProvider';
import { DiskFileSystemProvider } from 'vs/platform/files/node/diskFileSystemProvider';
import { IFileService } from 'vs/platform/files/common/files';
import { ConfigurationCache } from 'vs/workbench/services/configuration/node/configurationCache';
import { ConfigurationFileService } from 'vs/workbench/services/configuration/node/configurationFileService';
import { KeybindingsEditingService, IKeybindingEditingService } from 'vs/workbench/services/keybinding/common/keybindingEditing';
import { WorkbenchEnvironmentService } from 'vs/workbench/services/environment/node/environmentService';
import { IWindowConfiguration } from 'vs/platform/windows/common/windows';
import { FileUserDataProvider } from 'vs/workbench/services/userData/common/fileUserDataProvider';
class SettingsTestEnvironmentService extends EnvironmentService {
class TestEnvironmentService extends WorkbenchEnvironmentService {
constructor(args: ParsedArgs, _execPath: string, private customAppSettingsHome: string) {
super(args, _execPath);
constructor(private _appSettingsHome: URI) {
super(parseArgs(process.argv) as IWindowConfiguration, process.execPath);
}
get appSettingsPath(): string { return this.customAppSettingsHome; }
get appSettingsHome() { return this._appSettingsHome; }
}
suite('ConfigurationEditingService', () => {
@@ -90,9 +93,8 @@ suite('ConfigurationEditingService', () => {
const id = uuid.generateUuid();
parentDir = path.join(os.tmpdir(), 'vsctests', id);
workspaceDir = path.join(parentDir, 'workspaceconfig', id);
globalSettingsFile = path.join(workspaceDir, 'config.json');
// {{SQL CARBON EDIT}}
workspaceSettingsDir = path.join(workspaceDir, '.azuredatastudio');
globalSettingsFile = path.join(workspaceDir, 'settings.json');
workspaceSettingsDir = path.join(workspaceDir, '.azuredatastudio'); // {{SQL CARBON EDIT}} .vscode to .azuredatastudio
return await mkdirp(workspaceSettingsDir, 493);
}
@@ -102,17 +104,20 @@ suite('ConfigurationEditingService', () => {
clearServices();
instantiationService = <TestInstantiationService>workbenchInstantiationService();
const environmentService = new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, globalSettingsFile);
const environmentService = new TestEnvironmentService(URI.file(workspaceDir));
instantiationService.stub(IEnvironmentService, environmentService);
const remoteAgentService = instantiationService.createInstance(RemoteAgentService, {});
const fileService = new FileService(new NullLogService());
const diskFileSystemProvider = new DiskFileSystemProvider(new NullLogService());
fileService.registerProvider(Schemas.file, diskFileSystemProvider);
fileService.registerProvider(Schemas.userData, new FileUserDataProvider(environmentService.appSettingsHome, environmentService.backupHome, diskFileSystemProvider, environmentService));
instantiationService.stub(IFileService, fileService);
instantiationService.stub(IRemoteAgentService, remoteAgentService);
const workspaceService = new WorkspaceService({ userSettingsResource: URI.file(environmentService.appSettingsPath), configurationCache: new ConfigurationCache(environmentService) }, new ConfigurationFileService(), remoteAgentService);
const workspaceService = new WorkspaceService({ configurationCache: new ConfigurationCache(environmentService) }, environmentService, fileService, 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);
const fileService = new FileService(new NullLogService());
fileService.registerProvider(Schemas.file, new DiskFileSystemProvider(new NullLogService()));
instantiationService.stub(IFileService, fileService);
instantiationService.stub(IKeybindingEditingService, instantiationService.createInstance(KeybindingsEditingService));
instantiationService.stub(ITextFileService, instantiationService.createInstance(TestTextFileService));
instantiationService.stub(ITextModelService, <ITextModelService>instantiationService.createInstance(TextModelResolverService));
instantiationService.stub(ICommandService, CommandService);
@@ -122,7 +127,10 @@ suite('ConfigurationEditingService', () => {
teardown(() => {
clearServices();
return clearWorkspace();
if (workspaceDir) {
return rimraf(workspaceDir, RimRafMode.MOVE);
}
return undefined;
});
function clearServices(): void {
@@ -135,16 +143,6 @@ suite('ConfigurationEditingService', () => {
}
}
function clearWorkspace(): Promise<void> {
return new Promise<void>((c, e) => {
if (parentDir) {
rimraf(parentDir, RimRafMode.MOVE).then(c, c);
} else {
c(undefined);
}
}).then(() => parentDir = null!);
}
test('errors cases - invalid key', () => {
return testObject.writeConfiguration(EditableConfigurationTarget.WORKSPACE, { key: 'unknown.key', value: 'value' })
.then(() => assert.fail('Should fail with ERROR_UNKNOWN_KEY'),
@@ -187,7 +185,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! });
instantiationService.stub(INotificationService, <INotificationService>{ prompt: target, _serviceBrand: null!, notify: null!, error: null!, info: null!, warn: null!, status: 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

@@ -10,8 +10,7 @@ import * as path from 'vs/base/common/path';
import * as os from 'os';
import { URI } from 'vs/base/common/uri';
import { Registry } from 'vs/platform/registry/common/platform';
import { ParsedArgs, IEnvironmentService } from 'vs/platform/environment/common/environment';
import { EnvironmentService } from 'vs/platform/environment/node/environmentService';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { parseArgs } from 'vs/platform/environment/node/argv';
import * as pfs from 'vs/base/node/pfs';
import * as uuid from 'vs/base/common/uuid';
@@ -37,21 +36,27 @@ import { IWindowConfiguration } from 'vs/platform/windows/common/windows';
import { RemoteAgentService } from 'vs/workbench/services/remote/electron-browser/remoteAgentServiceImpl';
import { RemoteAuthorityResolverService } from 'vs/platform/remote/electron-browser/remoteAuthorityResolverService';
import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
import { FileService } from 'vs/workbench/services/files/common/fileService';
import { FileService } from 'vs/platform/files/common/fileService';
import { NullLogService } from 'vs/platform/log/common/log';
import { DiskFileSystemProvider } from 'vs/workbench/services/files/node/diskFileSystemProvider';
import { DiskFileSystemProvider } from 'vs/platform/files/node/diskFileSystemProvider';
import { ConfigurationCache } from 'vs/workbench/services/configuration/node/configurationCache';
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';
import { SignService } from 'vs/platform/sign/browser/signService';
import { FileUserDataProvider } from 'vs/workbench/services/userData/common/fileUserDataProvider';
import { IKeybindingEditingService, KeybindingsEditingService } from 'vs/workbench/services/keybinding/common/keybindingEditing';
import { WorkbenchEnvironmentService } from 'vs/workbench/services/environment/node/environmentService';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
class SettingsTestEnvironmentService extends EnvironmentService {
class TestEnvironmentService extends WorkbenchEnvironmentService {
constructor(args: ParsedArgs, _execPath: string, private customAppSettingsHome: string) {
super(args, _execPath);
constructor(private _appSettingsHome: URI) {
super(parseArgs(process.argv) as IWindowConfiguration, process.execPath);
}
get appSettingsPath(): string { return this.customAppSettingsHome; }
get appSettingsHome() { return this._appSettingsHome; }
}
function setUpFolderWorkspace(folderName: string): Promise<{ parentDir: string, folderDir: string }> {
@@ -93,6 +98,14 @@ function setUpWorkspace(folders: string[]): Promise<{ parentDir: string, configP
suite('WorkspaceContextService - Folder', () => {
setup(() => {
// {{SQL CARBON EDIT}} - Remove tests
});
teardown(() => {
// {{SQL CARBON EDIT}} - Remove tests
});
test('getWorkspace()', () => {
// {{SQL CARBON EDIT}} - Remove tests
assert.equal(0, 0);
@@ -145,15 +158,14 @@ suite('WorkspaceConfigurationService - Remote Folder', () => {
remoteSettingsFile = path.join(parentDir, 'remote-settings.json');
instantiationService = <TestInstantiationService>workbenchInstantiationService();
const environmentService = new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, globalSettingsFile);
const environmentService = new TestEnvironmentService(URI.file(parentDir));
const remoteEnvironmentPromise = new Promise<Partial<IRemoteAgentEnvironment>>(c => resolveRemoteEnvironment = () => c({ settingsPath: URI.file(remoteSettingsFile).with({ scheme: Schemas.vscodeRemote, authority: remoteAuthority }) }));
const remoteAgentService = instantiationService.stub(IRemoteAgentService, <Partial<IRemoteAgentService>>{ getEnvironment: () => remoteEnvironmentPromise });
const fileService = new FileService(new NullLogService());
fileService.registerProvider(Schemas.file, diskFileSystemProvider);
const configurationFileService = new ConfigurationFileService();
configurationFileService.fileService = fileService;
fileService.registerProvider(Schemas.userData, new FileUserDataProvider(environmentService.appSettingsHome, environmentService.backupHome, diskFileSystemProvider, environmentService));
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({ configurationCache, remoteAuthority }, environmentService, fileService, remoteAgentService);
instantiationService.stub(IWorkspaceContextService, testObject);
instantiationService.stub(IConfigurationService, testObject);
instantiationService.stub(IEnvironmentService, environmentService);
@@ -264,7 +276,7 @@ suite('WorkspaceConfigurationService - Remote Folder', () => {
// }
// });
// });
// fs.writeFileSync(remoteSettingsFile, '{ "configurationService.remote.machineSetting": "remoteValue" }');
// await instantiationService.get(IFileService).writeFile(URI.file(remoteSettingsFile), VSBuffer.fromString('{ "configurationService.remote.machineSetting": "remoteValue" }'));
// return promise;
// });