Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

ScriptEditor 'goto_line' on external editor is not working #52294

Closed
MikeSchulze opened this issue Aug 31, 2021 · 8 comments · Fixed by #55709
Closed

ScriptEditor 'goto_line' on external editor is not working #52294

MikeSchulze opened this issue Aug 31, 2021 · 8 comments · Fixed by #55709

Comments

@MikeSchulze
Copy link

Godot version

Godot Engine v3.3.3.stable.mono.official.b973f997f

System information

Windows 10

Issue description

I'm current extending GdUnit3 to support C# testing inside the Godot editor.

I use the ScriptEditor over the plugin interface to jump to a specific line.
For GdScripts is works fine.
Is external editor set than it only opens the correct source but it not jumps to specified line.

Example code:

get_editor_interface().get_script_editor().goto_line(line_number)

For external editor is set
image

I tryed to configure the external Text Editor but it has no affect.
Enable or disable makes no difference

Steps to reproduce

  • use Godot Mono in bundle with VS Code
  • enable mono -> Editor -> External Editor -> "Visual Studio Code"
  • create a cs file
  • from plugin context excute
        var editor_interface := plugin.get_editor_interface()
	editor_interface.edit_resource(<path to source>)
	editor_interface.get_script_editor().goto_line(<line_number>)

The external editor is open the file but ignoring the line_number

Minimal reproduction project

No response

@YuriSizov
Copy link
Contributor

I don't think that's feasible. We have no control over another executable, and there is no guarantee that it even supports any outside interactions. Opening files is simple, as it's an operating system level operation. But you can't just tell another code editor to jump to a line.

@Calinou
Copy link
Member

Calinou commented Aug 31, 2021

But you can't just tell another code editor to jump to a line.

Can't the LSP server hosted by the Godot editor do that?

However, the built-in script editor isn't active at all when the external editor is enabled. So this wouldn't work anyway unless a dedicated method was added to handle this.

@YuriSizov
Copy link
Contributor

YuriSizov commented Aug 31, 2021

Can't the LSP server hosted by the Godot editor do that?

This seems to be for C#/Mono.

@MikeSchulze
Copy link
Author

MikeSchulze commented Sep 1, 2021

Ok, I have understood the problem,
Is there another way to do this?

Can I access the information which external editor is set?

A dedicated function would be very helpfull ;)

@raulsntos
Copy link
Member

You can get the external editor path from the EditorSettings:

var editor_interface := plugin.get_editor_interface()
var settings := editor_interface.get_editor_settings()
settings.get_setting("text_editor/external/exec_path")

Settings:

  • text_editor/external/use_external_editor: If using an external editor is enabled.
  • text_editor/external/exec_path: The executable path for the external editor
  • mono/editor/external_editor: The selected external editor for C# (overrides the previous settings but only for C#)

If the external editor is VSCode you can open a file on the line 42 using the following command:

/path/to/code -g /path/to/my/file.cs:42

See the documentation for the VSCode CLI options.

However, my recommendation would be to avoid hardcoding this for each editor.


In your code you are calling editor_interface.edit_resource(resource) which opens the built-in editor or the external editor (depends on your editor configuration and if the resource is a script it also depends on if the ScriptLanguage overrides the external editor setting).

The next line in your code editor_interface.get_script_editor().goto_line(42) is only used for setting the line in the built-in Godot editor but this probably does nothing since the built-in Godot editor is not open (since you have configured Godot to use an external editor).

Ideally, you would use the ScriptEditor::edit method since it handles all of this logic (checks if an external editor is configured and if the ScriptLanguage overrides the setting) and opens the right editor (internal or external) and allows specifying the line and column, unfortunately this method is not exposed to scripting so you can't use it.

You also don't have access to ScriptLanguage from scripting, so you can't check if the scripting language overrides the external editor setting manually, therefore even if the text_editor/external/use_external_editor setting is set to false it may still fail for languages that override this and you'd have to hardcode checking for each scripting language settings (if they expose this, which C# does but others may not). And even though the scripting languages implement a open_in_external_editor method, that is also not exposed to scripting.

@MikeSchulze
Copy link
Author

Thanks for this detailed anwser.
So you mean the only option is to get the editor settings end open manually the external editor right?

@raulsntos
Copy link
Member

Yes, currently EditorInterface::edit_resource opens the proper editor (internal or external) depending on the user configuration, but you can't specify the line or column number. And ScriptEditor::goto_line only works for the internal editor.

You can't really check if an external editor is configured because that depends on the scripting language (some languages may or may not override the global external editor setting).

I have created PR #55709 to expose an EditorInterface::edit_script method that will allow you to open any script resource specifying a line and column position which will open the proper editor (internal or external) at the right position.

@MikeSchulze
Copy link
Author

Thanks so much ;)

@akien-mga akien-mga added this to the 3.5 milestone Dec 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants