duanfu7840
duanfu7840
2015-02-23 22:08
浏览 38
已采纳

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

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.

图片转代码服务由CSDN问答提供 功能建议

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

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

  world,err:= redis.String(c.Do(“ GET”,“ message1”))
if err!= nil {
 fmt.Println(“ 找不到密钥”)
} 
   
 
 

产生以下错误消息。

*对Redis.String的调用中没有足够的参数。

仔细查看对Redis.String的调用 Redis.String,它似乎需要一个接口+ args。

  func String(回复接口{},err错误)(字符串,错误){
...。  
返回“”,fmt.Errorf(“ redigo:字符串的意外类型,得到类型%T”,回复)
} 
   
 
 

因此,我 只需在调用结束时添加一个“ err” arg,就可以欺骗IDE删除错误消息,就像这样:

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

但是 A ! 此“修补程序”使go编译器不满意...并且报告此消息(即使IntelliJ插件未将其解释为错误)。

./ t1.go:19:单值上下文中的多值c.Do()

关于IntelliJ Go的任何想法 插件需要两个args,而GoLang仅需要一个args,因为此功能很有帮助。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dqzuo0327
    dqzuo0327 2015-02-23 22:17
    已采纳

    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.

    点赞 评论

相关推荐