bugfix: skip Scala CLI auto-start outside workspace folders - #8737
bugfix: skip Scala CLI auto-start outside workspace folders#8737russwyte wants to merge 9 commits into
Conversation
Editor agents can open Scala files outside the LSP workspace, which previously made FallbackMetalsLspService spawn Scala CLI BSP for each orphan. Gate auto-start on workspace folder membership; manual start is unchanged. Fixes scalameta#8736.
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughScala CLI fallback auto-start now checks Scala file type and workspace-folder containment. Workspace folders are supplied dynamically to the fallback service, which skips out-of-workspace startup while retaining in-workspace orphan behavior. Unit and LSP tests cover these decisions. ChangesWorkspace-aware Scala CLI auto-start
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant LSPClient
participant WorkspaceLspService
participant FallbackMetalsLspService
participant ScalaCliAutoStart
LSPClient->>WorkspaceLspService: didOpen document
WorkspaceLspService->>FallbackMetalsLspService: handle document path
FallbackMetalsLspService->>ScalaCliAutoStart: check workspace and file type
alt outside workspace
ScalaCliAutoStart-->>FallbackMetalsLspService: skip startup
FallbackMetalsLspService-->>LSPClient: clear diagnostics
else eligible path
ScalaCliAutoStart-->>FallbackMetalsLspService: allow startup
FallbackMetalsLspService->>FallbackMetalsLspService: start/import Scala CLI and run load()
end
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
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 `@tests/unit/src/test/scala/tests/OutOfWorkspaceScalaCliLspSuite.scala`:
- Around line 43-52: The fixed 500 ms delays do not synchronize assertions with
fallback import completion. In
tests/unit/src/test/scala/tests/OutOfWorkspaceScalaCliLspSuite.scala#L43-L52 and
`#L81-L87`, replace each Thread.sleep-based wait with awaiting the fallback-import
task or the existing test-harness idle hook before performing the Scala CLI
server/path assertions.
🪄 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: 3da690e7-235c-4cb8-8c22-d6ddfe3afcf7
📒 Files selected for processing (5)
metals/src/main/scala/scala/meta/internal/metals/FallbackMetalsLspService.scalametals/src/main/scala/scala/meta/internal/metals/WorkspaceLspService.scalametals/src/main/scala/scala/meta/internal/metals/scalacli/ScalaCliAutoStart.scalatests/unit/src/test/scala/tests/OutOfWorkspaceScalaCliLspSuite.scalatests/unit/src/test/scala/tests/ScalaCliAutoStartSuite.scala
Skipping Scala CLI was not enough: presentation-compiler load still published Problems for Cursor-restored sibling files. Short-circuit didOpen, clear diagnostics, and skip import/load for paths outside workspace folders.
|
Opened a parallel port to |
|
Parallel port to |
Keep API-only docs, demote ignore logs to debug, and expand unit/LSP edge cases (including lexical symlink membership) for reviewability.
Summary
textDocument/didOpentargets a path outside the LSP workspace folder(s).didOpeninFallbackMetalsLspService, clears stale diagnostics, and gates auto-start viaScalaCliAutoStart.WorkspaceLspServicepasses both Scala and non-Scala folder roots into the check. Empty folder list keeps legacy auto-start (standalone / no-folder sessions). Manualmetals.scala-cli-startis unchanged.Motivation
Some editors (notably Cursor) can send
didOpenfor Scala files outside the configured workspace. Metals treated those as orphans and started a Scala CLI BSP per file, flooding Problems and spawning many processes even with no open tabs.Test plan
unit/testOnly tests.ScalaCliAutoStartSuite(membership policy: in/out, siblings, empty folders, non-Scala/Java, scripts, worksheets/sbt, multi-folder, prefix lookalikes, lexical symlink cases)unit/testOnly tests.OutOfWorkspaceScalaCliLspSuite(LSP: outside/sibling skip; empty folders still auto-start; outside.sc/ non-Scala / repeated outsiders)ScalaCliSuite/StartScalaCliServer)