usd-idea icon indicating copy to clipboard operation
usd-idea copied to clipboard

Add support for binary USD files

Open justint opened this issue 4 years ago • 3 comments

If a user tries to open a binary usd file, PyCharm will read the binary data as-is which isn't helpful.

Instead, the plug-in should be converting the binary data to ASCII whenever a binary file is opened, and converted back whenever the user saves the file (essentially mimicking what usdedit does).

This can likely be done using the VirtualFile system, I'll have to do further investigations on how to implement this functionality.

justint avatar Nov 09 '19 23:11 justint

Following Peter's instructions in the IntelliJ Platform IDE Support Forum on creating a PSI from a binary file, I've had limited success getting this to work:

  • I've written a USDFileDecompiler class that uses usdcat to convert the binary file into ASCII, but the resulting text is neither syntax highlighted or editable. It seems like decompiled files are by default not associated with a language (resulting in no syntax highlighting) and are read-only.

  • My other attempt was to implement a USDFileViewProviderFactory and mimic JetBrains' approach towards Java Class files, but that seemed to have no effect on opening binary USD files (they weren't even being decompiled).

I'm going to pause on trying to implement this feature and focus my efforts towards other features for now. I'll revisit this at some point later when I have a better idea of how to get this working.

justint avatar Apr 18 '20 19:04 justint

Any updates on revisiting USD binary support?

olessiasoukhareva avatar Aug 12 '22 21:08 olessiasoukhareva

This feature has been a long saga for me, with sadly no promising results of a perfect solution.

Since my last comment in 2020, I've made the following attempt with mixed success:

I subclassed LightVirtualFile to a custom USDVirtualFile which defines how binary USD files are read and written (with usdcat), and then implemented a USDFileEditorProvider to override its createEditor method. In that overridden method, I cast the provided VirtualFile to a USDVirtualFile, and then pass that USDVirtualFile into a new text editor with TextEditorProvider.getInstance().createEditor(project, usdVirtualFile).

This has been successful in converting the binary file to ASCII and providing syntax highlighting, but a new critical bug has arisen from this method that I've never been able to solve: whenever one clicks a node within the open file's Structure View, a new tab of the same file opens up, resulting in two open tabs of the same file. The second tab will have no text in the tab title, and the structure view "Jump To Source" will only work in the second tab.

I've come to realize this is likely happening because there are two VirtualFiles of the binary USD: the original provided by the LocalFileSystem, and the USDVirtualFile provided by me in the FileEditorProvider. Having these two VirtualFiles active are confusing the IDE, and it doesn't realize the file is already open in one tab when using the "Jump To Source" action. The OpenFileDescriptor is failing to identify the opened editor to navigate to when called upon in FileNavigator, which could all come back to the two VirtualFile problem.


So long story short, it seems like the JetBrains IDEA software is just not built to support this kind of workflow, and any workarounds I've attempted have not been successful. I'm going to unassign myself but leave this open in case someone else would like to take a stab at this (I'm also happy to share more details to anyone interested in picking up this work).

justint avatar Sep 19 '22 19:09 justint