GoSublime的GoLint / GoType无效(无重复)

时间:2014-09-18 13:12:12

标签: go sublimelinter gosublime

在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,因为我之前没有注意到之前的错误(我修复了)。正如GoSublime所示,Go就在那里:

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加载了正确的链接。

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

但是,我仍然会在开头提到这些错误。

提前致谢!

1 个答案:

答案 0 :(得分:1)

我修好了。问题是缺乏bash配置文件的知识。我在SublimeLinter页面上找到了有关自定义链接的故障排除的详细信息。

http://www.sublimelinter.com/en/latest/troubleshooting.html#special-considerations-for-bash

打开Debug,我看到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文件的顶部:

    source~ / .bash_profile

  • 将GO变量和PATH更改(以及您在此.bashrc文件中修改过的所有其他路径条目)移动到新的.bash_profile文件。确保从.bashrc中删除它们。

完成。关闭Sublime并重新打开。现在正确地选择了路径。

这是有效的,因为在您打开的每个交互式终端上都会读取source ~/.bash_profile文件,因为在那里使用了.bashrc文件。但是对于仅登录会话,例如来自SublimeLinter的会话,只使用.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

相关问题