@@ -13,7 +13,7 @@ import * as collections from 'vs/base/common/collections';
1313import { Disposable , IDisposable , dispose , toDisposable } from 'vs/base/common/lifecycle' ;
1414import { RunOnceScheduler , Delayer } from 'vs/base/common/async' ;
1515import { FileChangeType , FileChangesEvent , IContent , IFileService } from 'vs/platform/files/common/files' ;
16- import { ConfigurationModel , ConfigurationModelParser } from 'vs/platform/configuration/common/configurationModels' ;
16+ import { ConfigurationModel } from 'vs/platform/configuration/common/configurationModels' ;
1717import { WorkspaceConfigurationModelParser , FolderSettingsModelParser , StandaloneConfigurationModelParser } from 'vs/workbench/services/configuration/common/configurationModels' ;
1818import { FOLDER_SETTINGS_PATH , TASKS_CONFIGURATION_KEY , FOLDER_SETTINGS_NAME , LAUNCH_CONFIGURATION_KEY } from 'vs/workbench/services/configuration/common/configuration' ;
1919import { IStoredWorkspaceFolder } from 'vs/platform/workspaces/common/workspaces' ;
@@ -26,14 +26,52 @@ import { equals } from 'vs/base/common/objects';
2626import { Schemas } from 'vs/base/common/network' ;
2727import { IEnvironmentService } from 'vs/platform/environment/common/environment' ;
2828import { IConfigurationModel , compare } from 'vs/platform/configuration/common/configuration' ;
29+ import { FileServiceBasedUserConfiguration , NodeBasedUserConfiguration } from 'vs/platform/configuration/node/configuration' ;
30+
31+ export class LocalUserConfiguration extends Disposable {
32+
33+ private readonly userConfigurationResource : URI ;
34+ private userConfiguration : NodeBasedUserConfiguration | FileServiceBasedUserConfiguration ;
35+ private changeDisposable : IDisposable = Disposable . None ;
36+
37+ private readonly _onDidChangeConfiguration : Emitter < ConfigurationModel > = this . _register ( new Emitter < ConfigurationModel > ( ) ) ;
38+ public readonly onDidChangeConfiguration : Event < ConfigurationModel > = this . _onDidChangeConfiguration . event ;
39+
40+ constructor (
41+ environmentService : IEnvironmentService
42+ ) {
43+ super ( ) ;
44+ this . userConfigurationResource = URI . file ( environmentService . appSettingsPath ) ;
45+ this . userConfiguration = this . _register ( new NodeBasedUserConfiguration ( environmentService . appSettingsPath ) ) ;
46+ this . changeDisposable = this . _register ( this . userConfiguration . onDidChangeConfiguration ( configurationModel => this . _onDidChangeConfiguration . fire ( configurationModel ) ) ) ;
47+ }
48+
49+ initialize ( ) : Promise < ConfigurationModel > {
50+ return this . userConfiguration . initialize ( ) ;
51+ }
52+
53+ reload ( ) : Promise < ConfigurationModel > {
54+ return this . userConfiguration . reload ( ) ;
55+ }
56+
57+ async adopt ( fileService : IFileService ) : Promise < ConfigurationModel | null > {
58+ if ( this . userConfiguration instanceof NodeBasedUserConfiguration ) {
59+ this . userConfiguration . dispose ( ) ;
60+ dispose ( this . changeDisposable ) ;
61+ this . userConfiguration = this . _register ( new FileServiceBasedUserConfiguration ( this . userConfigurationResource , fileService ) ) ;
62+ this . changeDisposable = this . _register ( this . userConfiguration . onDidChangeConfiguration ( configurationModel => this . _onDidChangeConfiguration . fire ( configurationModel ) ) ) ;
63+ }
64+ return null ;
65+ }
66+ }
2967
3068export class RemoteUserConfiguration extends Disposable {
3169
3270 private readonly _cachedConfiguration : CachedUserConfiguration ;
3371 private _userConfiguration : FileServiceBasedUserConfiguration | CachedUserConfiguration ;
3472
35- private readonly _onDidUpdateConfiguration : Emitter < ConfigurationModel > = this . _register ( new Emitter < ConfigurationModel > ( ) ) ;
36- public readonly onDidChangeConfiguration : Event < ConfigurationModel > = this . _onDidUpdateConfiguration . event ;
73+ private readonly _onDidChangeConfiguration : Emitter < ConfigurationModel > = this . _register ( new Emitter < ConfigurationModel > ( ) ) ;
74+ public readonly onDidChangeConfiguration : Event < ConfigurationModel > = this . _onDidChangeConfiguration . event ;
3775
3876 constructor (
3977 remoteAuthority : string ,
@@ -43,18 +81,22 @@ export class RemoteUserConfiguration extends Disposable {
4381 this . _userConfiguration = this . _cachedConfiguration = new CachedUserConfiguration ( remoteAuthority , environmentService ) ;
4482 }
4583
46- load ( ) : Promise < ConfigurationModel > {
47- return this . _userConfiguration . loadConfiguration ( ) ;
84+ initialize ( ) : Promise < ConfigurationModel > {
85+ return this . _userConfiguration . initialize ( ) ;
86+ }
87+
88+ reload ( ) : Promise < ConfigurationModel > {
89+ return this . _userConfiguration . reload ( ) ;
4890 }
4991
5092 async adopt ( configurationResource : URI | null , fileService : IFileService ) : Promise < ConfigurationModel | null > {
5193 if ( this . _userConfiguration instanceof CachedUserConfiguration ) {
5294 const oldConfigurationModel = this . _userConfiguration . getConfigurationModel ( ) ;
5395 let newConfigurationModel = new ConfigurationModel ( ) ;
5496 if ( configurationResource ) {
55- this . _userConfiguration = new FileServiceBasedUserConfiguration ( configurationResource , oldConfigurationModel , fileService ) ;
56- this . _register ( this . _userConfiguration . onDidChange ( configurationModel => this . onDidUserConfigurationChange ( configurationModel ) ) ) ;
57- newConfigurationModel = await this . _userConfiguration . loadConfiguration ( ) ;
97+ this . _userConfiguration = new FileServiceBasedUserConfiguration ( configurationResource , fileService ) ;
98+ this . _register ( this . _userConfiguration . onDidChangeConfiguration ( configurationModel => this . onDidUserConfigurationChange ( configurationModel ) ) ) ;
99+ newConfigurationModel = await this . _userConfiguration . initialize ( ) ;
58100 }
59101 const { added, updated, removed } = compare ( oldConfigurationModel , newConfigurationModel ) ;
60102 if ( added . length > 0 || updated . length > 0 || removed . length > 0 ) {
@@ -67,61 +109,14 @@ export class RemoteUserConfiguration extends Disposable {
67109
68110 private onDidUserConfigurationChange ( configurationModel : ConfigurationModel ) : void {
69111 this . updateCache ( configurationModel ) ;
70- this . _onDidUpdateConfiguration . fire ( configurationModel ) ;
112+ this . _onDidChangeConfiguration . fire ( configurationModel ) ;
71113 }
72114
73115 private updateCache ( configurationModel : ConfigurationModel ) : Promise < void > {
74116 return this . _cachedConfiguration . updateConfiguration ( configurationModel ) ;
75117 }
76118}
77119
78- class FileServiceBasedUserConfiguration extends Disposable {
79-
80- private readonly reloadConfigurationScheduler : RunOnceScheduler ;
81- protected readonly _onDidChange : Emitter < ConfigurationModel > = this . _register ( new Emitter < ConfigurationModel > ( ) ) ;
82- readonly onDidChange : Event < ConfigurationModel > = this . _onDidChange . event ;
83-
84- constructor (
85- private readonly configurationResource : URI ,
86- private configurationModel : ConfigurationModel ,
87- private readonly fileService : IFileService
88- ) {
89- super ( ) ;
90-
91- this . _register ( fileService . onFileChanges ( e => this . handleFileEvents ( e ) ) ) ;
92- this . reloadConfigurationScheduler = this . _register ( new RunOnceScheduler ( ( ) => this . loadConfiguration ( ) . then ( configurationModel => this . _onDidChange . fire ( configurationModel ) ) , 50 ) ) ;
93- this . fileService . watchFileChanges ( this . configurationResource ) ;
94- this . _register ( toDisposable ( ( ) => this . fileService . unwatchFileChanges ( this . configurationResource ) ) ) ;
95- }
96-
97- loadConfiguration ( ) : Promise < ConfigurationModel > {
98- return this . fileService . resolveContent ( this . configurationResource )
99- . then ( content => content . value , e => {
100- errors . onUnexpectedError ( e ) ;
101- return '' ;
102- } ) . then ( content => {
103- const parser = new ConfigurationModelParser ( this . configurationResource . toString ( ) ) ;
104- parser . parse ( content ) ;
105- this . configurationModel = parser . configurationModel ;
106- return this . configurationModel ;
107- } ) ;
108- }
109-
110- private handleFileEvents ( event : FileChangesEvent ) : void {
111- const events = event . changes ;
112-
113- let affectedByChanges = false ;
114- // Find changes that affect workspace file
115- for ( let i = 0 , len = events . length ; i < len && ! affectedByChanges ; i ++ ) {
116- affectedByChanges = resources . isEqual ( this . configurationResource , events [ i ] . resource ) ;
117- }
118-
119- if ( affectedByChanges ) {
120- this . reloadConfigurationScheduler . schedule ( ) ;
121- }
122- }
123- }
124-
125120class CachedUserConfiguration extends Disposable {
126121
127122 private readonly _onDidChange : Emitter < ConfigurationModel > = this . _register ( new Emitter < ConfigurationModel > ( ) ) ;
@@ -145,7 +140,11 @@ class CachedUserConfiguration extends Disposable {
145140 return this . configurationModel ;
146141 }
147142
148- loadConfiguration ( ) : Promise < ConfigurationModel > {
143+ initialize ( ) : Promise < ConfigurationModel > {
144+ return this . reload ( ) ;
145+ }
146+
147+ reload ( ) : Promise < ConfigurationModel > {
149148 return pfs . readFile ( this . cachedConfigurationPath )
150149 . then ( content => content . toString ( ) , ( ) => '' )
151150 . then ( content => {
0 commit comments