Skip to content

improvement: Save semanticdb to disk under setting - #8762

Open
tgodzik wants to merge 1 commit into
scalameta:main-v2from
tgodzik:add-caching-mechanismt
Open

improvement: Save semanticdb to disk under setting#8762
tgodzik wants to merge 1 commit into
scalameta:main-v2from
tgodzik:add-caching-mechanismt

Conversation

@tgodzik

@tgodzik tgodzik commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Also allow to specify the maximum cache size for the text document cache.

Summary by CodeRabbit

  • New Features

    • Added configurable MBT settings for generated-source imports and SemanticDB caching.
    • Added an LRU SemanticDB cache with optional persistent storage and configurable size limits.
    • Added support for nested mbt.* configuration settings.
  • Bug Fixes

    • Preserved compatibility with existing flat MBT configuration keys.
    • Cache persistence errors no longer interrupt indexing.

@coderabbitai

coderabbitai Bot commented Aug 3, 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 804b52e3-1845-45c8-9866-88a096662ef1

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:

  • ✅ Review completed - (🔄 Check again to review again)

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.

@tgodzik
tgodzik force-pushed the add-caching-mechanismt branch 2 times, most recently from 79d6eb3 to d2a3109 Compare August 4, 2026 10:44
Also allow to specify the maximum cache size for the text document cache.
@tgodzik
tgodzik force-pushed the add-caching-mechanismt branch from d2a3109 to 2c372ca Compare August 4, 2026 13:40
@tgodzik
tgodzik marked this pull request as ready for review August 4, 2026 13:43

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

🤖 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/mbt/MbtReferenceProvider.scala`:
- Around line 721-733: The loadFromDisk method only validates cached
TextDocument entries using MD5 of source text, but doesn't account for changes
in build metadata (classpath, compiler options, source roots). When the build
context changes without text changes, stale SemanticDB is reused. Update the
loadFromDisk method to additionally validate a build-context fingerprint
alongside the existing md5 check at line 732. Compute the build-context
fingerprint from current MBT metadata and include it in both the document
storage step (around line 777) and the validation condition in loadFromDisk, so
cache entries are invalidated when build context changes.
- Around line 708-711: Update the cache management around removeEldestEntry so
changes to maxCacheSize are enforced immediately: under the cache lock, remove
eldest entries until the map size is at or below the current configured maximum
before the next cache access, including when the maximum decreases. Preserve the
existing one-entry eviction behavior for normal insertions.
🪄 Autofix

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: d5e7cb9d-8ad0-44a5-88b5-5f7ee4437967

📥 Commits

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

📒 Files selected for processing (8)
  • metals/src/main/scala/scala/meta/internal/metals/Configs.scala
  • metals/src/main/scala/scala/meta/internal/metals/Directories.scala
  • 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/metals/mbt/MbtReferenceProvider.scala
  • metals/src/main/scala/scala/meta/internal/metals/mbt/importer/BazelMbtImporter.scala
  • tests/unit/src/test/scala/tests/UserConfigurationSuite.scala
  • tests/unit/src/test/scala/tests/mbt/MbtReferenceSpec.scala

@zielinsky zielinsky left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Overall LGTM, two nitpicks from me

cacheDir = workspace.resolve(Directories.semanticdbCache)
_ = assert(cacheDir.exists, s"Cache directory should exist: $cacheDir")
cacheFiles = cacheDir.listRecursive.filter(_.isFile).toList
_ = println(s"Cache files: ${cacheFiles.mkString("\n")}")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

redundant print

}
} else None
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we add a newline between loadFromDisk and saveToDisk?

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