14

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.

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

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?

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).

The package I am looking at for content types is org.eclipse.core.contenttype.contentTypes.

3
  • good luck in your attempts :-) Commented Oct 1, 2010 at 11:12
  • Getting this stuff straight as a user of Eclipse is hard enough, so I too wish you luck in trying to figure it out as a plug-in author!
    – dty
    Commented Oct 1, 2010 at 11:28
  • Thank you, but I would hardly call myself a plug-in author... Still learning!
    – nbz
    Commented Oct 1, 2010 at 11:34

2 Answers 2

13

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

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

Here is the xml code for it,

<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>

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'.

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.

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.

2
  • 1
    What is "PDE"? You reference it twice but don't explain what it stands for.
    – tgharold
    Commented Apr 1, 2013 at 17:34
  • Plug-in Development Environment
    – nbz
    Commented Apr 3, 2013 at 15:56
10

Note: this (new language support, custom syntax highlighting, ...) is the kind of feature provided with XText.

Xtext - Language Development Framework

With Xtext you can easily create your own programming languages and domain-specific languages (DSLs).
The framework supports the development of language infrastructures including compilers and interpreters as well as full blown Eclipse-based IDE integration.

XText custom editor example

Since the sources are available, you might have a lots of clues to illustrate the usage of the packages you are currently looking.

4
  • And this would apply even if the compiler and interpreter is already written and I only need to create the IDE (the GUI for the xyz language programmers, to be precise) which then connects to the compiler and interpreter?
    – nbz
    Commented Oct 1, 2010 at 12:05
  • @nEm: I am not sure: XText bases all its generated classes on a grammar of your language, so I don't know if you can switch those for your own classes. But my point was: in term of editor and syntax highlighting, you have lots of practical implementation examples in this XText plugin. So even if you don't use it directly, you can at least take some ideas from it.
    – VonC
    Commented Oct 1, 2010 at 12:08
  • Yup got it! Thanks, I'll look into it. Definitely some good direction to start with.
    – nbz
    Commented Oct 1, 2010 at 12:13
  • VonC: I did look through the XText, but it was not what I was looking for. Although I have kept it in mind because it seems very useful.
    – nbz
    Commented Feb 10, 2011 at 16:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.