Skip to content

refactor: move the SemanticDB to binary name conversion onto Symbol - #8763

Merged
tgodzik merged 1 commit into
scalameta:main-v2from
damiankus-vl:improvement-extract-common-symbol-conversion-operations
Aug 13, 2026
Merged

refactor: move the SemanticDB to binary name conversion onto Symbol#8763
tgodzik merged 1 commit into
scalameta:main-v2from
damiankus-vl:improvement-extract-common-symbol-conversion-operations

Conversation

@damiankus-vl

@damiankus-vl damiankus-vl commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

There are a few places where we convert SemanticDB symbols to Java binary names, for example

sym.stripSuffix("#").stripSuffix(".").replace('/', '.')

We could extract that logic to make it reusable

This change originated in from #8742
I've moved it to a separate PR to make the original one smaller

Summary by CodeRabbit

  • Bug Fixes

    • Improved Javadoc link resolution for nested Java classes and their members.
    • Fully qualified and same-package references now navigate more reliably to the correct source files.
    • Invalid or empty Javadoc references are ignored without creating broken links.
    • Improved class name handling for source navigation, Java module lookup, and related tooling.
  • Tests

    • Added coverage for nested-class links, tooltips, resolution targets, invalid references, and Java source navigation.

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 05f12749-7c16-4f35-a5af-0d9aa8ae59f7

📥 Commits

Reviewing files that changed from the base of the PR and between daced54 and edb4a67.

📒 Files selected for processing (3)
  • metals/src/main/scala/scala/meta/internal/parsing/DocumentLinksProvider.scala
  • tests/unit/src/test/scala/tests/DocumentLinkLspSuite.scala
  • tests/unit/src/test/scala/tests/parsing/DocumentLinksProviderSuite.scala
🚧 Files skipped from review as they are similar to previous changes (1)
  • metals/src/main/scala/scala/meta/internal/parsing/DocumentLinksProvider.scala

📝 Walkthrough

Walkthrough

The change centralizes top-level SemanticDB symbol conversion. Javadoc links now resolve nested classes and members. Classpath, source-index, and virtual-text lookups use shared conversions. Tests cover valid, invalid, same-package, lowercase, and fully qualified references.

Changes

Top-level symbol name conversion

Layer / File(s) Summary
Top-level symbol conversion helpers
mtags/src/main/scala/scala/meta/internal/mtags/Symbol.scala
Symbol now converts top-level symbols to binary and class names and reconstructs symbols from class names.
Document and virtual-text symbol resolution
metals/src/main/scala/scala/meta/internal/metals/mbt/VirtualTextDocument.scala, metals/src/main/scala/scala/meta/internal/parsing/DocumentLinksProvider.scala, tests/unit/src/test/scala/tests/DocumentLinkLspSuite.scala, tests/unit/src/test/scala/tests/parsing/DocumentLinksProviderSuite.scala
Virtual text uses shared class-name conversion. Javadoc resolution generates ordered package-aware and nested-class candidates, validates references, and stops after the first successful lookup. Tests cover valid and invalid links.
Classpath and source index lookup
mtags/src/main/scala/scala/meta/internal/mtags/ClasspathDefinitionIndex.scala, mtags/src/main/scala/scala/meta/internal/mtags/SymbolIndexBucket.scala
Classfile paths, source paths, and Java reflective class names use shared symbol conversions.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Javadoc
  participant DocumentLinksProvider
  participant Symbol
  participant JavaSource
  Javadoc->>DocumentLinksProvider: submit nested class reference
  DocumentLinksProvider->>Symbol: construct ordered candidate symbols
  DocumentLinksProvider->>JavaSource: resolve candidates lazily
  JavaSource-->>DocumentLinksProvider: return source target
Loading

Possibly related PRs

Suggested reviewers: tgodzik

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The changes do not address issue #39, which requires non-constant SymbolKind values for val declarations. Implement the SymbolKind change required by issue #39 or link the pull request to the issue for the Symbol conversion refactor.
Out of Scope Changes check ⚠️ Warning The Symbol conversion and document-link changes are unrelated to the linked issue #39 and are therefore out of scope. Update the linked issue to match the refactor objectives or limit the pull request to the SymbolKind requirement.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes moving SemanticDB binary-name conversion logic onto Symbol, which is the main change.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@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: 1

