在 Sublime 3 的 Debian 测试中启用/检测 GoSublime + Linters 时遇到问题。我已经在 OSX 和 Windows 机器上完成了六次,没有失败。
ST 控制台显示:
SublimeLinter: debug mode: off
SublimeLinter: annotations activated: <builtin>
SublimeLinter: WARNING: golint deactivated, cannot locate 'golint'
SublimeLinter: WARNING: gotype deactivated, cannot locate 'gotype'
SublimeLinter: WARNING: govet deactivated, cannot locate 'go'
有趣的是它说它无法找到 go
因为我之前在设置之前没有注意到之前的错误(我修复了)。 Go 就在那里,正如 GoSublime 显示的那样:
GoSblime r13.12.26-3 sh: load env vars ['/bin/bash', '--login', '-c', 'echo "..."']: go version: ['/usr/local/go/bin/go', 'version'] -> `go version go1.3.1 linux/amd64
` -> `go1.3.1`: 0.043s
GoSublime r13.12.26-3: init mod(mg9)
SublimeLinter: debug mode: off
SublimeLinter: json activated: <builtin>
SublimeLinter: annotations activated: <builtin>
** 2014-09-18 08:48:11.608847 **:
GoSublime init r13.12.26-3 (0.001s)
| install margo: no
| install state: done
| sublime.version: 3065
| sublime.channel: stable
| about.ann: a14.02.25-1
| about.version: r13.12.26-3
| version: r13.12.26-3
| platform: linux-x64
| ~bin: ~/.config/sublime-text-3/Packages/User/GoSublime/linux-x64/bin
| margo.exe: ~bin/gosublime.margo_r13.12.26-3_go1.3.1.exe (ok)
| go.exe: /usr/local/go/bin/go (ok)
| go.version: go1.3.1
| GOROOT: /usr/local/go
| GOPATH: ~/go
| GOBIN: (not set) (should usually be `(not set)`)
| set.shell: ['/bin/bash', '--login', '-c', '$CMD']
| env.shell: /bin/bash
| shell.cmd: ['/bin/bash', '--login', '-c', '${CMD}']
--------------------------------
GOBIN(未设置)是另一个有趣的问题,我承认我以前在其他系统上没有注意过。
所以我想这是从 GoSublime 插件代理的 Linter 插件配置的问题?我相信我已经正确设置了它,因为我复制并粘贴了目录并且它们在终端中起作用(告诉我没有输入错误)。
# GoSublime.sublime-settings (User)
{
"env": {
"GOROOT": "/usr/local/go",
"GOPATH": "$HOME/go",
"PATH": "$PATH:$GOROOT/bin:$GOPATH/bin"
}
}
MarGo 也不再提示找不到 GOPATH;所以,我确实设置正确并且它被检测到了。
今天我什至深入研究了很棒的 GoSublime 设置来尝试解决这个问题,并找到了关于设置我可以为 bash 指定的 shell 命令的要点;所以,我现在有这个:
"shell": ["/bin/bash", "--login", "-c", "$CMD"],
"env": {
"GOROOT": "/usr/local/go",
"GOPATH": "$HOME/go",
"PATH": "$PATH:$GOROOT/bin:$GOPATH/bin"
},
但这也没有帮助。
使用以下内容:
Debian Testing (all updated packages)
i3 Window Manager (though I don't think this worked with Gnome)
Go 1.3.1 (built from source release, located at /usr/local/go)
SublimeText 3 3065 (registered)
GoSublime (latest as of posting)
go get github.com/golang/lint (and working in terminal)
go get code.google.com/p/go.tools/cmd/gotype (works in terminal)
go vet (working in terminal)
所有路径都已正确设置。
# i3wm
exec GOPATH="$HOME/go"
exec GOROOT="/usr/local/go"
exec PATH="$PATH:$GOROOT/bin:$GOPATH/bin"
# .bashrc
export GOPATH="$HOME/go"
export GOROOT="/usr/local/go"
PATH="$PATH:$GOROOT/bin:$GOPATH/bin"
这些工作正常,我可以从终端和 i3(在 Go 中编写一些自定义状态栏)运行 Go 命令、安装包等。
GoType 和 GoLint 也已安装,我可以从 bash 运行它们。
通用的 SublimeLinter 加载了正确的 linter。
reloading plugin SublimeLinter-annotations.linter
SublimeLinter: annotations linter loaded
reloading plugin SublimeLinter-contrib-golint.linter
SublimeLinter: golint linter loaded
reloading plugin SublimeLinter-contrib-gotype.linter
SublimeLinter: gotype linter loaded
reloading plugin SublimeLinter-contrib-govet.linter
SublimeLinter: govet linter loaded
reloading plugin SublimeLinter-json.linter
SublimeLinter: json linter loaded
reloading plugin sublimelint.commands
reloading plugin sublimelint.sublimelint
但是,我继续收到开头提到的这些错误。
提前致谢!
最佳答案
我修好了。问题是缺乏对 bash
配置文件的了解。我在 SublimeLinter 页面上找到了有关自定义 linter 故障排除的详细信息。
http://www.sublimelinter.com/en/latest/troubleshooting.html#special-considerations-for-bash
打开调试,我看到 SublimeLinter 使用的扩展 PATH 不包括我的任何自定义 PATH 设置。
简答:
- 将所有
GO
变量移动到.bash_profile
文件 - 将所有
PATH
变量移动到同一个.bash_profile
文件 - 在您的
.bashrc
文件中添加一行以执行交互式终端的.bash_profile
文件
(下面的答案较长,适用于 Linux 用户)
启动终端时,这是一个“交互式”bash shell。 bash 只读取我已正确设置的 .bashrc
文件。我没有 .bash_profile
,因为我的 .bashrc
使用我的所有设置都可以很好地用于交互式 shell。
但是从 SublimeLinter 中,这会加载一个“登录”bash shell - 这不是交互式的。在 Linux 上,这只会加载 .bash_profile
文件 - 而不是 .bashrc
文件。
修复:
将此添加到您的
.bashrc
文件的顶部:来源 ~/.bash_profile
将您的 GO 变量和 PATH 更改(以及仅供引用,您在此 .bashrc 文件中修改的所有其他路径条目)移动到新的
.bash_profile
文件。确保从 .bashrc 中删除它们。
完成。关闭 Sublime 并重新打开。该路径现在已正确拾取。
这是有效的,因为 source ~/.bash_profile
文件会在您打开的每个交互式终端上读取,因为那里使用了 .bashrc 文件。但对于仅登录 session ,例如来自 SublimeLinter 的 session ,仅使用 .bash_profile
- 您的 .bashrc 未执行。
因此,您只想在 .bash_profile
中指定自定义 GO 变量(GOROOT、GOPATH 等),而不是在 .bashrc 中。但是,为了从交互式 shell(例如终端)读取这个 .bash_profile 文件,你必须执行那个 .bash_profile。我们将第一行添加到您的 .bashrc 文件的顶部:source ~/.bash_profile
。这将运行配置文件脚本,该脚本吸收您的自定义 GO 变量以及所有自定义 PATH 变量。
(对于 OSX)请参阅此评论中上面的第一个链接。
您可以在此处阅读有关 bash 文件的更多信息:http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html
关于GoSublime 的 GoLint/GoType 不工作(没有重复),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25913635/