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 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)