ECMAScript icon indicating copy to clipboard operation
ECMAScript copied to clipboard

Feedback / assistance on feature: opening tsx in external editor when opening jsx in editor

Open lewiji opened this issue 5 years ago • 0 comments

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_editor function 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.cpp file for opening the external editor. The ScriptEditor::edit function checks the script->get_language->overrides_external_editor() function of the ECMAScript module. The "native" Godot code to open the external editor exists within the edit function. 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 .tsx file is not detected, it would just open the regular .jsx file. 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.json file? Currently I'm just looking at the project root (ie res://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!

lewiji avatar Nov 10 '20 21:11 lewiji