关于开发自定义 Eclipse 编辑器的教程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/786884/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 13:40:17  来源:igfitidea点击:

Tutorial regarding the development of a custom Eclipse editor

javaeclipseeditor

提问by Adam Paynter

I wish to learn about developing an editor for Eclipse for a particular programming language. Is there a tutorial available to help me with this? It would be beneficial if it covered such topics as syntax highlighting and auto-completion.

我希望了解如何为特定编程语言为 Eclipse 开发编辑器。是否有教程可以帮助我解决这个问题?如果它涵盖语法高亮和自动完成等主题,那将是有益的。

采纳答案by jamesh

I started at this one. It was a year out of date when I used it, but the concepts have stayed the same.

我从这个开始。我使用它时已经过时了一年,但概念保持不变。

The best thing I can suggest in lieu of a how-to would be to take find a language that is already integrated, and see how they do it. Here's the real advice - don't pick one with a package name that begins with org.eclipse(like the ant one). There are so much support provided by eclipse, it is much easier to see what code you need to write if it starts with another package prefix. Try looking at the groovyor scalaplugins, for example.

我可以建议代替操作方法的最好方法是找到一种已经集成的语言,然后看看他们是如何做到的。这是真正的建议 - 不要选择包名以 开头的包名org.eclipse(比如 ant )。eclipse 提供了这么多的支持,如果它以另一个包前缀开头,就更容易看到需要编写的代码。例如,尝试查看groovyscala插件。

In my experience, it is the error highlighting which is the hardest to do accurately; next hardest is content assist.

根据我的经验,最难准确做到的是错误突出显示;下一个最难的是内容辅助。

If you are in control of the compiler or runtime of the language that you're writing an editor, it makes life a lot easier if you can get the compiler to give you all the data your IDE will need to present it to the user (e.g. list of tokens - for syntax colouring, tooltips; content assist will be much better, because you're not faking a compiler, but using the real one instead; same with error highlighting).

如果您可以控制正在编写编辑器的语言的编译器或运行时,那么如果您可以让编译器为您提供 IDE 将其呈现给用户所需的所有数据(例如标记列表 - 用于语法着色、工具提示;内容辅助会好得多,因为您不是伪造编译器,而是使用真实的编译器;与错误突出显示相同)。

The IDE has the relatively easy job of only displaying errors, and colouring, etc.

IDE 的工作相对简单,仅显示错误和着色等。

Once you have it down to display only, the example XML editor looks quite useful.

一旦您将其设置为仅显示,示例 XML 编辑器看起来非常有用。

Much of the partitioning rules I have found less useful; I've always ended up building my own - binary search over a list of tokens is extremely useful.

我发现许多分区规则不太有用;我总是最终构建自己的 - 对令牌列表进行二分搜索非常有用。

回答by Scott Stanchfield

The best one I've seen for a standard Eclipse text-based editor is

我见过的最好的基于 Eclipse 文本的编辑器是

http://www.ibm.com/developerworks/edu/os-dw-os-ecl-commplgin1.html

http://www.ibm.com/developerworks/edu/os-dw-os-ecl-commplgin1.html

(you need to sign up for a free IBM account). Prashant Deva, author of a really nice ANTLR2 plugin did this one.

(您需要注册一个免费的 IBM 帐户)。Prashant Deva,一个非常好的 ANTLR2 插件的作者做了这个。

You may also want to look into tools that will generate an editor:

您可能还想查看将生成编辑器的工具:

Eclipse Modeling Project (EMF/TMF/GMF)

Eclipse 建模项目 (EMF/TMF/GMF)

http://www.eclipse.org/modeling/

http://www.eclipse.org/modeling/

TMF helps build textual editors; GMF helps build graphical editors. A pretty good book is available (also on safari books)

TMF 帮助构建文本编辑器;GMF 帮助构建图形编辑器。有一本不错的书(也在 safari 书籍上)

Tutorial at: http://wiki.eclipse.org/index.php/GMF_Tutorial

教程位于:http: //wiki.eclipse.org/index.php/GMF_Tutorial

A good intro on GMF: http://www.ibm.com/developerworks/opensource/library/os-ecl-gmf/

关于 GMF 的一个很好的介绍:http: //www.ibm.com/developerworks/opensource/library/os-ecl-gmf/

Dynamic Languages Tool Kit

动态语言工具包

http://www.eclipse.org/dltk/

http://www.eclipse.org/dltk/

Tutorials available from that site. Note that you can use DLTK for static language editing as well; the "dynamic" part comes from the interpreter configuration and launching.

可从该站点获得教程。请注意,您也可以使用 DLTK 进行静态语言编辑;“动态”部分来自解释器配置和启动。

Xtext(now part of TMF)

Xtext(现在是 TMF 的一部分)

http://wiki.eclipse.org/Xtext

http://wiki.eclipse.org/Xtext

Note: good content assist can be quite difficult; it really involves follow-set analysis for every terminal in your grammar. You can simplify it quite a bit by just keeping track of defined symbols and keywords and just suggesting all that match the existing prefix. The generators above make this a little easier, but aren't perfect.

注意:好的内容辅助可能相当困难;它确实涉及对语法中每个终端的后续分析。您可以通过跟踪定义的符号和关键字并建议与现有前缀匹配的所有内容来简化它。上面的生成器使这更容易一些,但并不完美。

Good luck!

祝你好运!

回答by gcastro

You're probably looking for something like this article on building Eclipse editors with JFace text. It's got enough to get you started and it goes through syntax highlighting, content assist, content outline, and error markers.

您可能正在寻找类似于这篇关于使用 JFace 文本构建Eclipse 编辑器的文章。它足以让您入门,它通过语法突出显示、内容辅助、内容大纲和错误标记。

回答by Eyal

All of these answers are good, and I looked at, and used, the tutorials linked above myself.

所有这些答案都很好,我查看并使用了上面链接的教程。

I'd add this one, from Charles University in Prague. It's been updated recently, whereas the ones mentioned above are from 5-10 years ago.

我要添加这个来自布拉格查尔斯大学的。最近更新了,上面提到的都是5-10年前的。

I'm not actually sure that things have changed that much, but since it was helpful to me, I'm adding it here.

我实际上不确定事情是否发生了很大变化,但由于它对我有帮助,因此我将其添加到此处。