var exec = require ( 'child-process-promise' ) . exec ; var iconv = require ( 'iconv-lite' ) ; import * as vscode from 'vscode' ; function execute ( command ) { var configuration = vscode . workspace . getConfiguration ( 'codegnuglobal' ) ; var encoding = configuration . get < string > ( 'encoding' ) ; var output = 'utf8' ; if ( encoding != null && encoding != "" ) { output = 'binary' ; } return exec ( command , { cwd : vscode . workspace . rootPath , encoding : output , maxBuffer : 10 * 1024 * 1024 } ) . then ( function ( result ) : Buffer { if ( encoding != null && encoding != "" ) { var decoded = iconv . decode ( result . stdout , encoding ) ; return decoded ; } return result . stdout ; } ) . fail ( function ( error ) { console . error ( "Error: " + error ) ; } ) . progress ( function ( childProcess ) { console . log ( "Command: " + command + " running..." ) ; } ) ; } ; export class Global { exec : string ; updateInProgress : boolean ; queueUpdate : boolean ; run ( params ) { return execute ( this . exec + ' ' + params . join ( ' ' ) ) ; } updateTags ( ) { var configuration = vscode . workspace . getConfiguration ( 'codegnuglobal' ) ; var shouldupdate = configuration . get < boolean > ( 'autoupdate' , true ) ; if ( shouldupdate ) { if ( this . updateInProgress ) { this . queueUpdate = true ; } else { this . updateInProgress = true ; var self = this ; this . run ( [ '-u' ] ) . then ( ( ) => { self . updateTagsFinish ( ) ; } ) . catch ( ( ) => { self . updateTagsFinish ( ) ; } ) ; } } } updateTagsFinish ( ) { this . updateInProgress = false ; if ( this . queueUpdate ) { this . queueUpdate = false ; this . updateTags ( ) ; } } parseLine ( content ) { try { if ( content == null || content == "" ) return null ; var values = content . split ( / +/ ) ; var tag = values . shift ( ) ; var line = parseInt ( values . shift ( ) ) - 1 ; var path = values . shift ( ) . replace ( "%20" , " " ) ; var info = values . join ( ' ' ) ; return { "tag" : tag , "line" : line , "path" : path , "info" : info , "kind" : this . parseKind ( info ) } ; } catch ( ex ) { console . error ( "Error: " + ex ) ; } return null ; } private parseKind ( info ) { var kind = vscode . SymbolKind . Variable ; if ( info . startsWith ( 'class ' ) ) { kind = vscode . SymbolKind . Class ; } else if ( info . startsWith ( 'struct ' ) ) { kind = vscode . SymbolKind . Class ; } else if ( info . startsWith ( 'enum ' ) ) { kind = vscode . SymbolKind . Enum ; } else if ( info . indexOf ( '(' ) != - 1 ) { kind = vscode . SymbolKind . Function ; } return kind ; } constructor ( exec ) { this . exec = exec ; } }