Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Ecplise CDT's indexer limited to the common filetypes for sources and headers?

I'm working on a project while involves TOM files (.t extension), which get compiled into .c files. Now, I've told my Eclipse to treat them like C sources files, but the CDT indexer doesn't seem to want to touch them. Is it possible to tell it to consider additional filetypes?

Note: TOM files look just like C files but with some additional syntax, which would just look like syntax errors on some lines to the indexer.

like image 791
einpoklum Avatar asked Mar 15 '23 07:03

einpoklum


1 Answers

The easiest way to do this is define a new association. To do this on your project, open Project Properties -> C/C++ General -> File Types, then select Use Project Settings and define a new extension:

t file type

You can also define this at the workspace level, Window -> Preferences -> C/C++ -> File Types

This should give you most of what you want. For example, (I don't actually know TOM), I have a simple project with 1 C file, 1 H file and 1 T file. All the features you want and expect just work:

tom running example

If you want more

If you want more, this can be done, but not without writing your own Eclipse plug-in that understands a little bit about *.t files. Fortunately, it takes only a few lines of XML. By the end of this you should end up with basically the same functionality as above, but you have a starting point for your very own TOM plug-in.

What you need to do is define a Content type by extending the org.eclipse.core.contenttype.contentTypes extension point (there is also some older docs that gave a run through)

In your plugin.xml this would look something like:

   <extension point="org.eclipse.core.contenttype.contentTypes">
      <!-- declares a content type for TOM source files -->
      <content-type id="tSource" name="TOM File"
         base-type="org.eclipse.core.runtime.text"
         file-extensions="t"
         priority="high"/>
    </extension>

You might consider making the base-type something other than plain text, e.g. you could make it org.eclipse.cdt.core.cSource.

Then you need to define a new language, called for our purposes TOM Language. You do this with the org.eclipse.cdt.core.language extension point.

An example of what this might look like is:

   <extension
         point="org.eclipse.cdt.core.language">
      <language
            class="org.eclipse.cdt.core.dom.ast.gnu.c.GCCLanguage"
            id="com.kichwacoders.tom.core.tomlanguage"
            name="TOM Language">
         <contentType
               id="com.kichwacoders.tom.core.tSource"></contentType>
      </language>
   </extension>

The class, GCCLanguage is the standard GCC one. Of course if you want to further improve support, adding or customizing parser is an option (to remove those syntax errors about tom stuff) you could extend the GCCLanguage or one of the other classes in the hierarchy.

Once you have done all that and added your new plug-in to your Eclipse install, you will have TOM file support.

If you have read to the end, you might find it useful to simply fork https://github.com/jonahkichwacoders/com.kichwacoders.tom.core which contains all the code above?

like image 185
Jonah Graham Avatar answered Apr 29 '23 05:04

Jonah Graham