dongsuikai8286 2014-09-18 13:12 采纳率: 100%
浏览 127
已采纳

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

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条回答 默认 最新

  • dongxiang3205 2014-10-08 21:56
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler