forked from golang/vscode-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src: refactor tools env variables to handle installation and execution
I modified this change to focus only on addressing the differences between environment variables when installing tools vs. when running them. https://golang.org/cl/233325 now handles the issue reports on restart. Change-Id: I9d03e2c8f9244bade19606e9d9c6892da9fa0c66 GitHub-Last-Rev: e6f4db3 GitHub-Pull-Request: golang#28 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/232863 Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
- Loading branch information
1 parent
bc0a099
commit ab4483e
Showing
29 changed files
with
177 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/*--------------------------------------------------------- | ||
* Copyright (C) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE in the project root for license information. | ||
*--------------------------------------------------------*/ | ||
|
||
'use strict'; | ||
|
||
import path = require('path'); | ||
import vscode = require('vscode'); | ||
import { getCurrentGoPath, getGoConfig, getToolsGopath, resolvePath } from './util'; | ||
|
||
// toolInstallationEnvironment returns the environment in which tools should | ||
// be installed. It always returns a new object. | ||
export function toolInstallationEnvironment(): NodeJS.Dict<string> { | ||
const env = newEnvironment(); | ||
|
||
// If the go.toolsGopath is set, use its value as the GOPATH for `go` processes. | ||
// Else use the Current Gopath | ||
let toolsGopath = getToolsGopath(); | ||
if (toolsGopath) { | ||
// User has explicitly chosen to use toolsGopath, so ignore GOBIN. | ||
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; | ||
} | ||
|
||
// toolExecutionEnvironment returns the environment in which tools should | ||
// be executed. It always returns a new object. | ||
export function toolExecutionEnvironment(): NodeJS.Dict<string> { | ||
const env = newEnvironment(); | ||
const gopath = getCurrentGoPath(); | ||
if (gopath) { | ||
env['GOPATH'] = gopath; | ||
} | ||
return env; | ||
} | ||
|
||
function newEnvironment(): NodeJS.Dict<string> { | ||
const toolsEnvVars = getGoConfig()['toolsEnvVars']; | ||
const env = Object.assign({}, process.env, toolsEnvVars); | ||
|
||
// The http.proxy setting takes precedence over environment variables. | ||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.