我正在为其创建一个 Eclipse 插件以支持一种新语言.我遇到的问题是内容类型/文件关联及其各自的编辑器.
I am creating an Eclipse plug-in for it to support a new language. The problem I have is with the content type/file association and its respective editor.
该语言没有 Java 或 XML 基础,假设它的扩展名为 '.xyz
'
The language has no base in Java or XML and let's say its extension is '.xyz
'
根据我对在线研究的了解,我需要创建一个文件扩展名为.xyz
"的新内容类型.但是我在网上找到的所有信息都与将新扩展名与 java 相关联(用于 java 语法突出显示)或创建可以是 XML 变体的新文件类型有关,因此有很多关于描述器的详细信息.
基本上,我对内容描述器感到困惑,我是否也要为新语言创建一个新的描述器?对于与 XML 或 JAVA 完全无关的语言,我会给出什么基本类型?
From what I understood of research online, I would need to create a new Content Type with file extension '.xyz
'. But all the information I have found online has related to either associating a new extension with java (for java syntax highlighting) or creating a new type of file which can be a variant of XML, hence having a lot of details about the describer.
Basically, I am confused about the content describer, am I also to create a new describer for a new language? And what base-type would I give for a language not related to XML or JAVA at all?
另外,由于我将添加自己的语法突出显示,我是否需要创建自己的编辑器,或者我可以在预设的 editorArea(编辑器)中打开这样的文件.
Also, since I will be adding my own syntax highlighting, would I need to create my own editor or can I just open such a file in the pre-set editorArea (editors).
我正在查看的内容类型包是 org.eclipse.core.contenttype.contentTypes
.
The package I am looking at for content types is org.eclipse.core.contenttype.contentTypes
.
我意识到我从来没有真正为这个问题选择过答案,最终我找到了一些有用的信息,所以我想我会分享它.
I realised that I never really picked an answer for this question and eventually I found some useful information on it, so I thought I would share it.
这是我理解和使用的信息;如果有任何错误或我误解了,我深表歉意,我愿意接受任何更正.
This is the information I understood and used; I apologize if there are any errors or I have misunderstood, and I am open to any corrections.
实际上比我预期的要简单得多.要创建一个新的文件扩展名,你只需要扩展
It was actually a lot simpler than I expected. To create a new file extension, you just need to extend
org.eclipse.core.contenttype.contentTypes
如果您使用的是 PDE,那么您只需右键单击扩展程序(一旦将其添加到扩展程序选项卡中)并选择新建... -> 内容类型
If you are using the PDE, then you can just right click on the extension (once it is added in the extensions tab) and choose New... -> content-type
这是它的xml代码,
<extension
id="com.newLanguage.XYZ.contentType"
point="org.eclipse.core.contenttype.contentTypes">
<content-type
file-extensions="xyz,xyzz"
id="com.newLanguage.XYZ.contenttypeMod"
name="XYZ File"
priority="normal">
</content-type>
</extension>
在这里,您可以通过定义唯一的 id、人类可读的名称和扩展名来设置此内容类型的属性.您还可以为此内容类型提供多个扩展名.例如,我的 XYZ 语言可以有 2 种扩展名.xyz"和.xyzz".
Here you can set the properties of this content-type by defining a unique id, a human-readable name and the extension. You can also give multiple extensions for this content type. For example, my XYZ language can have 2 types of extension '.xyz, and '.xyzz'.
当我有一个通用文件扩展名时,内容描述器就会出现:'.xy',但文件的内容或格式可能会有所不同,因此我需要一个描述器,以便编辑器能够浏览文件并识别差异.这对于突出显示我需要了解差异的语法非常方便.
The content describer comes in when I have one generic file-extension: '.xy' but the content or format of the file may differentiate and so I need a describer for the editor to be able to go through the content of the file and recognize the difference. This is handy for syntax highlighting where I need to know the differences.
由于我不太擅长解释这个,这个链接对我非常有用.
Since I am not very good at explaining this, this link was extremely useful to me.
但总而言之,本教程 让我步调一致,实际上让我在理解如何为 Eclipse 实现 IDE 插件方面取得了很大进展.我认为这是一个非常理想的起点,尤其是对于新手而言.
But all in all, this tutorial is what set me on my pace and has actually taken me far in understanding how to implement an IDE plug-in for Eclipse. I think it is a very ideal place to start, especially for someone new.
另一个让我继续工作的地方是 Eclipse 常见问题解答,但我特别想指出第 3.5 节实现对您自己的语言的支持,其中包含许多教程链接.
Another place that kept my work going is the Eclipse FAQs but I would specifically like to point out to section 3.5 Implementing Support for Your Own Language which has many tutorial links.
这篇关于Eclipse 插件:为 Eclipse 不支持的语言创建新的文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!