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

Creating signals generates no code in external editor #41283

Open
chucklepie opened this issue Aug 15, 2020 · 34 comments · Fixed by #42416
Open

Creating signals generates no code in external editor #41283

chucklepie opened this issue Aug 15, 2020 · 34 comments · Fixed by #42416

Comments

@chucklepie
Copy link

chucklepie commented Aug 15, 2020

Bugsquad edit: This issue has been confirmed several times already. No need to confirm it further.


Godot version:
3.2.2 stable

OS/device including version:
linux mint 64 bit

Issue description:
I am using latest VSCode. External editor opens/switches to vscode when accessing code ok. However when I select to create a signal, it sets the signal as created in the godot IDE, it switches to vscode and opens the correct script file, but no code is generated, as per video, it simply jumps to line 1.

Additionally when you double click on the signal to go to the code it doesn't open editor. If I manually create the signal in the correct place, double clicking still does not open the editor. If I go to an existing signal already created then it switches to vscode fine.

As a side note, if I create a new script file and open it, vscode opens and the default templates are populated ok, so it is just signals and nothing to do with creating new code...

vscode

Project settings for vscode are:
code
-g {file}:{line}:{col}

Steps to reproduce:

  1. create a signal
  2. no code is created
@chucklepie
Copy link
Author

I am now and again (i.e. not always), seeing this message in Godot, despite the files not being open in Godot:

Another resource is loaded from path 'res://entities/static/Missile_Launcher.gd' (possible cyclic resource inclusion).

@Calinou
Copy link
Member

Calinou commented Aug 15, 2020

This seems to be a duplicate of #23208, but people are only reporting issues when using C# there.

@chucklepie
Copy link
Author

chucklepie commented Aug 15, 2020 via email

@Calinou
Copy link
Member

Calinou commented Sep 29, 2020

Cross-posting my comment for reference:

I think the issue has more to do with using an external editor than C# in itself.

A simple fix would be to save the file automatically when Godot creates the function in its built-in script editor. This way, the external editor will reload the file (if it supports automatic file reloading) and show the newly created function.

However, this is problematic if you've made unsaved changes in the external editor, since you'll see a "conflict prompt" in this case (as the file has been modified externally, yet you had unsaved changes). This could be alleviated by enabling the "save on focus loss" behavior in your external editor.

@shawkes
Copy link

shawkes commented Sep 29, 2020

That's quite a specific thing to do with the c# class file generation as well. Maybe this is better separate, but linked by reference?

That aspect (code being generated in the wrong place) is covered in a separate issue #12908

This and #23208 are the same underlying issue (PR will fix both), so closing one makes sense.

@AMOfficialGithub
Copy link

Does anyone know if this issue has been fixed yet?

@Calinou
Copy link
Member

Calinou commented Nov 14, 2020

@AMOfficalGithub Not yet. #42416 needs to be merged for this to be fixed. Most modern IDEs reload modified files automatically. Therefore, saving the file implements this feature without having to do anything IDE-specific.

@samtsejerome
Copy link

This is still an issue in 3.2.3

Calinou added a commit to Calinou/godot that referenced this issue May 5, 2021
This makes it possible for external editors to pick up the changes.
Most modern editors should reload the file automatically,
but some older/lightweight editors may ask the user instead
(or only warn after trying to save in the external editor).

This closes godotengine#41283.
@akien-mga akien-mga added this to the 4.0 milestone May 6, 2021
akien-mga pushed a commit to akien-mga/godot that referenced this issue May 9, 2021
This makes it possible for external editors to pick up the changes.
Most modern editors should reload the file automatically,
but some older/lightweight editors may ask the user instead
(or only warn after trying to save in the external editor).

This closes godotengine#41283.

(cherry picked from commit 0ade686)
@Calinou
Copy link
Member

Calinou commented May 23, 2021

Reopening because the feature isn't working as intended when an external editor is configured: #42416 (comment)

@Calinou Calinou reopened this May 23, 2021
@Brin-o
Copy link

Brin-o commented May 29, 2021

I'm on 3.3.2 stable using GDScript + VS Code on Windows and this is an issue as well

@prafulla-codes
Copy link

Hi, I am also facing this issue on godot v 3.2.3.stable.mono using C# + VS Code Configured on Windows 10

@mediad02
Copy link

This is the first time i'm commenting on a bug, but i would like to add some of my observations about godot not generating code in external editors.

I'm on Godot 3.2.2 stable and using VS Code with the godot-tools plugin

I get the same issue when creating a signal, godot does not auto generates the signal code in the external editor.
but if I disconnect the signal, then disable external editor and open the scripts with the internal godot editor and then re-enable external editor and create the signal the code is auto generated within the external editor, VS Code.

if you didn't follow my procedure i can post screenshots of the steps to reproduce this.

@prafulla-codes
Copy link

Hi @mediad02 , yes it would be really helpful if you attach the screenshots, I will also help to test it out

@otsoaingles
Copy link

I saw this issue today in 3.5.1 when following the "fist 2d game" tutorial.

Godot_v3.5.1-stable_mono_win64
Windows 11
Latest VS Code

@JohnC3
Copy link

JohnC3 commented Mar 7, 2023

Still an issue in 4.0 and 3.5. Following the first 2d game tutorial.
Rider
Windows 11 and windows 10.

This issue seems to be quite old it might make sense to document it in the tutorials. Perhaps offer a workaround assuming one works.

@nrmiller
Copy link

Just saw this is still active. I admit, this confused me since I'm very new to Godot! 😅

I'm not sure if this helps, but perhaps C# partial classes can be utilized. Instead of modifying the primary script, a Godot-managed partial class might be able to be generated and used.

