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.
- Loading branch information
1 parent
97ffefc
commit f771895
Showing
6 changed files
with
73 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import path = require('path'); | ||
import vscode = require('vscode'); | ||
import { getToolsEnvVars, getCurrentGoPath } from './util'; | ||
import { outputChannel } from './goStatus'; | ||
import { getCurrentGoWorkspaceFromGOPATH, getGoRuntimePath } from './goPath'; | ||
import cp = require('child_process'); | ||
|
||
export function installCurrentPackage() { | ||
let editor = vscode.window.activeTextEditor; | ||
if (!editor) { | ||
vscode.window.showInformationMessage('No editor is active, cannot find current package to install'); | ||
return; | ||
} | ||
if (editor.document.languageId !== 'go') { | ||
vscode.window.showInformationMessage('File in the active editor is not a Go file, cannot find current package to install'); | ||
return; | ||
} | ||
|
||
let goRuntimePath = getGoRuntimePath(); | ||
if (!goRuntimePath) { | ||
vscode.window.showInformationMessage('Cannot find "go" binary. Update PATH or GOROOT appropriately'); | ||
return; | ||
} | ||
|
||
const env = Object.assign({}, getToolsEnvVars()); | ||
const cwd = path.dirname(editor.document.uri.fsPath); | ||
const goConfig = vscode.workspace.getConfiguration('go', editor.document.uri); | ||
const args = ['install']; | ||
|
||
if (goConfig['buildTags']) { | ||
args.push('-tags', '"' + goConfig['buildTags'] + '"'); | ||
} | ||
|
||
// Find the right importPath instead of directly using `.`. Fixes https://github.com/Microsoft/vscode-go/issues/846 | ||
const currentGoWorkspace = getCurrentGoWorkspaceFromGOPATH(getCurrentGoPath(), cwd); | ||
const importPath = currentGoWorkspace ? cwd.substr(currentGoWorkspace.length + 1) : '.'; | ||
args.push(importPath); | ||
|
||
outputChannel.clear(); | ||
outputChannel.show(); | ||
outputChannel.appendLine(`Installing ${importPath === '.' ? 'current package' : importPath}`); | ||
|
||
cp.execFile(goRuntimePath, args, { env, cwd }, (err, stdout, stderr) => { | ||
outputChannel.appendLine(err ? `Installation failed: ${stderr}` : `Installation successful`); | ||
}); | ||
} |
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