英文:
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
这不是你犯的错误,只是我们目前在处理这个插件的特定部分时遇到的问题。
谢谢。
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论