Custom Programming Language

I am looking to develop a plugin for editing a custom language. The language doesn't have a specific file extension for its source.

Is there a way that I can get the editor to associate specific files with a filetype, rather than file extensions?

Is there a plugin which already does something similar for its custom language that I can look to for guidance in this?

Thanks

2 comments

There is no way to do this. Our workaround is to associate the empty
extension "" with our language, because most extensionless files are
files of the plugin's language. It's a crappy workaround though, you
should vote for http://jetbrains.net/jira/browse/IDEA-4712

Sam Alston wrote:

I am looking to develop a plugin for editing a custom language. The language doesn't have a specific file extension for its source.

Is there a way that I can get the editor to associate specific files with a filetype, rather than file extensions?

Is there a plugin which already does something similar for its custom language that I can look to for guidance in this?

Thanks

0

I have found a workaround, which while I'm still working out the details, does allow opening any file as a specific file type.

To start, (remembering that we are keeping this as simple as possible) we are going to use the interface to create a new file type for our custom language. This example uses the HTML file type, but this does work with a custom one.

You then need to have a Wrapper for VirtualFile which overrides key methods. Notice that we only override methods involving File Type or File Name. That is because these are what's used to determine how to open the file.

Using the simplest method (adding an "Open As XXXX" link to the toolbar) we can use the following code in an AnAction class.


And voila! We can now open any file as any filetype we wish.

The only problems that I have remaining, is that an Exception fires every now and again in the IDEA vm. Not sure why.

Secondly the name of the extension shows up in the filename at the top. So if its obnoxiously long, then it could become annoying.

I hope this helps people out there who are trying to write plugins for their own custom languages.

0

Please sign in to leave a comment.