Skip to content

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

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
lewiji opened this issue Nov 10, 2020 · 1 comment · Fixed by #211
Closed
Labels
enhancement New feature or request

Comments

@lewiji
Copy link
Contributor

lewiji commented Nov 10, 2020

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:

lewiji@604fe63

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!

@nmerget nmerget added investigation Needs some investigation enhancement New feature or request and removed investigation Needs some investigation labels Sep 15, 2024
@nmerget
Copy link
Collaborator

nmerget commented Sep 27, 2024

Hey, thank you @lewiji for your suggestion.

I used your code as a base to create a slightly different approach:

  • I created new tool godot-ts as the recommended way to use GodotJS with TypeScript
  • It will bundle esbuild for generating the .ts files
  • I added a esbuild plugin to add a custom banner to the generated file, with the absolute path of the origin file as comment
  • in this branch I used your code to check the file content
  • if it has a generated banner we open the origin file otherwise we keep opening the .mjs file

Pros:

  • we don't rely on tsconfig.json
  • we can open existing origin files and normal .mjs files

Cons:

  • we need to generate the banner to work properly

I added a documentation for this use case -> https://godotjs.github.io/documentation/typescript/intro

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants