import { workspace , WorkspaceConfiguration } from 'vscode' ; import which from 'which' ; import { join } from 'path' ; import { DocumentSelector } from 'vscode-languageserver-protocol' ; import { showOpenSettingsPrompt } from './utils' ; export class ConfigurationService { private config : { [ key ] : any ; } = { } ; public constructor ( ) { } public async init ( ) { const workspaceConfiguration = workspace . getConfiguration ( 'psalm' ) ; this . config . phpExecutablePath = workspaceConfiguration . get < string > ( 'phpExecutablePath' ) || ( await which ( 'php' ) ) ; this . config . phpExecutableArgs = workspaceConfiguration . get < string [ ] > ( 'phpExecutableArgs' ) || [ '-dxdebug.remote_autostart=0' , '-dxdebug.remote_enable=0' , '-dxdebug_profiler_enable=0' , ] ; this . config . psalmScriptPath = workspaceConfiguration . get < string > ( 'psalmScriptPath' ) || join ( 'vendor' , 'vimeo' , 'psalm' , 'psalm-language-server' ) ; this . config . psalmScriptArgs = workspaceConfiguration . get < string [ ] > ( 'psalmScriptArgs' ) || [ ] ; this . config . disableAutoComplete = workspaceConfiguration . get < boolean > ( 'disableAutoComplete' ) || false ; this . config . maxRestartCount = workspaceConfiguration . get < number > ( 'maxRestartCount' ) || 5 ; this . config . unusedVariableDetection = workspaceConfiguration . get < boolean > ( 'unusedVariableDetection' ) || false ; this . config . enableVerbose = workspaceConfiguration . get < boolean > ( 'enableVerbose' ) || false ; this . config . connectToServerWithTcp = workspaceConfiguration . get < boolean > ( 'connectToServerWithTcp' ) || false ; this . config . enableUseIniDefaults = workspaceConfiguration . get < boolean > ( 'enableUseIniDefaults' ) || false ; this . config . logLevel = workspaceConfiguration . get < string > ( 'logLevel' ) || 'INFO' ; this . config . analyzedFileExtensions = workspaceConfiguration . get < string [ ] | DocumentSelector > ( 'analyzedFileExtensions' ) || [ { scheme : 'file' , language : 'php' } ] ; this . config . configPaths = workspaceConfiguration . get < string [ ] > ( 'configPaths' ) || [ 'psalm.xml' , 'psalm.xml.dist' ] ; this . config . hideStatusMessageWhenRunning = workspaceConfiguration . get < boolean > ( 'hideStatusMessageWhenRunning' ) || false ; } public async validate ( ) { if ( ! this . config . psalmServerScriptPath ) { await showOpenSettingsPrompt ( 'The setting psalm.psalmScriptPath must be provided (e.g. vendor/bin/psalm-language-server)' ) ; return false ; } return true ; } public get < T > ( key ) { if ( ! ( key in this . config ) ) { throw new Error ( `Key ${ key } not found in configuration` ) ; } return this . config [ key ] ; } public getAll ( ) { return this . config ; } }