import { inject , injectable } from 'inversify' ; import type * as vscode from 'vscode' ; import { Configuration } from '.' ; import { VsCodeApi } from '../ioc/types' ; export const IConfigurationAccessor = Symbol ( 'ConfigurationAccessor' ) ; /**
 * An injectable abstraction over vscodes Configuration API.
 */ export interface IConfigurationAccessor { get < T > ( section , defaultValue ) : T ; update < T > ( section , value , updateGlobally ? ) : Promise < void > ; hasGlobal ( section ) : boolean ; onDidChangeConfiguration : vscode . Event < vscode . ConfigurationChangeEvent > ; } @ injectable ( ) export default class ConfigurationAccessor implements IConfigurationAccessor { constructor ( @ inject ( VsCodeApi ) private readonly vscodeApi ) { } get < T > ( section , defaultValue ) { const v = this . vscodeApi . workspace . getConfiguration ( ) . get ( section , defaultValue ) ; return v ; } hasGlobal ( section ) { const inspection = this . vscodeApi . workspace . getConfiguration ( ) . inspect ( section ) ; if ( inspection ) { return inspection . globalValue !== undefined ; } return false ; } async update < T > ( section , value , updateGlobally = true ) { await this . vscodeApi . workspace . getConfiguration ( ) . update ( section , value , updateGlobally ) ; } onDidChangeConfiguration ( handler , thisArg ? , disposables ? ) { return this . vscodeApi . workspace . onDidChangeConfiguration ( handler , thisArg , disposables ) ; } }