import { WorkerManager } from './workerManager' ; import { LanguageServiceDefaults } from './_.contribution' ; import * as languageFeatures from './languageFeatures' ; import { Uri , IDisposable } from './fillers/monaco-editor-core' ; export function setupLanguageMode < T extends languageFeatures . IWorker > ( defaults ) { const disposables = [ ] ; const providers = [ ] ; const client = new WorkerManager ( defaults ) ; disposables . push ( client ) ; const worker = ( ... uris ) : Promise < any > => { return client . getLanguageServiceWorker ( ... uris ) ; } ; function registerProviders ( ) { const { languageId , modeConfiguration } = defaults ; disposeAll ( providers ) ; if ( modeConfiguration . diagnostics ) { providers . push ( new languageFeatures . DiagnosticsAdapter ( languageId , worker , defaults ) ) ; } } registerProviders ( ) ; disposables . push ( asDisposable ( providers ) ) ; return asDisposable ( disposables ) ; } function asDisposable ( disposables ) { return { dispose : ( ) => disposeAll ( disposables ) } ; } function disposeAll ( disposables ) { while ( disposables . length ) { disposables . pop ( ) ?. dispose ( ) ; } }