Skip to content

Commit 6c97d21

Browse files
authored
Merge pull request #142 from NicholasBolen/dont-alphabet
Do not reorder elements alphabetically
2 parents d89fab0 + ca452b5 commit 6c97d21

File tree

7 files changed

+22
-43
lines changed

7 files changed

+22
-43
lines changed

src/reorder.rs

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -137,27 +137,6 @@ impl GDScriptTokenKind {
137137
}
138138
}
139139

140-
/// Returns the name of the element. This is used to sort elements of the
141-
/// same type alphabetically.
142-
pub fn get_name(&self) -> &str {
143-
match self {
144-
GDScriptTokenKind::ClassAnnotation(name) => name,
145-
GDScriptTokenKind::ClassName(name) => name,
146-
GDScriptTokenKind::Extends(name) => name,
147-
GDScriptTokenKind::Docstring(name) => name,
148-
GDScriptTokenKind::Signal(name, _) => name,
149-
GDScriptTokenKind::Enum(name, _) => name,
150-
GDScriptTokenKind::Constant(name, _) => name,
151-
GDScriptTokenKind::StaticVariable(name, _) => name,
152-
GDScriptTokenKind::ExportVariable(name, _) => name,
153-
GDScriptTokenKind::RegularVariable(name, _) => name,
154-
GDScriptTokenKind::OnReadyVariable(name, _) => name,
155-
GDScriptTokenKind::Method(name, _, _) => name,
156-
GDScriptTokenKind::InnerClass(name, _) => name,
157-
GDScriptTokenKind::Unknown(name) => name,
158-
}
159-
}
160-
161140
/// Returns whether this element is private (starts with underscore).
162141
pub fn is_private(&self) -> bool {
163142
match self {
@@ -744,7 +723,7 @@ fn sort_gdscript_tokens(
744723
return privacy_cmp;
745724
}
746725

747-
// Finally we sort alphabetically. We also handle the top annotations up here.
726+
// Finally, we handle the top annotations
748727
match (&a.token_kind, &b.token_kind) {
749728
(
750729
GDScriptTokenKind::ClassAnnotation(a_text),
@@ -767,7 +746,7 @@ fn sort_gdscript_tokens(
767746
};
768747
a_priority.cmp(&b_priority)
769748
}
770-
_ => a.token_kind.get_name().cmp(b.token_kind.get_name()),
749+
_ => std::cmp::Ordering::Equal,
771750
}
772751
});
773752

tests/expected/comments_basic.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ func do_another_thing() -> void:
3030

3131
func test_function():
3232
var a = "test"
33-
# This comment should stay inside of the function body
33+
# This comment should stay inside of the function body
3434
print(a)

tests/reorder_code/expected/reorder_annotations.gd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ class_name Test
22
extends Node
33

44

5-
func a():
5+
@rpc("authority", "call_remote", "reliable")
6+
func my_rpc():
67
pass
78

89

9-
@rpc("authority", "call_remote", "reliable")
10-
func my_rpc():
10+
func a():
1111
pass

tests/reorder_code/expected/reorder_class_docstring.gd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ extends Node
44
## It has multiple lines.
55

66

7-
func a():
7+
func b():
88
pass
99

1010

11-
func b():
11+
func a():
1212
pass

tests/reorder_code/expected/reorder_class_docstring_misplaced.gd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ class_name TestClass
22
extends Node
33

44

5-
## This is the class docstring
6-
## It has multiple lines.
7-
func a():
5+
func b():
86
pass
97

108

11-
func b():
9+
## This is the class docstring
10+
## It has multiple lines.
11+
func a():
1212
pass

tests/reorder_code/expected/reorder_complete.gd

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,27 +56,27 @@ func _exit_tree():
5656
pass
5757

5858

59-
func get_public_property() -> float:
60-
return regular_variable
61-
62-
6359
@rpc("authority", "call_remote", "reliable")
6460
func public_method() -> int:
6561
return TEST_CONSTANT
6662

6763

68-
func set_public_property(value: float):
69-
regular_variable = value
64+
func get_public_property() -> float:
65+
return regular_variable
7066

7167

72-
func _get_private_property() -> bool:
73-
return _private_regular
68+
func set_public_property(value: float):
69+
regular_variable = value
7470

7571

7672
func _private_method() -> String:
7773
return _PRIVATE_CONSTANT
7874

7975

76+
func _get_private_property() -> bool:
77+
return _private_regular
78+
79+
8080
func _set_private_property(value: bool):
8181
_private_regular = value
8282

tests/reorder_code/expected/reorder_regions.gd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class_name Test
22
extends Node
33

44

5-
func a():
5+
func c():
66
pass
77

88

@@ -12,7 +12,7 @@ func bar():
1212
#endregion
1313

1414

15-
func c():
15+
func a():
1616
pass
1717

1818

0 commit comments

Comments
 (0)