-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
optimize lsp_pos_to_pos #1423
optimize lsp_pos_to_pos #1423
Conversation
31134bf
to
4615fde
Compare
@@ -66,39 +66,26 @@ pub mod util { | |||
pos: lsp::Position, | |||
offset_encoding: OffsetEncoding, | |||
) -> Option<usize> { | |||
let max_line = doc.lines().count().saturating_sub(1); |
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.
Oh wow, that was missed in the original PR review.
let pos_line = pos.line as usize; | ||
let pos_line = if pos_line > max_line { | ||
if pos_line > doc.len_lines() - 1 { |
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.
Should still use saturating_sub
if you have 0
lines (no line endings)
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 noticed that it would return 1
even on an empty string ""
in the tests:
Line 456 in cc03a25
test_case!("", (1, 0) => None); |
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.
Looks good then 👍🏻
Seems to work.