Skip to content

Recurse into special constructs to find document symbols #892

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lionel-
Copy link
Contributor

@lionel- lionel- commented Aug 8, 2025

Addresses posit-dev/positron#8881

We now consistently recurse inside these constructs to collect nested document symbols such as comment sections:

  • if-else branches
  • loops

The behaviour regarding nested assignments implemented in #859 has been adapted so that { blocks in if-else branches and loops still counts as top-level. This way these assignments are all treated as consistently part of the outline:

x <- 1

if (TRUE) {
  x <- 2
} else {
  x <- 3
}

for (i in xs) {
  x <- 4
}

In addition we also now collect comment sections in parameter lists of function definitions:

x <- function(
  # section ----
  arg
) {
  ...
}

QA Notes

Comment sections and other kinds of document symbols in if-else branches and loops are now part of the outline:

# top ----

if (TRUE) {
  # if ----
  foo <- function() {}
} else {
  # else ----
  foo <- function() {}
}

for (i in xs) {
  # loop ----
  bar <- function() {}
}

Comment sections in parameter lists of function definitions are now included as well. We don't recurse through default arguments though.

x <- function(
  # section ----
  arg = function() {
    # not a section ----
  }
) {
  ...
}
Screenshot 2025-08-08 at 13 54 15

@lionel- lionel- requested a review from DavisVaughan August 8, 2025 17:56
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.

1 participant