import { Models } from 'omnisharp-client' ; import { Omni } from '../server/omni' ; const Range = require ( 'atom' ) . Range ; import { each } from 'lodash' ; import { CompositeDisposable } from 'ts-disposables' ; interface LinterMessage { type : string ; text ? : string ; html ? : string ; filePath ? : string ; range ? : Range ; [ key ] : any ; } interface IndieRegistry { register ( options ) : Indie ; has ( indie ) : Boolean ; unregister ( indie ) : void ; } interface Indie { setMessages ( messages ) : void ; deleteMessages ( ) : void ; dispose ( ) : void ; } function mapIndieValues ( error ) { const level = error . LogLevel . toLowerCase ( ) ; return { type : level , text : `${ error . Text } [${ Omni . getFrameworks ( error . Projects ) }] ` , filePath : error . FileName , range : new Range ( [ error . Line , error . Column ] , [ error . EndLine , error . EndColumn ] ) } ; } function showLinter ( ) { each ( document . querySelectorAll ( 'linter-bottom-tab' ) , ( element ) => { element . style . display = '' ; } ) ; each ( document . querySelectorAll ( 'linter-bottom-status' ) , ( element ) => { element . style . display = '' ; } ) ; const panel = < HTMLElement > document . querySelector ( 'linter-panel' ) ; if ( panel ) panel . style . display = '' ; } function hideLinter ( ) { each ( document . querySelectorAll ( 'linter-bottom-tab' ) , ( element ) => { element . style . display = 'none' ; } ) ; each ( document . querySelectorAll ( 'linter-bottom-status' ) , ( element ) => { element . style . display = 'none' ; } ) ; const panel = < HTMLElement > document . querySelector ( 'linter-panel' ) ; if ( panel ) panel . style . display = 'none' ; } let showHiddenDiagnostics = true ; export function init ( linter ) { const disposable = new CompositeDisposable ( ) ; let cd ; disposable . add ( atom . config . observe ( 'omnisharp-atom.hideLinterInterface' , hidden => { if ( hidden ) { cd = new CompositeDisposable ( ) ; disposable . add ( cd ) ; cd . add ( Omni . activeEditor . filter ( z => ! z ) . subscribe ( showLinter ) ) ; cd . add ( Omni . activeEditor . filter ( z => ! ! z ) . subscribe ( hideLinter ) ) ; } else { if ( cd ) { disposable . remove ( cd ) ; cd . dispose ( ) ; } showLinter ( ) ; } } ) ) ; disposable . add ( atom . config . observe ( 'omnisharp-atom.showHiddenDiagnostics' , show => { showHiddenDiagnostics = show ; atom . workspace . getTextEditors ( ) . forEach ( editor => { const editorLinter = linter . getEditorLinter ( editor ) ; if ( editorLinter ) { editorLinter . lint ( true ) ; } } ) ; } ) ) ; disposable . add ( Omni . activeEditor . filter ( z => ! ! z ) . take ( 1 ) . delay ( 1000 ) . subscribe ( e => { Omni . whenEditorConnected ( e ) . subscribe ( ( ) => { atom . workspace . getTextEditors ( ) . forEach ( editor => { const editorLinter = linter . getEditorLinter ( editor ) ; if ( editorLinter ) { editorLinter . lint ( true ) ; } } ) ; } ) ; } ) ) ; return disposable ; } export function registerIndie ( registry , disposable ) { const linter = registry . register ( { name : 'c#' } ) ; disposable . add ( linter , Omni . diagnostics . subscribe ( diagnostics => { const messages = [ ] ; for ( const item of diagnostics ) { if ( showHiddenDiagnostics || item . LogLevel !== 'Hidden' ) { messages . push ( mapIndieValues ( item ) ) ; } } linter . setMessages ( messages ) ; } ) ) ; }