-
Notifications
You must be signed in to change notification settings - Fork 11
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
refactor(char_classing): use inbuilt vim functions #53
Conversation
Awesome, thanks! Sorry, I maybe should've waited to merge the FFI branch. |
No worries, I didn't post the bug until after I had a solution. I should have posted it sooner and mentioned I was looking into it. I did test the FFI changes on their own without the fix here, and they didn't solve this issue alone. |
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.
Nice, this looks good to me! I'll let @tris203 look over it before we merge though :)
I'd have to look at the other code But can we fix at the other side with a <= or something? The char class function is basically just the cls function from Nvim/Vim and id like to keep it as close to that as possible My preference would be to fix the prev_word implementation to exit early and add an assert in char_class that the string isnt empty If this is possible https://github.com/neovim/neovim/blob/master/src%2Fnvim%2Ftextobject.c#L273-L306 On my phone, so apologies for formatting |
I'll take a look, should be able to move the empty string check I think. I wasn't aware of the Vim cls stuff. |
The above changes appear to work for the issue I logged, and all tests pass. If I add Currently this assertion has not been committed. |
Upon initial investigation, it looks like there are a number of additional places that would need to handle the empty string case since it is no longer part of the I wonder if it's best to disregard adding an empty string assertion in |
I don't know if we need the guard and it might be that the offset ranges in the while loop need to be modified to be non inclusive |
7e8b682
to
a59896b
Compare
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.
Just these (other
isn't used anywhere anymore), then looks good to me!
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.
lgtm! sorry for confusion
This closes #50.
This took me quite a while to follow through. In short, it's hitting the while loop one additional time because of the
utils.char_class
falling through to the default value ofother
which is the same class as the initial match. So the resulting offset is one less than it should be, resulting in a column of zero instead of the correct 1.The docs for
vim.fn.strcharpart
say it returns empty string on error, which is what is happening here when the index is outside the line. It made the most sense to add a guard for this edge case so I introduced an additionalchar_classes
enum member.At least, this is how it was working until the simultaneous change to use the FFI in #49. The tests still pass, things still look to work, my issue remains fixed, but this might want a slightly more detailed review due to the FFI changes.
Edit: I also added a missed test for the emoji
char_classes
member from #49, in commit bf4df53