import * as vscode from 'vscode' ; interface LanguageConfig { readonly unicodeCompletionsEnabled ? : boolean ; readonly markupCompletionsEnabled ? : boolean ; readonly showOnColon ? : boolean ; readonly emojiDecoratorsEnabled ? : boolean ; } export class Configuration implements LanguageConfig { public get languages ( ) : Iterable < string > { return this . languageConfigurations . keys ( ) ; } public unicodeCompletionsEnabled = true ; public markupCompletionsEnabled = true ; public showOnColon = true ; public emojiDecoratorsEnabled = true ; private languageConfigurations = new Map < string , LanguageConfig > ( ) ; constructor ( ) { this . updateConfiguration ( ) ; } public areUnicodeCompletionsEnabled ( document ) { return this . is ( 'unicodeCompletionsEnabled' , this . getLanguageId ( document ) ) ; } public areMarkupCompletionsEnabled ( document ) { return this . is ( 'markupCompletionsEnabled' , this . getLanguageId ( document ) ) ; } public shouldShowOnColon ( forLanguage ) { return this . is ( 'showOnColon' , forLanguage ) ; } public isInlineEnabled ( forLanguage ) { return this . is ( 'emojiDecoratorsEnabled' , forLanguage ) ; } public updateConfiguration ( ) { const config = vscode . workspace . getConfiguration ( 'emojisense' ) ; this . unicodeCompletionsEnabled = config . get < boolean > ( 'unicodeCompletionsEnabled' , true ) ; this . markupCompletionsEnabled = config . get < boolean > ( 'markupCompletionsEnabled' , true ) ; this . showOnColon = config . get < boolean > ( 'showOnColon' , true ) ; this . emojiDecoratorsEnabled = config . get < boolean > ( 'emojiDecoratorsEnabled' , true ) ; this . languageConfigurations = new Map ( ) ; const languagesConfig = config . get < any > ( 'languages' , { } ) ; for ( const language of Object . keys ( languagesConfig || { } ) ) { const configValue = languagesConfig [ language ] ; const languageName = language . toLowerCase ( ) ; if ( typeof configValue === 'boolean' ) { if ( configValue ) { this . languageConfigurations . set ( languageName , { } ) ; } } else { this . languageConfigurations . set ( languageName , configValue ) ; } } } private getLanguageId ( document ) { return document . languageId ; } private is ( setting , forLanguage ) { const languageConfig = this . getLanguageConfig ( forLanguage ) ; if ( ! languageConfig ) { return false ; } return typeof languageConfig [ setting ] !== 'undefined' ? ! ! languageConfig [ setting ] : this [ setting ] ; } private getLanguageConfig ( languageId ) { return this . languageConfigurations . get ( languageId . toLowerCase ( ) ) ; } }