-
Notifications
You must be signed in to change notification settings - Fork 109
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
fix out-by-one in get_leaf_for_position #218
Conversation
in fact let's not write our own binary search, there's one in the standard library. Just need to make sure we use the right one out of |
ah no, the |
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.
Thanks for the patch! I will have to test with Jedi if all the tests still pass, but in general I feel like this is a good direction.
well this causes absolute carnage in jedi unit tests, I might need some help understanding why that is and whether this is salvageable... |
Is there a way you can tell me what you changed without the refactoring? I have a hard time understanding that. I don't really understand the original issue either. You don't have to revert all the changes, but maybe just post a few lines that you would change in the old code? |
without the refactoring the change is just to the condition the unit test is intended to show the problem: without the fix the element that is found is not the one at the given position. |
This is intentional. It is unclear if the position is on the Jedi usually does this by first asking for |
I was coming to a similar conclusion: or at any rate that making a change along those lines was less likely to break the world Round about https://github.com/davidhalter/jedi/blob/b814ca2951b29be2a103395039240dbe6c5c154d/jedi/api/__init__.py#L371, something like this, perhaps? +
+ if leaf is not None and leaf.end_pos == (line, column) and leaf.type == 'newline':
+ next_ = leaf.get_next_leaf()
+ if next_ is not None and next_.start_pos == leaf.end_pos:
+ leaf = next_
+ |
Fixes #217
I've taken the liberty of rewriting the binary search so that it's not recursive. To my tastes that's much easier to follow but I guess if you really liked it the way it was I can switch it back!