Adding custom file encoding support

Answered

What is the preferred way, if any, of adding additional file encoding to Intellij? I couldn't find any documentation on this topic.

We have source files using ancient, niche file encoding, for which there is no support in JVM. Currently it's infeasible to convert it to any standard encoding, we're stuck with it for some time.

I managed to create a working CharsetProvider implementation for the encoding, creating a proper .jar that can be added to the JVM's classpath as an additional Charset implementation.

And I actually made Intellij support this encoding by adding the jar path to the CLASS_PATH variable in bin/idea.sh script (on Linux). However, this feels like a hacky way, especially given the recommended way of executing Intellij is through the bin/idea binary and I would like to provide a solution that can be easily used by other engineers.

I was wondering if there is some other standard way of adding the jar to the Intellij's classpath? I tried adding it to idea64.vmoptions but it doesn't work. Maybe I should use something completely different, e.g. through a plugin, and avoid adding jar to the classpath?

0
2 comments

Sorry for delay. Please try providing custom com.intellij.openapi.vfs.encoding.FileEncodingProvider extension point in a custom plugin, it might be enough.

In addition, programmatic access to VM options is possible via com.intellij.diagnostic.VMOptions

0

Thank you for the pointers! I successfully added encoding support using FileEncodingProvider for the selected file types, but I still need to address some functionality issues. Currently, I am unable to change the encoding of a file that is already open in my custom encoding. 

For example, when I select UTF-8, I get a “Reload or Convert” dialog. However, clicking the “Reload” button doesn't produce any results. When I click “Convert”, the contents are indeed converted, but my custom encoding no longer appears in the list of available encodings.

In fact, the custom encoding only shows up in the list if the file was opened with it from the beginning. I’m wondering if there’s a way to make it available without adding the CharsetProvider to the JVM's classpath as I did initially.

I plan to spend some more time trying to resolve this issue, but I would greatly appreciate any ideas or suggestions you might have that could help me. 

0

Please sign in to leave a comment.