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

匆匆过客 提交于 2019-12-04 17:45:34

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:

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:

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?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!