improvement: Save semanticdb to disk under setting - #8762
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
79d6eb3 to
d2a3109
Compare
Also allow to specify the maximum cache size for the text document cache.
d2a3109 to
2c372ca
Compare
There was a problem hiding this comment.
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
📒 Files selected for processing (8)
metals/src/main/scala/scala/meta/internal/metals/Configs.scalametals/src/main/scala/scala/meta/internal/metals/Directories.scalametals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scalametals/src/main/scala/scala/meta/internal/metals/UserConfiguration.scalametals/src/main/scala/scala/meta/internal/metals/mbt/MbtReferenceProvider.scalametals/src/main/scala/scala/meta/internal/metals/mbt/importer/BazelMbtImporter.scalatests/unit/src/test/scala/tests/UserConfigurationSuite.scalatests/unit/src/test/scala/tests/mbt/MbtReferenceSpec.scala
zielinsky
left a comment
There was a problem hiding this comment.
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")}") |
| } | ||
| } else None | ||
| } | ||
| } |
There was a problem hiding this comment.
Can we add a newline between loadFromDisk and saveToDisk?
Also allow to specify the maximum cache size for the text document cache.
Summary by CodeRabbit
New Features
mbt.*configuration settings.Bug Fixes