sourcegraph / go-langserver

Go language server to add Go support to editors and other tools that use the Language Server Protocol (LSP)
https://sourcegraph.com
MIT License
1.17k stars 89 forks source link

implementations: "this function is not a method" error could just simply be "no results" #307

Open slimsag opened 6 years ago

slimsag commented 6 years ago

If you find implementations on a function rather than a method, you get an error:

Error getting implementations: This function is not a method

e.g. https://sourcegraph.com/github.com/sourcegraph/go-langserver/-/blob/langserver/implementation.go#L65:6&tab=impl

Of course, finding implementations on a function doesn't make sense. It only works on interface types and methods (finding the interfaces that implement that method).

We could make this error less confusing by e.g. just returning no error and simply returning no results.

The error originates from here: https://sourcegraph.com/github.com/sourcegraph/go-langserver@bf90fac03a4d1a07f50701547d56fabfdb0c32ec/-/blob/langserver/implementation.go#L76:30

berkant commented 6 years ago

IMHO, present error is better as it is a no-go for a function or method to be implemented. I also wonder how come it would work on methods. Sounds illogical to me.

nicksnyder commented 6 years ago

The language server client (e.g. editors) shouldn't need to know a priori if a given location in a file is a valid location to call "find implementations". No results instead of an error makes sense to me.

kevinburke commented 6 years ago

I'm not sure that that's right FWIW, or it might be masking an error.

Calling "find implementations" on MustParse in github.com/kevinburke/aws-vault/vendor/github.com/alecthomas/kingpin.v2 should return at least one implementation, in github.com/kevinburke/aws-vault/main.go, but it doesn't find it.

local URL is http://localhost:7080/github.com/kevinburke/aws-vault/-/blob/vendor/gopkg.in/alecthomas/kingpin.v2/global.go#L84:6&tab=impl

keegancsmith commented 6 years ago

@kevinburke Find implementations finds methods which implement an interface methods. What you are referring to is find references. In this case it works https://sourcegraph.com/github.com/kevinburke/aws-vault/-/blob/vendor/gopkg.in/alecthomas/kingpin.v2/global.go#L84:6=&tab=references

kevinburke commented 6 years ago

I suppose but I guess even if I'm calling it incorrectly, it would be nice if the error message was clearer, for example, it could say "this function is not an interface definition" instead of "this function is not a method", the latter of which doesn't make much sense.