🤖 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/parsing/DocumentLinksProvider.scala`:
- Line 299: Update classRefToSymbols so dotted Javadoc class references support
SemanticDB nested-class symbols: retain the Symbol.fromToplevelClassName
candidate for top-level classes, and additionally resolve nested segments using
the nested symbol form (for example, java/util/Map#Entry#). Return both
candidates when necessary so valid nested links can be found without breaking
top-level resolution.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 2f70fbcf-2869-436a-bb20-39d9c0d9e3fd

📥 Commits

Reviewing files that changed from the base of the PR and between d70c1d7 and 2e4557b.

📒 Files selected for processing (5)
  • metals/src/main/scala/scala/meta/internal/metals/mbt/VirtualTextDocument.scala
  • metals/src/main/scala/scala/meta/internal/parsing/DocumentLinksProvider.scala
  • mtags/src/main/scala/scala/meta/internal/mtags/ClasspathDefinitionIndex.scala
  • mtags/src/main/scala/scala/meta/internal/mtags/Symbol.scala
  • mtags/src/main/scala/scala/meta/internal/mtags/SymbolIndexBucket.scala

Comment thread metals/src/main/scala/scala/meta/internal/parsing/DocumentLinksProvider.scala Outdated

@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: 1

🤖 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/parsing/DocumentLinksProvider.scala`:
- Line 304: Update the dotted-reference handling around
DocumentLinksProvider.dottedClassRefToSymbols so references beginning with a
type name also generate the current-package candidate (for example,
a/Outer#Inner#) before unqualified candidates. Preserve existing resolution
behavior and add LSP regressions covering {`@link` Outer.Inner} and {`@link`
Outer.Inner#doSomething} in the same package.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 7ceb44c7-058d-499a-a63e-ebb52ec41fc5

📥 Commits

Reviewing files that changed from the base of the PR and between 2e4557b and 80a0940.

📒 Files selected for processing (3)
  • metals/src/main/scala/scala/meta/internal/parsing/DocumentLinksProvider.scala
  • tests/unit/src/test/scala/tests/DocumentLinkLspSuite.scala
  • tests/unit/src/test/scala/tests/parsing/DocumentLinksProviderSuite.scala

Comment thread metals/src/main/scala/scala/meta/internal/parsing/DocumentLinksProvider.scala Outdated
@damiankus-vl
damiankus-vl force-pushed the improvement-extract-common-symbol-conversion-operations branch 2 times, most recently from dcc391a to daced54 Compare August 6, 2026 11:33
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

// A reference starting with a type names a class of the current package:
// `Outer.Inner` inside `package a` is `a/Outer#Inner#`, which no
// unqualified reading covers. First, as for a simple name.
val startsWithTypeName = classRef.headOption.exists(_.isUpper)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Doesn't it break if we have a lower case class?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

will have a look

@damiankus-vl damiankus-vl Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've updated the logic and added some test cases to check if references to classes with lowercase names are properly resolved

commit: e75c1d82485b7a439b9bdfdecf658587b6aa3933

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

extracted the changes related to javadoc links to a separate PR as they can be merged separately:
#8790

List(simpleSymbol)
} else {
List(classRef.replace('.', '/') + "#")
val toplevelSymbol = Symbol.fromToplevelClassName(classRef).value

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

these changes were added to address the following feedback:
#8763 (comment)

// A reference starting with a type names a class of the current package:
// `Outer.Inner` inside `package a` is `a/Outer#Inner#`, which no
// unqualified reading covers. First, as for a simple name.
val startsWithTypeName = classRef.headOption.exists(_.isUpper)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

will have a look

@damiankus-vl
damiankus-vl force-pushed the improvement-extract-common-symbol-conversion-operations branch 3 times, most recently from e75c1d8 to 7e09c11 Compare August 12, 2026 14:56
@damiankus-vl
damiankus-vl force-pushed the improvement-extract-common-symbol-conversion-operations branch from 7e09c11 to bd2e3c9 Compare August 13, 2026 08:51
tgodzik pushed a commit that referenced this pull request Aug 13, 2026
…types (#8790)

Extracted from #8763

these changes address the following automated feedback:
#8763 (comment)

and also this comment (resolving links to classes with lowercase names):
#8763 (comment)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Bug Fixes**
* Improved JavaDoc link resolution for nested classes, package and class
references, same-package symbols, and local members.
* Invalid or unresolved references no longer generate incorrect document
links.
  * Empty JavaDoc link tags are now ignored.

* **Tests**
* Added coverage for valid, invalid, mixed, qualified, and lowercase
references.
* Improved verification of link counts, tooltips, and resolution
targets.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

@tgodzik tgodzik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@tgodzik
tgodzik merged commit 641a972 into scalameta:main-v2 Aug 13, 2026
18 checks passed
@damiankus-vl
damiankus-vl deleted the improvement-extract-common-symbol-conversion-operations branch August 13, 2026 09:44
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