为什么这个Go-Lang IntelliJ插件与Go的语法不一致?

huangapple go评论80阅读模式
英文:

Why is this Go-Lang IntelliJ plugin is inconsistent with Go's syntax?

问题

我对Go有点陌生,所以这可能是一个Go的问题,而不是IntelliJ的问题:我刚刚在IntelliJ 14中设置了https://github.com/go-lang-plugin-org/go-lang-idea-plugin/的zip文件。

我发现编译器与语法高亮器不一致。

以下代码会产生以下错误信息:

*not enough arguments in call to Redis.String.

仔细看一下对Redis.String的调用,它似乎接受一个interface+args。

因此,我可以通过在调用的末尾简单地添加一个"err"参数来欺骗IDE,以消除错误消息,如下所示:

world, err := redis.String(c.Do("GET", "message1"), err)

但是,这个"修复"会让Go编译器不高兴...它会报告以下消息(尽管IntelliJ插件不将其解释为错误)。

./t1.go:19: multiple-value c.Do() in single-value context

关于为什么IntelliJ Go插件需要两个参数,而GoLang只需要一个参数来调用此函数的想法将非常有帮助。

英文:

I'm somewhat new to Go, so this could be a Go problem, rather than an IntelliJ one: I've just set up https://github.com/go-lang-plugin-org/go-lang-idea-plugin/ from the zipfile, in IntelliJ 14.

I found that the compiler is inconsistent with the syntax highlighter.

world, err := redis.String(c.Do("GET", "message1"))
if err != nil {
    fmt.Println("key not found")
}

Yields the following error message.

> *not enough arguments in call to Redis.String.

Looking closer at the call to Redis.String, it appears to take an interface+args.

func String(reply interface{}, err error) (string, error) {
     ....
	return "", fmt.Errorf("redigo: unexpected type for String, got type %T", reply)
}

And thus, I'm able to trick the IDE into removing the rror message, by simply adding an "err" arg to the end of the call, like so:

world, err := redis.String(c.Do("GET", "message1"), err)

But Alas! This "fix" makes the go compiler unhappy... and it reports this message (even though the IntelliJ plugin does not interpret this as an error).

> ./t1.go:19: multiple-value c.Do() in single-value context

Any thoughts on why the IntelliJ Go Plugin wants two args, wheresas GoLang only wants one arg, for this function would be of great help.

答案1

得分: 1

这不是你犯的错误,只是我们目前在处理这个插件的特定部分时遇到的问题。

根据我的回答,请关注问题13431222

谢谢。

英文:

It's not a mistake you are making, it's just a problem that we currently have with that particular part of plugin which takes care of things like that.

As per my answer, please watch the issues 1343 and 1222.

Thank you.

huangapple
  • 本文由 发表于 2015年2月24日 06:08:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/28684449.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定