2014-09-18 13:12

GoSublime的GoLint / GoType不起作用(无重复)

  • sublimelinter

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
| 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)`)
| ['/bin/bash', '--login', '-c', '$CMD']
| /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 (and working in terminal) 
go get (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"

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!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • dongxiang3205 dongxiang3205 7年前

    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.

    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:

    点赞 评论 复制链接分享