Skip to content

Conversation

@adamscott
Copy link
Member

@adamscott adamscott commented Feb 3, 2025

Warning

For this moment, this PR is public for testing purposes. Work is still done to it to iron out issues.
Use at your own risk AND always backup before trying out new features.

This PR adds the refactor rename symbol functionality to the GDScript code editor inside the Godot editor.

To use this feature, just click on the desired symbol to rename and press F2 on your keyboard. You can also use the contextual menu (right click) or use the entry in the Edit menu.

Capture d’écran du 2025-02-03 17-15-43

Fixes godotengine/godot-proposals#899

@adamscott adamscott added this to the 4.x milestone Feb 3, 2025
@adamscott adamscott force-pushed the add-refactoring-rename branch 6 times, most recently from 96f6d0b to 85aed63 Compare February 4, 2025 14:10
Copy link

@ZanyaNova ZanyaNova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really hoping this becomes a thing! I'm terrible with naming things correctly on my first pass.

@adamscott adamscott force-pushed the add-refactoring-rename branch 5 times, most recently from 1ce9d14 to d093dcb Compare April 1, 2025 13:50
@adamscott adamscott modified the milestones: 4.x, 4.5 Apr 1, 2025
@adamscott adamscott force-pushed the add-refactoring-rename branch 5 times, most recently from 9a7d2b6 to fa91b69 Compare April 3, 2025 15:26
@HolonProduction
Copy link
Member

HolonProduction commented Apr 3, 2025

  • When using this in an unsaved file the changes get mixed up with the code from disk.
  • Doesn't seem to work for constants and signals at all at the moment
  • Doesn't pick up usages as type hint:
class Test:
	pass

var with_type: Test
  • The following scenario with two scripts:
# a.gd
extends Node
class_name Test1

const SIZE_EXPAND = 1

static var USUAL = 2
# b.gd
extends Node

func ready(delta: float) -> void:
	Test1.SIZE_EXPAND # Renaming SIZE_EXPAND will modify b.gd but not a.gd
	Test1.USUAL # Renaming USUAL will modify a.gd but not b.gd
	pass

Without having looked at the implementation: Collecting all usages and replacing them needs to happen in two passes, or the change might destroy references that can not be found anymore.

  • Shadowing:
extends Node

var delta: float # Renaming delta will rename the parameter name as well but not the usages
func test(delta: float): # Renaming delta will change the occurence in print but not the standalone occurence
	print(delta) # Renaming delta will change the parameter name but not the standalone occurence
	delta # Renaming delta will change the parameter name and the occurence in print but not the standalone occurence

@BenjaTK
Copy link

BenjaTK commented Apr 15, 2025

Could a 'Match Case' functionality be considered for this? Something like renaming test to test_renamed also changes TEST to TEST_RENAMED, Test to TestRenamed, etc.?

@adamscott
Copy link
Member Author

Could a 'Match Case' functionality be considered for this? Something like renaming test to test_renamed also changes TEST to TEST_RENAMED, Test to TestRenamed, etc.?

I don't understand.

@BenjaTK
Copy link

BenjaTK commented Apr 15, 2025

Could a 'Match Case' functionality be considered for this? Something like renaming test to test_renamed also changes TEST to TEST_RENAMED, Test to TestRenamed, etc.?

I don't understand.

See IntelliJ IDEA for example.

If you rename the class MyClass to YourClass:

Before

class_name MyClass

[...]

var my_class = MyClass.new()

After

class_name YourClass

[...]

var your_class = YourClass.new()

@adamscott adamscott requested a review from vnen April 16, 2025 14:09
@adamscott adamscott marked this pull request as ready for review April 23, 2025 13:49
@adamscott adamscott force-pushed the add-refactoring-rename branch from 4ebaae9 to 533d479 Compare November 3, 2025 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add "refactor" tooling to rename symbols in the script editor