Skip to content

Commit eef13d5

Browse files
committed
Merge pull request godotengine#105347 from HolonProduction/lsp-utf8
LSP: Account for unicode identifiers
2 parents 99f5a3d + e213737 commit eef13d5

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

modules/gdscript/language_server/gdscript_extend_parser.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -712,9 +712,9 @@ String ExtendGDScriptParser::get_identifier_under_position(const LSP::Position &
712712
LSP::Position pos = p_position;
713713
if (
714714
pos.character >= line.length() // Cursor at end of line.
715-
|| (!is_ascii_identifier_char(line[pos.character]) // Not on valid identifier char.
715+
|| (!is_unicode_identifier_continue(line[pos.character]) // Not on valid identifier char.
716716
&& (pos.character > 0 // Not line start -> there is a prev char.
717-
&& is_ascii_identifier_char(line[pos.character - 1]) // Prev is valid identifier char.
717+
&& is_unicode_identifier_continue(line[pos.character - 1]) // Prev is valid identifier char.
718718
))) {
719719
pos.character--;
720720
}
@@ -723,7 +723,7 @@ String ExtendGDScriptParser::get_identifier_under_position(const LSP::Position &
723723
for (int c = pos.character; c >= 0; c--) {
724724
start_pos = c;
725725
char32_t ch = line[c];
726-
bool valid_char = is_ascii_identifier_char(ch);
726+
bool valid_char = is_unicode_identifier_continue(ch);
727727
if (!valid_char) {
728728
break;
729729
}
@@ -732,13 +732,17 @@ String ExtendGDScriptParser::get_identifier_under_position(const LSP::Position &
732732
int end_pos = pos.character;
733733
for (int c = pos.character; c < line.length(); c++) {
734734
char32_t ch = line[c];
735-
bool valid_char = is_ascii_identifier_char(ch);
735+
bool valid_char = is_unicode_identifier_continue(ch);
736736
if (!valid_char) {
737737
break;
738738
}
739739
end_pos = c;
740740
}
741741

742+
if (!is_unicode_identifier_start(line[start_pos + 1])) {
743+
return "";
744+
}
745+
742746
if (start_pos < end_pos) {
743747
r_range.start.line = r_range.end.line = pos.line;
744748
r_range.start.character = start_pos + 1;

modules/gdscript/tests/scripts/lsp/class.gd

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,19 @@ class Inner2:
5858
# | | ^^^^ -> class2:func:arg2
5959
# ^^^^ -> class2:func:arg1
6060

61-
class Inner3 extends Inner2:
61+
class Inner extends Inner2:
6262
# | | ^^^^^^ -> class2
6363
# ^^^^^^ class3 -> class3
6464
var whatever = "foo"
6565
# ^^^^^^^^ class3:whatever -> class3:whatever
6666

67+
var ütf8 = ""
68+
# ^^^^ class3:utf8 -> class3:utf8
69+
6770
func _init():
6871
# ^^^^^ class3:init
6972
# Note: no self-ref check here: resolves to `Object._init`.
70-
# usages of `Inner3.new()` DO resolve to this `_init`
73+
# usages of `Inner三.new()` DO resolve to this `_init`
7174
pass
7275

7376
class NestedInInner3:
@@ -97,14 +100,18 @@ func _ready():
97100
# | | ^^^^^^ -> func:class1:value2
98101
# ^^^^^^ -> func:class1:value1
99102

100-
var inner3 = Inner3.new()
103+
var inner3 = Inner.new()
101104
# | | | | ^^^ -> class3:init
102105
# | | ^^^^^^ -> class3
103106
# ^^^^^^ func:class3 -> func:class3
104107
print(inner3)
105108
# ^^^^^^ -> func:class3
106109

107-
var nested1 = Inner3.NestedInInner3.new()
110+
print(inner3tf8)
111+
# | | ^^^^ -> class3:utf8
112+
# ^^^^^^ -> func:class3
113+
114+
var nested1 = Inner三.NestedInInner3.new()
108115
# | | | | ^^^^^^^^^^^^^^ -> class3:nested1
109116
# | | ^^^^^^ -> class3
110117
# ^^^^^^^ func:class3:nested1 -> func:class3:nested1
@@ -115,7 +122,7 @@ func _ready():
115122
print(value_nested1)
116123
# ^^^^^^^^^^^^^ -> func:class3:nested1:value
117124

118-
var nested2 = Inner3.AnotherNestedInInner3.new()
125+
var nested2 = Inner.AnotherNestedInInner3.new()
119126
# | | | | ^^^^^^^^^^^^^^^^^^^^^ -> class3:nested2
120127
# | | ^^^^^^ -> class3
121128
# ^^^^^^^ func:class3:nested2 -> func:class3:nested2

0 commit comments

Comments
 (0)