import { StatusBarItem , workspace , WorkspaceConfiguration } from "coc.nvim" ; import * as metalsLanguageClient from "metals-languageclient" ; import { downloadProgress } from "metals-languageclient" ; import { ChildProcessPromise } from "promisify-child-process" ; import { Commands } from "./commands" ; export function trackDownloadProgress ( title , download , progress ) { return downloadProgress ( { download , onProgress : ( _ ) => { progress . text = title ; progress . show ( ) ; } , onError : progress . dispose , onComplete : progress . dispose , } ) ; } export function checkServerVersion ( config ) { metalsLanguageClient . checkServerVersion ( { config , updateConfig : ( { configSection , latestServerVersion } ) => { config . update ( configSection , latestServerVersion , true ) ; } , onOutdated : ( { message , upgradeChoice , openSettingsChoice , dismissChoice , upgrade , } ) => { workspace . showQuickpick ( [ upgradeChoice , openSettingsChoice , dismissChoice ] , message ) . then ( ( choice ) => { if ( choice === 0 ) { upgrade ( ) ; } else if ( choice === 1 ) { workspace . nvim . command ( Commands . OPEN_COC_CONFIG , true ) ; } } ) ; } , } ) ; } export function toggleLogs ( ) { const logsBuffer = workspace . documents . find ( ( doc ) => doc . uri == "output:/metals" ) ; if ( logsBuffer ) { workspace . nvim . command ( `bd ${ logsBuffer . bufnr }` ) ; } else { workspace . nvim . command ( Commands . OPEN_LOGS ) ; } } export function wait ( ms ) { return new Promise ( ( resolve ) => { setTimeout ( resolve , ms ) ; } ) ; } export function detectLaunchConfigurationChanges ( ) { metalsLanguageClient . detectLaunchConfigurationChanges ( workspace , ( { message , reloadWindowChoice , dismissChoice } ) => { return workspace . showQuickpick ( [ reloadWindowChoice , dismissChoice ] , message ) . then ( ( choice ) => { if ( choice === 0 ) { workspace . nvim . command ( Commands . RESTART_COC , true ) ; } } ) ; } , [ "statusBarEnabled" , "bloopVersion" , "enable" ] ) ; }