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

"Lookup Symbol" or "Ctrl+LMB" not working for functions defined in script of another node #82258

Closed
nagidev opened this issue Sep 24, 2023 · 11 comments · Fixed by #79386
Closed

Comments

@nagidev
Copy link
Contributor

nagidev commented Sep 24, 2023


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


Godot version

v4.2.beta1.official [b137180]

System information

Windows 10 - Godot v4.1.1.stable.official

Issue description

Lookup symbol option not available

Including a reference to a child node, and accessing a function on the child node works in game.
However, trying to use the "Lookup symbol" option or CTRL+LMB on the function from the script editor does not work at all.

This works fine in Godot 3.5.

Additionally, the functions defined in the child node are not suggested in auto-complete in the parent node's script.

Steps to reproduce

  1. Create a scene with a parent node and a child node (type does not matter).
    ParentNode
    ChildNode
  2. Attach scripts to both nodes.
  3. Define a function (say, foo) in the child node's script.
  4. Reference the child node in the parent node's script (say, @onready var child = $ChildNode) Note: the issue only happens when onready is used.
  5. Call the function foo from the child anywhere in the parent node's script.
  6. Firstly, the function "foo" is not suggested in the auto-complete. Second, "lookup symbol" or "CTRL+LMB" don't open the function definition.

Minimal reproduction project

lookupBug.zip

@nagidev nagidev changed the title "Lookup Symbol" or "Ctrl+LMB" not working for functions in script of another node "Lookup Symbol" or "Ctrl+LMB" not working for functions defined in script of another node Sep 24, 2023
@eterlan
Copy link

eterlan commented Sep 24, 2023

As far as I know, if you don't declare class_name, you can't get any intellisense for your custom function.
The workaround is to declared class_name, and field with type.
I make some test and find some quite interesting behaviour.
case 1: child node has declared class_name, it has intellisense from parent if I declare the field as var child : Child
case 2: child node has declared class_name, it has no intellisense from parent if I declared the field as @onready var child: Child = $child

@nagidev
Copy link
Contributor Author

nagidev commented Sep 24, 2023

Getting the same results. This code seems to be working as expected and Lookup symbol is working.

extends Node

var child_node : ChildNode

func _ready():
	child_node = $ChildNode

func parent_function():
	child_node.child_function()

Although, this means we need to write extra code and define a class_name for each script. It works just fine in 3.5.

@API-Beast
Copy link

It seems like 4.1 has trouble deducing the type of $ expressions, while in 3.x it did that just fine.

@nosdregamon
Copy link

Isn't this because $ChildNode is defined @onready, and unless we run this as tool-script, onready is simply never called?

@nagidev
Copy link
Contributor Author

nagidev commented Sep 25, 2023

Turning the script into a tool script doesn't change the issue. In fact, I originally noticed the issue while working on tool scripts.

@willnationsdev
Copy link
Contributor

willnationsdev commented Sep 25, 2023

I would guess that it's because $Name can return anything extending Node and it cannot ascertain definitively whether or not the returned node will be a valid reference for the hinted type. Is it also the same (with @onready) if you do $ChildNode as ChildNode or perhaps = ($ChildNode as ChildNode) (should both be equivalent, but just in case the parser is making a distinction)?

@dalexeev
Copy link
Member

Generally speaking, autocompletion with dynamic typing is not always possible. But in this case, we could infer a weak type using the editor's information about the current scene, just as we autocomplete node paths. (The same script can be attached to multiple scenes, so autocompletion is not possible without an open scene.)

@nagidev
Copy link
Contributor Author

nagidev commented Sep 26, 2023

Godot 3 managed to pull this off quite reliably. Is there a way to bring back that feature?

@API-Beast
Copy link

API-Beast commented Sep 29, 2023

image
This is a general issue regarding $ syntax that also affects auto-complete. Here for example in 3.x it would show me the "aim_at" function, but in 4.x it will only show me generic Node functions.

I would really argue this is a regression from 3.x to 4.x rather than a "discussion" as it tagged right now. It is a feature that was core in 3.x and was lost during the rewrites.

@KoltPenny
Copy link

I'm also having this issue! We'll see how it goes.

@HolonProduction
Copy link
Contributor

HolonProduction commented Oct 30, 2023

It is definitely possible in this context to interfere the script. I added code for this in #79386 however the sorting seems to be broken currently.

I used the MRP with a custom build from the PR:

  • child_function is in the suggestions
  • CTRL + Left click works

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.

9 participants