英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论