Skip to content

Fix LSP line/pos at start of a line #866

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

Merged
merged 1 commit into from
May 14, 2025

Conversation

jakebailey
Copy link
Member

Before:

image

After:

image

We really need tests for this conversion but this should be sufficient to fix this for demo purposes.

Probably fixes the global completions PR?

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes the calculation of the line and character positions for LSP by adjusting how the line start is determined when the given position is not at the beginning of a line.

  • Adjusts the line detection logic in PositionToLineAndCharacter by detecting if the position is at a line start and decrementing the line index if not.
  • Ensures that the line value does not become negative with a max(0, line) clamp.
Comments suppressed due to low confidence (1)

internal/ls/converters.go:242

  • Consider adding tests to cover edge cases for this conversion logic, such as when the position coincides with the start of a line and when it does not.
line, isLineStart := slices.BinarySearch(lineMap.LineStarts, position)

@jakebailey
Copy link
Member Author

Yep, works:

image

@jakebailey jakebailey enabled auto-merge May 14, 2025 01:21
@jakebailey jakebailey added this pull request to the merge queue May 14, 2025
Merged via the queue into main with commit 85bee7d May 14, 2025
23 checks passed
@gabritto gabritto mentioned this pull request May 14, 2025
@jakebailey jakebailey deleted the jabaile/fix-converter-at-line-start branch May 21, 2025 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants