本文介绍了Eclipse插件:为Eclipse不支持的语言创建一个新的文件扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为它创建一个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的基础,我们假设它的扩展名为'code> .xyz '

The language has no base in Java or XML and let's say its extension is '.xyz'

从我对在线研究的了解,我需要创建一个新的内容类型与文件扩展名' 名为.xyz 。但是我在网上发现的所有信息都涉及将一个新的扩展与java关联(对于java语法高亮)或创建一个新的类型的文件,它可以是XML的一个变体,因此有很多关于描述符的细节。 br>
基本上,我对内容描述者感到困惑,我还要为新语言创建一个新的描述符?而且,对于与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语言可以有两种类型的扩展名'.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插件的Eclipse。我认为这是一个非常理想的起点,特别是对于一个新的人来说。

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.

另一个让我工作进行的地方是,但我特意要指出,其中包含许多教程链接。

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不支持的语言创建一个新的文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 15:28