GoSublime的GoLint / GoType无法工作(没有重复)

huangapple go评论97阅读模式
英文:

GoSublime's GoLint / GoType not working (no duplicate)

问题

在Debian Testing的Sublime 3中,我在启用/检测GoSublime + Linters方面遇到了问题。在OSX和Windows机器上,我已经成功地完成了这个操作多次。

Sublime Text控制台显示:

SublimeLinter: debug mode: off
SublimeLinter: annotations activated:
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:
SublimeLinter: annotations activated:

GOBIN(未设置)也是一个有趣的问题,我承认在其他系统上以前没有注意到这个。

所以这可能是与Linter插件配置有关的问题,我想象是从GoSublime插件代理过来的?我相信我已经正确设置了它,因为我复制并粘贴了目录,并且它们在终端中运行正常(告诉我没有拼写错误)。

以下是我的GoSublime.sublime-settings(用户)文件的内容:

{
"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(所有更新的软件包)
i3窗口管理器(尽管我认为它在Gnome上无法工作)
Go 1.3.1(从源代码发布构建,位于/usr/local/go)
Sublime Text 3 3065(已注册)
GoSublime(最新版本)
go get github.com/golang/lint(在终端中工作)
go get code.google.com/p/go.tools/cmd/gotype(在终端中工作)
go vet(在终端中工作)

所有路径都正确设置。

以下是我的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命令,安装包等。

GoType和GoLint也已安装,并且我可以从bash中运行它们。

通用的SublimeLinter已加载正确的linters。

重新加载插件SublimeLinter-annotations.linter
SublimeLinter: annotations linter loaded
重新加载插件SublimeLinter-contrib-golint.linter
SublimeLinter: golint linter loaded
重新加载插件SublimeLinter-contrib-gotype.linter
SublimeLinter: gotype linter loaded
重新加载插件SublimeLinter-contrib-govet.linter
SublimeLinter: govet linter loaded
重新加载插件SublimeLinter-json.linter
SublimeLinter: json linter loaded
重新加载插件sublimelint.commands
重新加载插件sublimelint.sublimelint

但是,我仍然得到了一开始提到的这些错误。

提前感谢您的帮助!

英文:

Having a problem getting GoSublime + Linters enabled/detected on Debian Testing in Sublime 3. I've done this a half a dozen times on OSX and Windows machines without fail.

The ST console says:

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'

Interesting how it says it can't locate go as I haven't noticed that one before when setting things up with previous errors (that I fixed up). Go is there, as the GoSublime shows:

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}']
--------------------------------

The GOBIN (not set) is another interesting one that I admit I haven't paid attention to before on other systems.

So it's a problem with the Linter plugin configuration that is proxied from the GoSublime plugin I would imagine? I believe I have it set correctly, as I copy-n-paste the directories and they function in terminal (telling me there is no typeo).

# GoSublime.sublime-settings (User)
{
	"env": { 
		"GOROOT": "/usr/local/go",
		"GOPATH": "$HOME/go",
		"PATH": "$PATH:$GOROOT/bin:$GOPATH/bin"
	}
}

MarGo doesn't complain that it cannot find the GOPATH any longer either; so, I do have that set right and it is detected.

I even dug into the wonderful GoSublime settings today to try to resolve this and found the nugget about setting the shell command I can specify for bash; so, I now have this:

"shell": ["/bin/bash", "--login", "-c", "$CMD"],
"env": { 
	"GOROOT": "/usr/local/go",
	"GOPATH": "$HOME/go",
	"PATH": "$PATH:$GOROOT/bin:$GOPATH/bin"
},

But that didn't help either.

Using the following:

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)

All paths are setup correctly.

# 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"

These work fine and I can run Go commands, install packages, etc from both terminal and from i3 (writing some custom statusbars in Go).

GoType and GoLint are installed as well, and I can run them from bash.

The general SublimeLinter is loaded with correct linters.

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

But yet, I continue to get these errors as mentioned at the beginning.

Thanks in advance!

答案1

得分: 1

我已经修复了。问题是对bash配置文件的了解不足。我在SublimeLinter的故障排除页面上找到了详细信息。

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

通过打开调试模式,我发现SublimeLinter使用的扩展路径不包括我的自定义路径设置。

简短回答:

  • 将所有的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

英文:

I fixed it. The issue was a lack of knowledge of bash config files. I found the details on the SublimeLinter page for troubleshooting custom linters.

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

Turning on Debug, I saw that the expanded PATH that the SublimeLinter was using did not include any of my custom PATH settings.

Short answer:

  • move all of your GO variables to a .bash_profile file
  • move all of your PATH variables to that same .bash_profile file
  • add a line to your .bashrc file to execute the .bash_profile file for interactive terminals

(Longer answer below, for Linux users)

When starting a terminal, this is an "interactive" bash shell. bash reads the .bashrc file only, which I had setup correctly. I did not have a .bash_profile as my .bashrc worked fine for interactive shells with all of my settings.

But from within SublimeLinter, this loads a "login" bash shell - that is not interactive. On Linux, this only loads the .bash_profile file - not the .bashrc file.

The fix:

  • Add this to the top of your .bashrc file:

    source ~/.bash_profile

  • Move your GO variables and PATH changes (and FYI, ALL OTHER path entries you've modified in this .bashrc file) to a new .bash_profile file. Make sure to remove them from .bashrc.

Done. Close Sublime and reopen. The path is now picked up properly.

This works because the source ~/.bash_profile file is read on every interactive terminal you open, cause the .bashrc file is used there. But for login only sessions, such as the one from SublimeLinter, only the .bash_profile is used - your .bashrc is not executed.

So, you want to specify your custom GO variables (GOROOT, GOPATH, etc) in your .bash_profile only, not in the .bashrc. But, in order to read this .bash_profile file from interactive shells (e.g. terminals), you have to execute that .bash_profile. We do this with the first line to add at the top of your .bashrc file: source ~/.bash_profile. This runs the profile script that sucks in your custom GO variables, as well as all of your custom PATH variables.

(for OSX) See the first link above in this comment.

You can read more about bash files here: http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html

huangapple
  • 本文由 发表于 2014年9月18日 21:12:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/25913635.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定