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

Open
wants to merge 4 commits into
base: feature/method-symbols
Choose a base branch
from

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.

@lionel- lionel- force-pushed the feature/method-symbols branch from 698f1a3 to f67b10f Compare June 30, 2025 08:42
// Otherwise, collect as generic object
let name = contents.node_slice(&lhs)?.to_string();
if ctx.top_level || ctx.include_assignments_in_blocks {
// Collect as generic object, but only if we're at top-level. Assigned
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Collect as generic object, but only if we're at top-level. Assigned
// Collect as generic object, but typically only if we're at top-level. Assigned

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

// 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.

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.

2 participants