Skip to content

Commit

Permalink
#142027 #142020 listen to file operations
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 committed Feb 8, 2022
1 parent 25e06c6 commit cfd927b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/vs/platform/configuration/common/configurationModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import * as types from 'vs/base/common/types';
import { URI, UriComponents } from 'vs/base/common/uri';
import { addToValueTree, ConfigurationTarget, getConfigurationValue, IConfigurationChange, IConfigurationChangeEvent, IConfigurationCompareResult, IConfigurationData, IConfigurationModel, IConfigurationOverrides, IConfigurationUpdateOverrides, IConfigurationValue, IOverrides, removeFromValueTree, toValuesTree } from 'vs/platform/configuration/common/configuration';
import { ConfigurationScope, Extensions, IConfigurationPropertySchema, IConfigurationRegistry, overrideIdentifiersFromKey, OVERRIDE_PROPERTY_REGEX } from 'vs/platform/configuration/common/configurationRegistry';
import { IFileService } from 'vs/platform/files/common/files';
import { FileOperation, IFileService } from 'vs/platform/files/common/files';
import { Registry } from 'vs/platform/registry/common/platform';
import { Workspace } from 'vs/platform/workspace/common/workspace';

Expand Down Expand Up @@ -439,7 +439,10 @@ export class UserSettings extends Disposable {
this._register(this.fileService.watch(extUri.dirname(this.userSettingsResource)));
// Also listen to the resource incase the resource is a symlink - https://github.com/microsoft/vscode/issues/118134
this._register(this.fileService.watch(this.userSettingsResource));
this._register(Event.filter(this.fileService.onDidFilesChange, e => e.contains(this.userSettingsResource))(() => this._onDidChange.fire()));
this._register(Event.any(
Event.filter(this.fileService.onDidFilesChange, e => e.contains(this.userSettingsResource)),
Event.filter(this.fileService.onDidRunOperation, e => (e.isOperation(FileOperation.CREATE) || e.isOperation(FileOperation.DELETE) || e.isOperation(FileOperation.WRITE)) && extUri.isEqual(e.resource, userSettingsResource))
)(() => this._onDidChange.fire()));
}

async loadConfiguration(): Promise<ConfigurationModel> {
Expand Down
23 changes: 20 additions & 3 deletions src/vs/workbench/services/configuration/browser/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Event, Emitter } from 'vs/base/common/event';
import * as errors from 'vs/base/common/errors';
import { Disposable, IDisposable, dispose, toDisposable, MutableDisposable, combinedDisposable, DisposableStore } from 'vs/base/common/lifecycle';
import { RunOnceScheduler } from 'vs/base/common/async';
import { FileChangeType, FileChangesEvent, IFileService, whenProviderRegistered, FileOperationError, FileOperationResult } from 'vs/platform/files/common/files';
import { FileChangeType, FileChangesEvent, IFileService, whenProviderRegistered, FileOperationError, FileOperationResult, FileOperation, FileOperationEvent } from 'vs/platform/files/common/files';
import { ConfigurationModel, ConfigurationModelParser, ConfigurationParseOptions, DefaultConfigurationModel, UserSettings } from 'vs/platform/configuration/common/configurationModels';
import { WorkspaceConfigurationModelParser, StandaloneConfigurationModelParser } from 'vs/workbench/services/configuration/common/configurationModels';
import { TASKS_CONFIGURATION_KEY, FOLDER_SETTINGS_NAME, LAUNCH_CONFIGURATION_KEY, IConfigurationCache, ConfigurationKey, REMOTE_MACHINE_SCOPES, FOLDER_SCOPES, WORKSPACE_SCOPES } from 'vs/workbench/services/configuration/common/configuration';
Expand Down Expand Up @@ -215,7 +215,11 @@ class FileServiceBasedConfiguration extends Disposable {
this._standAloneConfigurations = [];
this._cache = new ConfigurationModel();

this._register(Event.debounce(Event.filter(this.fileService.onDidFilesChange, e => this.handleFileEvents(e)), () => undefined, 100)(() => this._onDidChange.fire()));
this._register(Event.debounce(
Event.any(
Event.filter(this.fileService.onDidFilesChange, e => this.handleFileChangesEvent(e)),
Event.filter(this.fileService.onDidRunOperation, e => this.handleFileOperationEvent(e))
), () => undefined, 100)(() => this._onDidChange.fire()));
}

async resolveContents(): Promise<[string | undefined, [string, string | undefined][]]> {
Expand Down Expand Up @@ -289,7 +293,7 @@ class FileServiceBasedConfiguration extends Disposable {
this._cache = this._folderSettingsModelParser.configurationModel.merge(...this._standAloneConfigurations);
}

private handleFileEvents(event: FileChangesEvent): boolean {
private handleFileChangesEvent(event: FileChangesEvent): boolean {
// One of the resources has changed
if (this.allResources.some(resource => event.contains(resource))) {
return true;
Expand All @@ -301,6 +305,19 @@ class FileServiceBasedConfiguration extends Disposable {
return false;
}

private handleFileOperationEvent(event: FileOperationEvent): boolean {
// One of the resources has changed
if ((event.isOperation(FileOperation.CREATE) || event.isOperation(FileOperation.DELETE) || event.isOperation(FileOperation.WRITE))
&& this.allResources.some(resource => this.uriIdentityService.extUri.isEqual(event.resource, resource))) {
return true;
}
// One of the resource's parent got deleted
if (event.isOperation(FileOperation.DELETE) && this.allResources.some(resource => this.uriIdentityService.extUri.isEqual(event.resource, this.uriIdentityService.extUri.dirname(resource)))) {
return true;
}
return false;
}

}

export class RemoteUserConfiguration extends Disposable {
Expand Down

0 comments on commit cfd927b

Please sign in to comment.