-
-
Notifications
You must be signed in to change notification settings - Fork 106
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
position_from_utf16 in workspace.py may return incorrect result. #302
Comments
This is valid python code(!) that may cause the above failure: def 㒨㒨虁虁𤯒𤯒():
pass
if __name__ == '__main__':
㒨㒨虁虁𤯒𤯒() |
Unfortunately I don't know this part of the LSP spec well enough to understand why the correct result is one! print(position_from_utf16(s, 2)) I assume this is simulating a client sending a position that is after the first emoji? Something like
where If so... would the fix be to do something like def position_from_utf16(line, pos):
idx = max(0, pos-1)
return pos - utf16_unit_offset(line[:idx]) so that the second emoji is not passed to the |
Yes
No that would not work Something like: def position_from_utf16(line, pos):
l = len(line)
i = p = 0
while (i < l) and (p < pos):
p += 2 if (ord(line[i]) > 0xFFFF) else 1
i += 1
return i should work. |
Can you have a look at #304 please? |
The following code that mimics the way position_from_utf16 calculates the result, demonstrates the issue:
The result is zero, but it should be one.
Although, this may not have a large real-world impact (you don't get many high-plane chars in python code), it would be nice to have a correct calculation.
The text was updated successfully, but these errors were encountered: