Skip to content

Refactor symbol visibility management in DocumentSymbolProvider#8369

Draft
doofin wants to merge 8 commits into
scalameta:mainfrom
doofin:feat/onlyTopSymbol
Draft

Refactor symbol visibility management in DocumentSymbolProvider#8369
doofin wants to merge 8 commits into
scalameta:mainfrom
doofin:feat/onlyTopSymbol

Conversation

@doofin

@doofin doofin commented May 12, 2026

Copy link
Copy Markdown
Contributor

This pull request improves the outline view in the Metals language server by reducing clutter from local variables, parameters, and private members. The main change is introducing a filter to control which symbols are shown, ensuring only top-level symbols are displayed in the outline.

Summary by CodeRabbit

  • New Features
    • Added a configuration option to control visibility of value and variable symbols in the document outline view.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 12, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d7ca570d-bd51-424a-a1c1-8df7e414f0e8

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

A new symbolsViewShowAll configuration flag controls whether value and variable declarations appear in document symbol outlines. The setting is added to the configuration schema, threaded through DocumentSymbolProvider to conditionally emit symbols, and wired through MetalsLspService.

Changes

Symbols View Configuration

Layer / File(s) Summary
Configuration schema
metals/src/main/scala/scala/meta/internal/metals/UserConfiguration.scala
UserConfiguration case class gains a symbolsViewShowAll: Boolean = false parameter. JSON serialization includes the field, and parsing logic reads "symbols-view-show-all" from configuration with a false default.
DocumentSymbolProvider filtering logic
metals/src/main/scala/scala/meta/internal/parsing/DocumentSymbolProvider.scala
Constructor now accepts userConfig: () => UserConfiguration. A new symbolsViewShowAll member reads the config value. A filterSymbols helper conditionally executes symbol-emission logic. Defn.Val, Decl.Val, Defn.Var, and Decl.Var cases wrap their symbol-emission calls in filterSymbols to gate symbols when the flag is disabled.
Service integration
metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala
documentSymbolProvider constructor call now includes () => userConfig as an additional argument, connecting the runtime configuration to the symbol provider.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A symbols view so neat and trim,
Shows only what we tell it when,
With showAll now we have the choice,
Vals and vars—let users rejoice! 🐰✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Refactor symbol visibility management in DocumentSymbolProvider' directly summarizes the main change—introducing symbol visibility filtering in DocumentSymbolProvider to control which symbols appear in the outline view.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@doofin doofin marked this pull request as ready for review May 12, 2026 15:09

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@metals/src/main/scala/scala/meta/internal/metals/UserConfiguration.scala`:
- Around line 65-66: Add a UserConfigurationOption entry for the new field so it
is exposed in the generated config schema/docs: update the
UserConfiguration.options collection to include an option describing
symbolsViewShowAll (label "symbols-view-show-all", its Boolean type, default
false, and a descriptive message). Locate the UserConfiguration class/companion
where options is defined and append the new UserConfigurationOption referencing
the symbolsViewShowAll field so clients and docs can discover and surface it.

In
`@metals/src/main/scala/scala/meta/internal/parsing/DocumentSymbolProvider.scala`:
- Line 27: The code currently caches the user flag in the val symbolsViewShowAll
at construction, preventing runtime config changes from taking effect; change
this by reading userConfig().symbolsViewShowAll dynamically inside filterSymbols
(or convert symbolsViewShowAll to a def that delegates to userConfig()) so
filterSymbols uses the current setting each call; update references to
symbolsViewShowAll in DocumentSymbolProvider to use the dynamic def or the
direct userConfig() read to ensure outline behavior reflects runtime updates.
- Around line 104-107: The parameter symbols (Term.Param) are still being added
unconditionally; wrap or gate the branch that adds Term.Param with the existing
filterSymbols check so parameters are only added when symbolsViewShowAll is
true. Locate the code that emits parameter symbols (the Term.Param handling
block) and call filterSymbols { ... } (or pass the param-add closure into
filterSymbols) instead of unconditionally invoking the add, reusing the existing
filterSymbols helper to suppress parameters when symbolsViewShowAll is false.
- Around line 105-107: The boolean check in filterSymbols is inverted: change
the branch so that when symbolsViewShowAll is true it executes addPatF and when
false it does nothing. Locate the filterSymbols method and swap the branches (or
invert the condition) so addPatF runs under symbolsViewShowAll == true; keep the
lazy-by-name parameter addPatF usage intact.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d87231fa-9eb1-449a-8119-37e29c176bc5

📥 Commits

Reviewing files that changed from the base of the PR and between 19751e7 and 8e4de3a.

📒 Files selected for processing (3)
  • metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala
  • metals/src/main/scala/scala/meta/internal/metals/UserConfiguration.scala
  • metals/src/main/scala/scala/meta/internal/parsing/DocumentSymbolProvider.scala

Comment on lines +65 to 66
symbolsViewShowAll: Boolean = false,
) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Register symbols-view-show-all in UserConfiguration.options.

The new field is parsed/serialized, but without a UserConfigurationOption entry it won’t be discoverable in generated config docs/schema and many clients won’t surface it properly.

Suggested patch
@@
       UserConfigurationOption(
         "mcp-client",
         "",
         "claude",
         "MCP Client Name",
@@
       ),
+      UserConfigurationOption(
+        "symbols-view-show-all",
+        "false",
+        "true",
+        "Show all symbols in outline view",
+        """|When enabled, include value/variable symbols (and other non-top-level entries)
+           |in the document symbols outline.
+           |""".stripMargin,
+        isBoolean = true,
+      ),
     )
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@metals/src/main/scala/scala/meta/internal/metals/UserConfiguration.scala`
around lines 65 - 66, Add a UserConfigurationOption entry for the new field so
it is exposed in the generated config schema/docs: update the
UserConfiguration.options collection to include an option describing
symbolsViewShowAll (label "symbols-view-show-all", its Boolean type, default
false, and a descriptive message). Locate the UserConfiguration class/companion
where options is defined and append the new UserConfigurationOption referencing
the symbolsViewShowAll field so clients and docs can discover and surface it.

