33 * Licensed under the MIT License. See License.md in the project root for license information.
44 * -------------------------------------------------------------------------------------------- */
55'use strict' ;
6- import {
7- ConfigurationChangeEvent ,
8- Event ,
9- EventEmitter ,
10- ExtensionContext ,
11- workspace ,
12- WorkspaceConfiguration ,
13- } from 'vscode' ;
14- import { constants } from './constants' ;
15- import { Logger } from './logger' ;
6+ import { ConfigurationChangeEvent , ConfigurationScope , Event , EventEmitter , ExtensionContext , workspace } from 'vscode' ;
7+ import { constants } from '../constants' ;
8+ import { Logger } from '../logger' ;
169export class Config {
17- private _config : WorkspaceConfiguration ;
10+ // private _config: WorkspaceConfiguration;
1811
1912 private _onDidChange = new EventEmitter < ConfigurationChangeEvent > ( ) ;
2013 get onDidChange ( ) : Event < ConfigurationChangeEvent > {
@@ -28,9 +21,7 @@ export class Config {
2821 // Constructor
2922 constructor ( ) {
3023 // Static reference to configuration
31- this . _config = workspace . getConfiguration ( constants . configId ) ;
32-
33- // Initialize
24+ // this._config = workspace.getConfiguration(constants.configId);
3425 }
3526
3627 private onConfigurationChanged ( e : ConfigurationChangeEvent ) {
@@ -40,37 +31,35 @@ export class Config {
4031 }
4132
4233 private reloadConfig ( ) {
43- this . _config = workspace . getConfiguration ( constants . configId ) ;
34+ // this._config = workspace.getConfiguration(constants.configId);
4435 }
4536
4637 // Get Parameter
47- getParam ( param : string ) : unknown {
48- this . reloadConfig ( ) ;
49- return this . _config . get ( param ) ;
38+ getParam < T > ( param : string , scope ?: ConfigurationScope , defaultValue ?: T ) : T | undefined {
39+ // this.reloadConfig();
40+ return defaultValue === undefined
41+ ? workspace . getConfiguration ( constants . configId , scope ) . get < T > ( param )
42+ : workspace . getConfiguration ( constants . configId , scope ) . get < T > ( param , defaultValue ) ;
5043 }
5144
5245 // Set Parameter
53- async setParam ( param : string , value : any , global = true ) : Promise < boolean > {
46+ async setParam ( param : string , value : any , global = true , scope ?: ConfigurationScope ) : Promise < boolean > {
5447 try {
55- await this . _config . update ( param , value , global ) ;
48+ await workspace . getConfiguration ( constants . configId , scope ) . update ( param , value , global ) ;
5649 } catch ( err ) {
5750 Logger . log ( 'Error updating configuration' ) ;
5851 return false ;
5952 }
6053
61- this . reloadConfig ( ) ;
54+ // this.reloadConfig();
6255
63- if ( this . _config !== undefined ) {
64- return true ;
65- } else {
66- return false ;
67- }
56+ return this . getParam ( param ) === value ;
6857 }
6958
70- changed ( e : ConfigurationChangeEvent , ... args : any [ ] ) {
71- const section : string = < string > args [ 0 ] ;
59+ changed ( e : ConfigurationChangeEvent , section : string , scope ?: ConfigurationScope ) : boolean {
60+ // const section: string = <string>args[0];
7261
73- return e . affectsConfiguration ( `${ constants . configId } .${ section } ` ) ;
62+ return e . affectsConfiguration ( `${ constants . configId } .${ section } ` , scope ) ?? true ;
7463 }
7564}
7665
0 commit comments