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

External script editing breaks project when introducing a class_name #44482

Closed
lostfictions opened this issue Dec 18, 2020 · 4 comments · Fixed by #47891
Closed

External script editing breaks project when introducing a class_name #44482

lostfictions opened this issue Dec 18, 2020 · 4 comments · Fixed by #47891

Comments

@lostfictions
Copy link

lostfictions commented Dec 18, 2020

Godot version:
v3.2.3.stable.flathub

OS/device including version:
Linux x64

Issue description:
It's possible I'm doing something very wrong, but when using an external code editor, introducing a class_name in GDScript appears to break the editor. The editor will crash when trying to play a scene with a script that references the named class. Disabling the external code editor or restarting the editor resolves the issue.

Steps to reproduce:

  • Open Godot and configure an external editor. I'm using VSCode with the godot-tools extension, version 1.1.2. The extension indicates that it is able to connect to Godot and completions and errors are (under normal circumstances) successfully shown.
  • Close Godot, reopen it, and create a new project.
  • Add a Node2D to the scene.
  • In the Scene view, click the Node2D and attach a new script. Name it Test.gd.
  • In the FileSystem view, right-click and select "New Script..." Accept all parameters and name it Util.gd.
  • Replace the contents of Util.gd with the following:
class_name Util

static func print_a_thing():
  print("Hello!")
  • Replace the contents of Test.gd with the following:
extends Node2D

func _ready():
	Util.print_a_thing()
  • Save the current scene and attempt to play the project.
  • The editor will output the following:

Parser Error: The identifier "Util" isn't declared in the current scope.

  • Quit the editor and reopen the project, and attempt to play the scene. The editor will log "Hello!" to the console as expected.
  • Alternately, go to Editor > Editor Settings... > Text Editor > External and uncheck "Use External Editor". Open and resave the scripts, and play the scene. The editor will log "Hello!" to the console as expected.

Minimal reproduction project:

repro.zip Note that with the repro steps used above, reloading the editor appears to resolve the issue, so this repro project may not accurately demonstrate the issue.

Also note that unless I'm misunderstanding something, this appears to be a broader issue than #10946 -- this does not apply to a running game and occurs regardless of whether or not "Sync Script Changes" is checked.

Possibly also related to #21461

@faximilie
Copy link

So for some context in-case someone is interested.

The Godot Editor will do some magic that is not present in the Language Server that most external editors rely on. It will add files with class_name declarations to the _global_script_classes variable in the project.godot file.

It seems a possible fix would be to ensure that the didChange method of the GDScript Language server to call add_global_class found in godot/core/object/script_language.h

@Lucrecious
Copy link

I'm still getting this issue with 3.3.2 even though #47891 has been merged to that branch. I even browsed the 3.3.2 commit to check if the fix is present, and it is. Doesn't seem like #47891 fixes this issue?

@akien-mga
Copy link
Member

CC @Razoric480

@Razoric480
Copy link
Contributor

Razoric480 commented Aug 4, 2021

Can confirm that #47891 didn't seem to work in some cases. But this is fixed by #48616 (and #48615)

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.

6 participants