'use strict' ; import path = require ( 'path' ) ; import vscode = require ( 'vscode' ) ; import { getCurrentGoPath , getGoPlusConfig , getToolsGopath } from './util' ; export function toolInstallationEnvironment ( ) { const env = newEnvironment ( ) ; let toolsGopath = getToolsGopath ( ) ; if ( toolsGopath ) { env [ 'GOBIN' ] = '' ; } else { toolsGopath = getCurrentGoPath ( ) ; } if ( ! toolsGopath ) { const msg = 'Cannot install Go tools. Set either go.gopath or go.toolsGopath in settings.' ; vscode . window . showInformationMessage ( msg , 'Open User Settings' , 'Open Workspace Settings' ) . then ( ( selected ) => { switch ( selected ) { case 'Open User Settings' : vscode . commands . executeCommand ( 'workbench.action.openGlobalSettings' ) ; break ; case 'Open Workspace Settings' : vscode . commands . executeCommand ( 'workbench.action.openWorkspaceSettings' ) ; break ; } } ) ; return ; } env [ 'GOPATH' ] = toolsGopath ; return env ; } export function toolExecutionEnvironment ( ) { const env = newEnvironment ( ) ; const gopath = getCurrentGoPath ( ) ; if ( gopath ) { env [ 'GOPATH' ] = gopath ; } return env ; } function newEnvironment ( ) { const toolsEnvVars = getGoPlusConfig ( ) [ 'toolsEnvVars' ] ; const env = Object . assign ( { } , process . env , toolsEnvVars ) ; const httpProxy = vscode . workspace . getConfiguration ( 'http' , null ) . get ( 'proxy' ) ; if ( httpProxy && typeof httpProxy === 'string' ) { env [ 'http_proxy' ] = httpProxy ; env [ 'HTTP_PROXY' ] = httpProxy ; env [ 'https_proxy' ] = httpProxy ; env [ 'HTTPS_PROXY' ] = httpProxy ; } return env ; }