-
Notifications
You must be signed in to change notification settings - Fork 185
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
Enhancements for the rename panel #2428
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
28a366f
Add buttons in rename panel
jwortmann 0f9f72f
Add inline diff and hide buttons after click
jwortmann c667f3b
Fix wrong diffs due to strip whitespace
jwortmann 0d93fc9
Simplify
jwortmann cb9fd8f
Ensure that preview is always accurate
jwortmann 7ded35c
Missed a variable update
jwortmann b817449
Reorder code a bit to avoid unnecessary function calls
jwortmann 897297c
Add UTF-16 tests
jwortmann 3d0ee6a
Use single phantom to avoid trailing space
jwortmann 7a66743
Refactor command to take WorkspaceEdit
jwortmann 2225e1c
Reword docstring
jwortmann 670ff23
Rename constant
jwortmann 239d4af
Simplify
jwortmann c24f4e2
CSS tweaks
jwortmann 36218f9
Add method to access PanelManager buttons
jwortmann 76db9d8
More CSS magic
jwortmann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from LSP.plugin.rename import utf16_to_code_points | ||
import unittest | ||
|
||
|
||
class LspRenamePanelTests(unittest.TestCase): | ||
|
||
def test_utf16_ascii(self): | ||
s = 'abc' | ||
self.assertEqual(utf16_to_code_points(s, 0), 0) | ||
self.assertEqual(utf16_to_code_points(s, 1), 1) | ||
self.assertEqual(utf16_to_code_points(s, 2), 2) | ||
self.assertEqual(utf16_to_code_points(s, 3), 3) # EOL after last character should count as its own code point | ||
self.assertEqual(utf16_to_code_points(s, 1337), 3) # clamp to EOL | ||
|
||
def test_utf16_deseret_letter(self): | ||
# https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocuments | ||
s = 'a𐐀b' | ||
self.assertEqual(len(s), 3) | ||
self.assertEqual(utf16_to_code_points(s, 0), 0) | ||
self.assertEqual(utf16_to_code_points(s, 1), 1) | ||
self.assertEqual(utf16_to_code_points(s, 2), 1) # 𐐀 needs 2 UTF-16 code units, so this is still at code point 1 | ||
self.assertEqual(utf16_to_code_points(s, 3), 2) | ||
self.assertEqual(utf16_to_code_points(s, 4), 3) | ||
self.assertEqual(utf16_to_code_points(s, 1337), 3) | ||
|
||
def test_utf16_emoji(self): | ||
s = 'a😀x' | ||
self.assertEqual(len(s), 3) | ||
self.assertEqual(utf16_to_code_points(s, 0), 0) | ||
self.assertEqual(utf16_to_code_points(s, 1), 1) | ||
self.assertEqual(utf16_to_code_points(s, 2), 1) | ||
self.assertEqual(utf16_to_code_points(s, 3), 2) | ||
self.assertEqual(utf16_to_code_points(s, 4), 3) | ||
self.assertEqual(utf16_to_code_points(s, 1337), 3) | ||
|
||
def test_utf16_emoji_zwj_sequence(self): | ||
# https://unicode.org/emoji/charts/emoji-zwj-sequences.html | ||
s = 'a😵💫x' | ||
self.assertEqual(len(s), 5) | ||
self.assertEqual(s, 'a\U0001f635\u200d\U0001f4abx') | ||
# 😵💫 consists of 5 UTF-16 code units and Python treats it as 3 characters | ||
self.assertEqual(utf16_to_code_points(s, 0), 0) # a | ||
self.assertEqual(utf16_to_code_points(s, 1), 1) # \U0001f635 | ||
self.assertEqual(utf16_to_code_points(s, 2), 1) # \U0001f635 | ||
self.assertEqual(utf16_to_code_points(s, 3), 2) # \u200d (zero width joiner) | ||
self.assertEqual(utf16_to_code_points(s, 4), 3) # \U0001f4ab | ||
self.assertEqual(utf16_to_code_points(s, 5), 3) # \U0001f4ab | ||
self.assertEqual(utf16_to_code_points(s, 6), 4) # x | ||
self.assertEqual(utf16_to_code_points(s, 7), 5) # after x | ||
self.assertEqual(utf16_to_code_points(s, 1337), 5) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe the naming could be a bit more clear that it's about position like
utf_16_pos_to_code_point_pos
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really feel
utf_16_pos_to_code_point_pos
. Could we keep the current name? I have reworded the docstring a little bit, and I think it's clear from the docstring and from usage what the function does.Btw, the parameter is named
col
because that's the name given in theView.text_point_utf16
method.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name to me strongly suggests something that feels like charset conversion which I think is kinda confusing.
Can we do
utf16_offset_to_code_point_offset
? Or if we want to match ST more thenutf16_point_to_code_point
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm willing to give up if you insist. I'm after all nit picking a bit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I'd say "code points" already implies that it's about the position, because there is no character encoding named "code points". If we want to have the word "position" in the name, then I would suggest
utf16_to_utf32_position
.If we want to mach ST closely, then it should probably be
code_point_utf16
or even the same nametext_point_utf16
(but the latter would be confusing I guess). The only difference between the builtin and this function here is that the builtin counts from the beginning of the view's content, while this one takes the string as an explicit parameter, and it always usesclamp=True
.So I would prefer one of these:
utf16_to_code_points
(current)utf16_to_utf32_position
code_point_utf16
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kinda like
utf16_to_utf32_position
but choose yourself whether to rename it or not later