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

C#: Add "Use actual type" context action for generically-typed Node::GetNode calls to resolve broken custom references #60

Open
knightofiam opened this issue Dec 20, 2020 · 1 comment

Comments

@knightofiam
Copy link

knightofiam commented Dec 20, 2020

@van800 Thank you for requesting this on Discord in response to my issue.

As a long time developer but relatively new to Godot, this would have saved me hours of pain.

Pseudocode example:

Before:

Player.cs (Attached via Godot editor to a KinematicBody2D Node named 'Player'):

public class Player : KinematicBody2D
{
  ...

  // My custom method
  public void Attack (Enemy enemy)
  {
    // Implement my uber-cool attack!
  }
}

Combat.cs (Attached via Godot editor to some sibling node):

...

// In some collision method:

var player = GetNode <KinematicBody2D> ("../Player"); // Incorrect: Obtain reference to
                                                      // Player class Node instance
                                                      // which extends KinematicBody2D

player.Attack (enemy); // Error: Cannot resolve symbol 'Attack'
                       // Huh? How do I fix this?
                       // Everything "just works" in GDScript... >:(
...

In the above example, the type KinematicBody2D should be hint-underlined, whereby ALT + Enter should show a context action such as Use actual type, in order to fix broken references to fields and methods after a mis-typed call to Node::GetNode.

Additionally, if practical, add a context action to the broken method call itself, such as Fix reference by using actual type.

After:

Combat.cs (Attached via Godot editor to some sibling node):

...

// In some collision method:

var player = GetNode <Player> ("../Player"); // Correct: Obtain reference to
                                             // Player class Node instance
                                             // which extends KinematicBody2D

player.Attack (enemy); // Error resolved; FINISH HIM!!!

...
@knightofiam knightofiam changed the title C#: Add "Use actual type" context action for generically-typed Node::GetNode calls to resolve custom method calls C#: Add "Use actual type" context action for generically-typed Node::GetNode calls to resolve broken references Dec 20, 2020
@knightofiam
Copy link
Author

Probably related implementation-wise to #4 & #39.

@knightofiam knightofiam changed the title C#: Add "Use actual type" context action for generically-typed Node::GetNode calls to resolve broken references C#: Add "Use actual type" context action for generically-typed Node::GetNode calls to resolve broken custom references Dec 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant