This repository has been archived by the owner on Jul 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 645
Add go.toolCommands
which specifies alternate command locations
#1297
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f0013b9
Add `go.toolCommands` which specifies alternate command locations
ikedam c9a4138
Merge remote-tracking branch 'origin/master' into feature/toolCommands
ramya-rao-a b273fd5
gopath shldnt have dependency on vscode, fixing for Windows
ramya-rao-a 42a4c40
vsix for testing
ramya-rao-a a6481e3
Merge remote-tracking branch 'origin/master' into feature/toolCommands
ramya-rao-a f138531
Better name for setting
ramya-rao-a e78b476
Combine getGoRuntimePathInternal into getBinPathWithPreferredGopath
ramya-rao-a 69bc71c
Update config description
ramya-rao-a d21f4b8
Add top used tools to alternate tools setting
ramya-rao-a a52239b
If absolute alternate path doesnt exist, ignore it
ramya-rao-a File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -11,16 +11,21 @@ | |
import fs = require('fs'); | ||
import path = require('path'); | ||
import os = require('os'); | ||
import vscode = require('vscode'); | ||
|
||
let binPathCache: { [bin: string]: string; } = {}; | ||
let runtimePathCache: string = ''; | ||
|
||
export function getBinPathFromEnvVar(toolName: string, envVarValue: string, appendBinToPath: boolean): string { | ||
toolName = correctBinname(toolName); | ||
let binname = correctBinname(toolName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if (path.isAbsolute(binname)) { | ||
binPathCache[toolName] = binname; | ||
return binname; | ||
} | ||
if (envVarValue) { | ||
let paths = envVarValue.split(path.delimiter); | ||
for (let i = 0; i < paths.length; i++) { | ||
let binpath = path.join(paths[i], appendBinToPath ? 'bin' : '', toolName); | ||
let binpath = path.join(paths[i], appendBinToPath ? 'bin' : '', binname); | ||
if (fileExists(binpath)) { | ||
binPathCache[toolName] = binpath; | ||
return binpath; | ||
|
@@ -30,8 +35,14 @@ export function getBinPathFromEnvVar(toolName: string, envVarValue: string, appe | |
return null; | ||
} | ||
|
||
export function getBinPathWithPreferredGopath(binname: string, ...preferredGopaths) { | ||
if (binPathCache[correctBinname(binname)]) return binPathCache[correctBinname(binname)]; | ||
export function getBinPathWithPreferredGopath(toolName: string, ...preferredGopaths) { | ||
if (binPathCache[toolName]) return binPathCache[toolName]; | ||
|
||
let binname = correctBinname(toolName); | ||
if (path.isAbsolute(binname)) { | ||
// Configured by the user | ||
return binname; | ||
} | ||
|
||
for (let i = 0; i < preferredGopaths.length; i++) { | ||
if (typeof preferredGopaths[i] === 'string') { | ||
|
@@ -59,11 +70,36 @@ export function getBinPathWithPreferredGopath(binname: string, ...preferredGopat | |
return binname; | ||
} | ||
|
||
function correctBinname(binname: string) { | ||
/** | ||
* Returns the actual name of the tool. | ||
* | ||
* This can be overridden with `go.toolCommands` configuration. | ||
* | ||
* @param toolName the name of the tool such as "go", "godoc" and so on. | ||
* | ||
* @return the actual name of the tool, such as "go", "go.exe", "/path/to/go". | ||
* May be an absolute path or only a file name (relative to GOROOT/bin). | ||
* Returns an absolute path only when it exists. | ||
*/ | ||
function correctBinname(toolName: string) { | ||
let goConfig = vscode.workspace.getConfiguration('go'); | ||
let toolCommands = goConfig['toolCommands']; | ||
if (toolCommands[toolName]) { | ||
let binname = toolCommands[toolName]; | ||
if (!path.isAbsolute(binname)) { | ||
// Relative name like 'go.sh', 'go.bat' | ||
return binname; | ||
} | ||
// Absolute path. | ||
// Valid only when it exists. | ||
if (fileExists(binname)) { | ||
return binname; | ||
} | ||
} | ||
if (process.platform === 'win32') | ||
return binname + '.exe'; | ||
return toolName + '.exe'; | ||
else | ||
return binname; | ||
return toolName; | ||
} | ||
|
||
/** | ||
|
@@ -74,6 +110,9 @@ function correctBinname(binname: string) { | |
export function getGoRuntimePath(): string { | ||
if (runtimePathCache) return runtimePathCache; | ||
let correctBinNameGo = correctBinname('go'); | ||
if (path.isAbsolute(correctBinNameGo)) { | ||
return correctBinNameGo; | ||
} | ||
if (process.env['GOROOT']) { | ||
let runtimePathFromGoRoot = path.join(process.env['GOROOT'], 'bin', correctBinNameGo); | ||
if (fileExists(runtimePathFromGoRoot)) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is used by the debug adapter via the
goDebug.ts
file. The debug adapter runs in a different process than the extension host and so will not have access tovscode