In general though, it seems like C# grammar parsing may be needed so that Godot can know which class and indentation level to insert the snippet. Or maybe it can search for the _Ready() function and insert the event subscription logic too.

If the issue is more so concerned with discarding unsaved changes in the external editor, perhaps we can look into creating a VS Code Extension capable of merging the incoming changes with the unsaved changes.

@kastromatos
Copy link

This issue totally ruin experience for C# newcomers. It is definitely step forward, to use Godot and VS without side extension and you also able to debug in VS with some workaround, but 'no code generation' issue is a brick wall you cannot go through on very first steps in tutorial.

Godot_v4.1-stable_mono_win64
Windows 10
Visual Studio Enterprise 2022

@GarrickWinter
Copy link

GarrickWinter commented Sep 14, 2023

I also ran into this while following the "Your First 2D Game" tutorial. While the issue itself isn't a devastating problem by any means, I think the fact that it's going to hit newcomers who are following an official tutorial is potentially severe from the perspective of the community's accessibility and growth.

I suggest rewriting the tutorial to explicitly mention the bug and provide a workaround. In particular, without the code generation working, the tutorial's suggestion of leaving the default connection settings seems to clash with the provided C# code. The tutorial suggests connecting to a function called _on_body_entered, which matches the GDScript code but differs from the C# code presented, which is a function called OnBodyEntered.

It seems after some testing that Godot generates CS files that smooths over the formatting differences between _on_body_entered and OnBodyEntered, but that's not something I would have expected or understood, and might be something worth contextualizing.

Godot 4.1.1 Mono / Windows 10 / Visual Studio Code

@Calinou
Copy link
Member

Calinou commented Sep 14, 2023

@GarrickWinter Feel free to open a pull request by editing https://github.com/godotengine/godot-docs/blob/master/getting_started/first_2d_game/03.coding_the_player.rst 🙂

I don't use C# myself, so I'm not sure what should be changed exactly on that page. It already mentions the code you should write after connecting the signal.

@GarrickWinter
Copy link

Thanks for prompting! I've made a pull request here. I think a small change to be more explicit, and an explicit warning about the bug, would be sufficient to smooth over this bump in the tutorial flow.

godotengine/godot-docs#7915

@rickygai
Copy link

Godot version 4.1.1
VS Code version1.82.2
Godot Tools VS Code extension version 1.3.1
System information Windows 11

The problem occurred in Godot 4.1.1 with VSCode as well, even Godot IDE itself is not creating the signal connect routine correctly, the routine is created out of the scope of the class of the script attached such as below.

269964822-21e4d172-5c58-4206-9fcc-85fa8ef9edf5

Please help to resolve this problem, it has been there for quite long.

@Eterxity
Copy link

still does not work as of v4.1.3.stable.mono.official [f06b6836a]

@Vysp3r

This comment was marked as off-topic.

@Calinou
Copy link
Member

Calinou commented Nov 20, 2023

@Vysp3r Please don't bump issues without contributing significant new information. Use the 👍 reaction button on the first post instead.

@Hobitus
Copy link

Hobitus commented Dec 1, 2023

I'm pretty sure the bug is in the _add_callback in the script_editor_plugin.cpp.
we add the script to the editor with EditorNode::get_singleton()->push_item(scr.ptr());

This adds the script to the history, then call _edit_current in case of external editor it opens the external editor but doesn't add the script in the tab of the editor.

Then
image

the get edited resources never finds the script because it's not in the editor tab but in the external editor,
so the call to add the function is never called.

	se->add_callback(p_function, p_args);

If there is a way to temporarily add the script to the internal editor?
or maybe creating a scripteditorbase from a script instead of finding the tab with the script.

@EvilBarney
Copy link

EvilBarney commented Feb 22, 2024

Just adding that this is still an issue in Godot 4.2.1 with C# and Visual Studio 2022.

Godot is able to create and open new scripts ok, but connecting a signal doesn't generate any C# code regardless of saving the scene / rebuilding in VS or Godot / closing and re-opening the source file, etc.

Edit: as a suggestion, and also given that directly modifying the file may cause problems if it has unsaved changes in the external editor: We already have the ability to copy the signal name to the clipboard from the node panel. How about some way of either copying the full signature (in appropriate language) from the same place, or directly putting the handler code on the clipboard when connecting signals? In the latter case, if it's made obvious enough that that's happening (maybe a "Copy script code to clipboard" checkbox on the create panel), and Godot is still opening the appropriate file, then it's just a case of the user choosing where to hit ctrl-v.

@kastromatos
Copy link

kastromatos commented Mar 4, 2024

Edit: as a suggestion, and also given that directly modifying the file may cause problems if it has unsaved changes in the external editor: We already have the ability to copy the signal name to the clipboard from the node panel. How about some way of either copying the full signature (in appropriate language) from the same place, or directly putting the handler code on the clipboard when connecting signals? In the latter case, if it's made obvious enough that that's happening (maybe a "Copy script code to clipboard" checkbox on the create panel), and Godot is still opening the appropriate file, then it's just a case of the user choosing where to hit ctrl-v.

@EvilBarney Nice catch but proposed and rejected almost a year ago:
Crutch for outside editor code generation issue

@Calinou
Copy link
Member

Calinou commented Mar 4, 2024

Nice catch but proposed and rejected almost a year ago:

I think this workaround makes a lot of sense, but there's another open proposal tracking it already: godotengine/godot-proposals#3633

Therefore, your proposal was actually a duplicate of that one.

@kastromatos
Copy link

kastromatos commented Mar 5, 2024

@Calinou Yeah... So we have 4 years old annoying bug and 3 years old proposed workaround both not implemented. At least this issue are in top 5 sorted by reaction in editor topic, so there is a hope that it will be noticed and fixed soon.

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.