Skip to content

Fix ranges of comment sections #855

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 4 commits into from
Jul 21, 2025
Merged

Fix ranges of comment sections #855

merged 4 commits into from
Jul 21, 2025

Conversation

lionel-
Copy link
Contributor

@lionel- lionel- commented Jun 26, 2025

Addresses #846.
Addresses posit-dev/positron#6137
Supersedes and closes #854.

Pair-programmed with an agent ✨.

The first commit refactors things to avoid the use of explicit stacks. The second commit is the fix.

Both linked issues stem from section ranges not extending to the section end. The section now ends at either the next non-nested section, or at the closing delimiter of the enclosing node (when the section is nested in a function for instance

The section end needs to be on the previous line. In principle range ends are exclusive, but in practice we need to go back a line for vscode breadcrumbs coverages to behave properly.

QA Notes

The fixes in this PR are tested on the backend side. On the frontend side you should see the following when testing:

With:

# https://github.com/posit-dev/ark/issues/846

{
    # level 1 ####
    1
    # another level 1 ####
    2
}

# Level ----

foo <- function() {
    1
    2
}

The breadcrumbs coverage (revealed when a breadcrumb is selected) should be consistent with the sections. Nested symbols such as function definitions should work as well.

Screen.Recording.2025-06-26.at.14.07.45.mov

With:

# https://github.com/posit-dev/positron/issues/6137

test_fun <- function(...) {












    return(invisible())
  }





  #### Section Title ####
  test_fun2 <- function(...) {







    fun3 <- function() {











    }







    # long function
    return(invisible())
  }

The breadcrumb sticky scrolls should incorporate sections. Nested breadcrumb should still work:

Screen.Recording.2025-06-26.at.14.08.10.mov

@lionel- lionel- force-pushed the bugfix/section-symbols branch from 74dbe94 to a5b9485 Compare June 30, 2025 08:42
Comment on lines +582 to +586
let line_len = line.len_chars().saturating_sub(1); // Subtract 1 for newline
tree_sitter::Point {
row: prev_row,
column: line_len,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason you don't include the newline? I feel like the newline is technically just the end of the current line, right? So it feels like that position would be valid

Copy link
Contributor Author

@lionel- lionel- Jul 21, 2025

Choose a reason for hiding this comment

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

Because after the newline you are no longer on that line, so that position actually represents column 0 of the line we started with. The n + 1 position on the line doesn't really exist in fact.

Side note, I find it confusing that Rope's line iterator includes trailing newlines. I think a "split by line" viewpoint is more intuitive.

@lionel- lionel- merged commit 538303e into main Jul 21, 2025
6 checks passed
@lionel- lionel- deleted the bugfix/section-symbols branch July 21, 2025 08:02
@github-actions github-actions bot locked and limited conversation to collaborators Jul 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants