Feedback / assistance on feature: opening tsx in external editor when opening jsx in editor
Hi, I've been working on a feature where the ECMAScript module will use the overrides_external_editor / open_in_external_editor functions to detect a request to edit a .jsx file, and if so, detect if there is a tsconfig.json present, and try to open the source .tsx file if it exists instead. You can see the current modifications here:
https://github.com/lewispollard/ECMAScript/commit/604fe636d4aab5030537cdf0616cc1ba43ae4ac1
This is currently a pretty dumb implementation that just overrides any attempt to load an ECMAScript file from the Godot editor.
A couple of things, my C++ is very rusty (haven't used it in about 10 years) and I've never worked on the Godot engine code before. If anyone has any advice on the below or anything else, please do let me know!
-
Using the
overrides_external_editorfunction seems a little inelegant for this purpose but I couldn't find a better route with the current modules. It just takes control away from the editor's request to edit any ECMAScript file. It'd be nicer to somehow intercept and edit the requested file path if possible? -
One result of the above is that I've had to duplicate code from the
editor/plugins/script_editor_plugin.cppfile for opening the external editor. TheScriptEditor::editfunction checks thescript->get_language->overrides_external_editor()function of the ECMAScript module. The "native" Godot code to open the external editor exists within theeditfunction. So the flow goes -ScriptEditor::edit -> ECMAScriptLanguage::overrides_external_editor() ->ECMAScriptLanguage::open_in_external_editor()which means I can't then call back to the original edit function to open the editor. It's a bit clumsy, I hope it makes sense. -
In addition to that, I was hoping to have it so that if the
.tsxfile is not detected, it would just open the regular.jsxfile. I could do this pretty simply using my modifications, but it would be nice to get rid of the duplicated code by somehow telling the ScriptEditor plugin to do its usual stuff rather than overriding the external editor, under specific conditions. -
Is there an easy method to recursively search for the
tsconfig.jsonfile? Currently I'm just looking at the project root (ieres://tsconfig.json)
Currently, if I have a tsconfig.json file in the root, and I click a script icon eg in the scene tree, it will successfully open the .tsx file in VS Code instead, which is a huge timesaver for me. Works great but it's not really generalised for the reasons above. Hope my explanations made sense!