Skip to content

Don't emit nested objects as document symbols #859

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

Conversation

lionel-
Copy link
Contributor

@lionel- lionel- commented Jun 27, 2025

Branched from #858
Addresses posit-dev/positron#8330

Objects assigned in {} blocks are currently emitted as document symbols, which causes the ouline and document symbol search (@ prefix in command palette) to be quite busy:

Screen.Recording.2025-06-27.at.15.18.45.mov

Here is how it looks like if we only emit top-level objects:

Screen.Recording.2025-06-27.at.15.20.35.mov

This is controllable via a new "positron.r.symbols.includeAssignmentsInBlocks setting. By default we don't include these nested assignments.

QA Notes

You should see the new setting in the config UI:

Screenshot 2025-07-05 at 09 44 17

It's documented that files need to be reopened (they can also be changed) or the server restarted for this setting to take effect.

foo.detail = Some(String::from("function()"));

assert_eq!(test_symbol("foo <- function() { bar <- 1 }"), vec![foo]);
insta::assert_debug_snapshot!(test_symbol("foo <- function() { bar <- function() 1 }"));
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be worth also having a snapshot test that sets include_assignments_in_blocks to true if you can easily expose that toggle

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. (I'm assuming you mean testing nested assignments below, rather than making extra sure we always include functions here)

// Assigned variables in nested contexts are not emitted as symbols
fn test_symbol_nested_assignments() {
insta::assert_debug_snapshot!(test_symbol(
"
Copy link
Contributor

Choose a reason for hiding this comment

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

And, to be super clear, at top level we do want assigned variables to be treated as symbols?

I honestly don't think that sounds super useful either

Like, a 300 line R script is bound to have a ton of assignments, and I'm not sure that seeing them in the outline feels that useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's useful at least in packages with e.g. R6 classes.

In scripts top-level assignments allow to quickly look through things like assigned data frames. But you're right that lots of variables won't be very useful to have in there.

@lionel- lionel- force-pushed the feature/method-symbols branch from f67b10f to 323baa2 Compare July 21, 2025 08:48
Base automatically changed from feature/method-symbols to main July 21, 2025 09:00
@lionel- lionel- force-pushed the feature/top-level-assign-symbols branch from bc8ec87 to db257d2 Compare July 21, 2025 10:26
@lionel- lionel- merged commit bdd1af1 into main Jul 21, 2025
6 checks passed
@lionel- lionel- deleted the feature/top-level-assign-symbols branch July 21, 2025 10:33
@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