如何从Go编译的包中获取语言x的类型信息?

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

How to get type info from Go compiled packages in language x?

问题

我想为Go语言编写一个简单的编辑器,具备基本的自动完成功能,作为一个个人项目。如何开始做呢?我看了一下Eclipse和IntelliJ的Go插件,但是它们对我来说太复杂了(更不用说编译一个了)。

英文:

I want to write a simple editor with basic autocomplete functionality for the Go language as a pet project. How would one go about doing it? I took a look at the Go plugins for Eclipse and IntelliJ, but they were too big for me to comprehend (not to mention getting one to compile).

答案1

得分: 2

Go标准库提供了构建Go解析器的基本组件,您可以使用它来解析源文件并查找函数定义等内容。

还有一个godoc命令,它已经可以满足您的需求:提取方法定义及其文档。您可以查看godoc的源代码来了解它的工作原理,或直接使用godoc命令。

这个用Go编写的编辑器的代码量适中,您可以参考它。

英文:

The Go standard library offers the building blocks for a Go parser which
you can use to parse the source files and look for function definitions and the like.

There's also the godoc command which
already does what you want: extracting method definitions and it's documentation. You may look in the
source code to see how godoc is
working or use godoc directly.

This editor written in Go projects has a manageable amount of code,
you may look into it.

答案2

得分: 2

这个问题的事实上的标准方法是使用nsf的gocode。我只在Vim中尝试过它 - 它工作得非常好。

尽管有针对特定编辑器的现成支持,但gocode并不特定于编辑器。它是一个带有通信协议的守护程序。因此,它可以从任何程序中使用。

英文:

The de facto standard approach to this problem is to use nsf's gocode. I have tried it only in Vim - it works very well.

Even though there's ready made support for specific editors, gocode is not editor specific. It's a daemon with a communication protocol. It is thus usable from any program.

huangapple
  • 本文由 发表于 2013年3月25日 13:10:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/15608046.html
匿名

发表评论

匿名网友

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

确定