SublimeLinter/SublimeLinter-gotype

Gotype fails to import subpackages of the same project

obi1kenobi opened this issue · 8 comments

Say you have a project that is organized as follows:

$GOPATH/
+src/
 +name/
  +a/
   +a.go
  +b/
   +b.go

It is perfectly legal for b.go to have a line such as import name/a. However, in the current setup, gotype fails to do the import (presumably because of the way files are copied to the temp directory). As a result, I get a ton of lint errors on everything that uses that package, even though the code will run just fine.

I am currently forced to run gotype with the following ignore_match settings:

"could not import [a-z/]* \\(can't find import: [a-z/]*\\)",
"undeclared name: [a-zA-Z_]*"

I was wondering if there is something I am doing wrong, or if this is a bug in the plugin.

If that's legal go, you're not doing anything wrong. This is just a limitation of the current plugin implementation.

I ran into the same issue. It turned out that the problem is with the way I run Sublime: when started it from terminal, everything works fine, as $GOPATH is set in .bashrc. However, if started it from the dock, .bashrc is not used, and gotype doesn't know where to look for references. I guess it behaves the same if you have Go installed to a place different than /usr/local/go - $GOROOT is missing.

Adding the env.variables to .profile fixes the problem for me.

Additionally, I changed the plugin to just this

    from SublimeLinter.lint import Linter, util
    class Gotype(Linter):
        """Provides an interface to gotype."""

        syntax = ('go', 'gosublime-go')
        cmd = ('gotype', '-e', '-a')  # no last file/dir parameter - use stdin
        regex = r'^.+:(?P<line>\d+):(?P<col>\d+):\s+(?P<message>.+)'
        error_stream = util.STREAM_STDERR

It works without overriding Run, as this results in gotype reading from stdin

Apologies for leaving this hanging for so long. I haven't ended up actually using this plugin, so I'd appreciate PRs or would be happy to name co-maintainers if you're interested in collaborating.

Btw another way to get this working in OSX is to run this command:

$ launchctl setenv GOPATH $GOPATH

Sublime will now see the GOPATH regardless of where it was launched from.

That's because this plugin copies files over to the temp dir. Why would you do that?

any news on the bug?

@zj8487 This issue contains all the news on this bug.

If anyone would like to fix this, or help out with this plugin in a permanent way, that would be more than welcome.

To be completely transparent, this is a linting plugin for a language I don't use for an editor I don't use. It's extremely unlikely I will be working on this further.

rasky commented

The main issue of this bug can't be fixed; if a GOPATH isn't defined, there's nothing the plugin can do. You can also define one in the plugin configuration, if you want (there's a configuration key gopath for that).

The other issue (running gotype on the full package) is fixed in 1.2.0, just released.