userConfig: () => UserConfiguration,
) {

val symbolsViewShowAll: Boolean = userConfig().symbolsViewShowAll

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Don’t cache symbolsViewShowAll at construction time.

Line 27 captures the flag once, so runtime config updates won’t affect outline behavior until restart. Read it dynamically in filterSymbols (or make it a def).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@metals/src/main/scala/scala/meta/internal/parsing/DocumentSymbolProvider.scala`
at line 27, The code currently caches the user flag in the val
symbolsViewShowAll at construction, preventing runtime config changes from
taking effect; change this by reading userConfig().symbolsViewShowAll
dynamically inside filterSymbols (or convert symbolsViewShowAll to a def that
delegates to userConfig()) so filterSymbols uses the current setting each call;
update references to symbolsViewShowAll in DocumentSymbolProvider to use the
dynamic def or the direct userConfig() read to ensure outline behavior reflects
runtime updates.

Comment on lines +104 to +107
// don't show local variables, parameters, and private members in the outline view, since they are not visible outside of their enclosing class or method. This is especially important for parameters, since they can be very numerous and clutter the outline view.
def filterSymbols(addPatF: => Unit) = {
if (symbolsViewShowAll) {} else addPatF
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Parameter symbols are still unfiltered.

The new behavior/comment mentions reducing parameter clutter, but Term.Param is still always added (Lines 232-239). Gate that branch with the same filter to keep behavior consistent.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@metals/src/main/scala/scala/meta/internal/parsing/DocumentSymbolProvider.scala`
around lines 104 - 107, The parameter symbols (Term.Param) are still being added
unconditionally; wrap or gate the branch that adds Term.Param with the existing
filterSymbols check so parameters are only added when symbolsViewShowAll is
true. Locate the code that emits parameter symbols (the Term.Param handling
block) and call filterSymbols { ... } (or pass the param-add closure into
filterSymbols) instead of unconditionally invoking the add, reusing the existing
filterSymbols helper to suppress parameters when symbolsViewShowAll is false.

Comment on lines +105 to +107
def filterSymbols(addPatF: => Unit) = {
if (symbolsViewShowAll) {} else addPatF
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

symbolsViewShowAll condition is reversed.

Line 106 currently hides symbols when symbolsViewShowAll is true and shows them when false, which is the opposite of the flag name and expected behavior.

Suggested patch
-    def filterSymbols(addPatF: => Unit) = {
-      if (symbolsViewShowAll) {} else addPatF
-    }
+    def filterSymbols(addPatF: => Unit): Unit = {
+      if (userConfig().symbolsViewShowAll) addPatF else ()
+    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def filterSymbols(addPatF: => Unit) = {
if (symbolsViewShowAll) {} else addPatF
}
def filterSymbols(addPatF: => Unit) = {
if (symbolsViewShowAll) addPatF else ()
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@metals/src/main/scala/scala/meta/internal/parsing/DocumentSymbolProvider.scala`
around lines 105 - 107, The boolean check in filterSymbols is inverted: change
the branch so that when symbolsViewShowAll is true it executes addPatF and when
false it does nothing. Locate the filterSymbols method and swap the branches (or
invert the condition) so addPatF runs under symbolsViewShowAll == true; keep the
lazy-by-name parameter addPatF usage intact.

@doofin doofin marked this pull request as draft May 12, 2026 15:13
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