1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Merge pull request #105347 from HolonProduction/lsp-utf8

LSP: Account for unicode identifiers
This commit is contained in:
Thaddeus Crews
2025-05-28 09:47:29 -05:00
2 changed files with 20 additions and 9 deletions

View File

@@ -712,9 +712,9 @@ String ExtendGDScriptParser::get_identifier_under_position(const LSP::Position &
LSP::Position pos = p_position;
if (
pos.character >= line.length() // Cursor at end of line.
|| (!is_ascii_identifier_char(line[pos.character]) // Not on valid identifier char.
|| (!is_unicode_identifier_continue(line[pos.character]) // Not on valid identifier char.
&& (pos.character > 0 // Not line start -> there is a prev char.
&& is_ascii_identifier_char(line[pos.character - 1]) // Prev is valid identifier char.
&& is_unicode_identifier_continue(line[pos.character - 1]) // Prev is valid identifier char.
))) {
pos.character--;
}
@@ -723,7 +723,7 @@ String ExtendGDScriptParser::get_identifier_under_position(const LSP::Position &
for (int c = pos.character; c >= 0; c--) {
start_pos = c;
char32_t ch = line[c];
bool valid_char = is_ascii_identifier_char(ch);
bool valid_char = is_unicode_identifier_continue(ch);
if (!valid_char) {
break;
}
@@ -732,13 +732,17 @@ String ExtendGDScriptParser::get_identifier_under_position(const LSP::Position &
int end_pos = pos.character;
for (int c = pos.character; c < line.length(); c++) {
char32_t ch = line[c];
bool valid_char = is_ascii_identifier_char(ch);
bool valid_char = is_unicode_identifier_continue(ch);
if (!valid_char) {
break;
}
end_pos = c;
}
if (!is_unicode_identifier_start(line[start_pos + 1])) {
return "";
}
if (start_pos < end_pos) {
r_range.start.line = r_range.end.line = pos.line;
r_range.start.character = start_pos + 1;

View File

@@ -58,16 +58,19 @@ class Inner2:
# | | ^^^^ -> class2:func:arg2
# ^^^^ -> class2:func:arg1
class Inner3 extends Inner2:
class Inner extends Inner2:
# | | ^^^^^^ -> class2
# ^^^^^^ class3 -> class3
var whatever = "foo"
# ^^^^^^^^ class3:whatever -> class3:whatever
var ütf8 = ""
# ^^^^ class3:utf8 -> class3:utf8
func _init():
# ^^^^^ class3:init
# Note: no self-ref check here: resolves to `Object._init`.
# usages of `Inner3.new()` DO resolve to this `_init`
# usages of `Inner.new()` DO resolve to this `_init`
pass
class NestedInInner3:
@@ -97,14 +100,18 @@ func _ready():
# | | ^^^^^^ -> func:class1:value2
# ^^^^^^ -> func:class1:value1
var inner3 = Inner3.new()
var inner3 = Inner.new()
# | | | | ^^^ -> class3:init
# | | ^^^^^^ -> class3
# ^^^^^^ func:class3 -> func:class3
print(inner3)
# ^^^^^^ -> func:class3
var nested1 = Inner3.NestedInInner3.new()
print(inner3.ütf8)
# | | ^^^^ -> class3:utf8
# ^^^^^^ -> func:class3
var nested1 = Inner三.NestedInInner3.new()
# | | | | ^^^^^^^^^^^^^^ -> class3:nested1
# | | ^^^^^^ -> class3
# ^^^^^^^ func:class3:nested1 -> func:class3:nested1
@@ -115,7 +122,7 @@ func _ready():
print(value_nested1)
# ^^^^^^^^^^^^^ -> func:class3:nested1:value
var nested2 = Inner3.AnotherNestedInInner3.new()
var nested2 = Inner.AnotherNestedInInner3.new()
# | | | | ^^^^^^^^^^^^^^^^^^^^^ -> class3:nested2
# | | ^^^^^^ -> class3
# ^^^^^^^ func:class3:nested2 -> func:class3:nested2