import { IConnection , RemoteConsole , RemoteWindow , MessageActionItem } from 'vscode-languageserver' ; import { LogLevel , ILogger } from '../interfaces' ; export class RemoteConnectionAdapter implements ILogger { private logger : RemoteConsole ; private window : RemoteWindow ; private level : LogLevel ; public constructor ( connection , level ? ) { this . level = level || LogLevel . error ; this . logger = connection . console ; this . window = connection . window ; } public setLogger ( logger ) { this . logger = logger . console ; } public setLogLevel ( level ) { this . level = level ; } public log ( message ) { if ( this . level >= LogLevel . log ) { this . logger . log ( message ) ; console . log ( message ) ; } } public info ( message , actions ? , callback ? ) { if ( this . level >= LogLevel . info ) { this . logger . info ( message ) ; console . info ( message ) ; if ( actions && callback ) { let messageActionItems = actions . map ( ( action ) => { return < MessageActionItem > { title : action } ; } ) ; this . window . showInformationMessage ( message , ... messageActionItems ) . then ( selected => { callback ( selected . title ) ; } ) ; } } } public warn ( message , actions ? , callback ? ) { if ( this . level >= LogLevel . warn ) { this . logger . warn ( message ) ; console . warn ( message ) ; if ( actions && callback ) { let messageActionItems = actions . map ( ( action ) => { return < MessageActionItem > { title : action } ; } ) ; this . window . showWarningMessage ( message , ... messageActionItems ) . then ( selected => { callback ( selected . title ) ; } ) ; } } } public error ( message , actions ? , callback ? ) { if ( this . level >= LogLevel . error ) { this . logger . error ( message ) ; console . error ( message ) ; if ( actions && callback ) { let messageActionItems = actions . map ( ( action ) => { return < MessageActionItem > { title : action } ; } ) ; this . window . showErrorMessage ( message , ... messageActionItems ) . then ( selected => { callback ( selected . title ) ; } ) ; } } } }