import * as vscode from 'vscode' ; const typeScriptExtensionId = 'vscode.typescript-language-features' ; const pluginId = 'ts-react-hooks-tools' ; const configurationSection = 'trht' ; interface SynchronizedConfiguration { preferFullAccess ? : boolean ; preferImmutableCall ? : boolean ; preferConstantCall ? : boolean ; } export async function activate ( context ) { const extension = vscode . extensions . getExtension ( typeScriptExtensionId ) ; if ( ! extension ) { return ; } await extension . activate ( ) ; if ( ! extension . exports || ! extension . exports . getAPI ) { return ; } const api = extension . exports . getAPI ( 0 ) ; if ( ! api ) { return ; } vscode . workspace . onDidChangeConfiguration ( ( e ) => { if ( e . affectsConfiguration ( configurationSection ) ) { synchronizeConfiguration ( api ) ; } } , undefined , context . subscriptions ) ; synchronizeConfiguration ( api ) ; } function synchronizeConfiguration ( api ) { api . configurePlugin ( pluginId , getConfiguration ( ) ) ; } function getConfiguration ( ) { const config = vscode . workspace . getConfiguration ( configurationSection ) ; const outConfig = { } ; withConfigValue ( config , outConfig , 'preferFullAccess' ) ; withConfigValue ( config , outConfig , 'preferImmutableCall' ) ; withConfigValue ( config , outConfig , 'preferConstantCall' ) ; return outConfig ; } function withConfigValue < C , K extends Extract < keyof C , string > > ( config , outConfig , key ) { const configSetting = config . inspect < C [ K ] > ( key ) ; if ( ! configSetting ) { return ; } if ( typeof configSetting . globalValue === 'undefined' && typeof configSetting . workspaceFolderValue === 'undefined' && typeof configSetting . workspaceValue === 'undefined' ) { return ; } const value = config . get < vscode . WorkspaceConfiguration [ K ] | undefined > ( key , undefined ) ; if ( typeof value !== 'undefined' ) { ( outConfig as any ) [ key ] = value ; } }