'use strict' ; import * as child_process from 'child_process' ; import * as path from 'path' ; import * as vscode from 'vscode' ; export function startedInDebugMode ( process ) { const args = process . execArgv ; if ( args ) { return args . some ( arg => /^--debug=?/ . test ( arg ) || /^--debug-brk=?/ . test ( arg ) || /^--inspect-brk=?/ . test ( arg ) ) ; } return false ; } export const extension = vscode . extensions . getExtension ( 'SonarSource.sonarlint-vscode' ) ; export const packageJson = extension . packageJSON ; export let extensionPath ; export let extensionContext ; export function setExtensionContext ( context ) { extensionContext = context ; extensionPath = extensionContext . extensionPath ; } export function execChildProcess ( process , workingDirectory , channel ? ) { return new Promise < string > ( ( resolve , reject ) => { child_process . exec ( process , { cwd : workingDirectory , maxBuffer : 500 * 1024 } , ( error , stdout , stderr ) => { if ( channel ) { let message = '' ; let err = false ; if ( stdout && stdout . length > 0 ) { message += stdout ; } if ( stderr && stderr . length > 0 ) { message += stderr ; err = true ; } if ( error ) { message += error . message ; err = true ; } if ( err ) { channel . append ( message ) ; channel . show ( ) ; } } if ( error ) { reject ( error ) ; return ; } if ( stderr && stderr . length > 0 ) { reject ( new Error ( stderr ) ) ; return ; } resolve ( stdout ) ; } ) ; } ) ; } export function resolveExtensionFile ( ... segments ) { return vscode . Uri . file ( path . join ( extensionPath , ... segments ) ) ; }