anomalyco / anomalyco/opencode
LSP root detection silently falls back to workspace root for wildcard markers
@kitlangton is already working on this.
Since Aug 8, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Description
Several language servers declare their project root with a glob pattern rather than a concrete filename:
- Haskell (
haskell-language-server):*.cabal - Terraform (
terraform-ls):*.tf - Julia (
julia-ls):*.jl - Swift / Xcode (
sourcekit-lsp):*.xcodeproj,*.xcworkspace
Filesystem.up (used by NearestRoot in packages/opencode/src/lsp/server.ts) only probes each candidate directory with a literal exists(join(dir, target)). A wildcard target such as *.cabal is never a literal filename, so the probe always returns false. The server therefore never finds the real project root and silently falls back to the workspace root (ctx.directory).
Impact
For multi-package Haskell projects, Terraform modules, Julia packages, and Xcode projects living in subdirectories, the LSP attaches to the wrong root. That breaks go-to-definition across packages, diagnostics, and module-level features — the server effectively cannot tell where the project actually is.
Steps to reproduce
- Open a Haskell project with a cabal package nested under
packages/mylib/mylib.cabal. - Inspect the root that
haskell-language-serveris given. - It resolves to the workspace root instead of
packages/mylib.
Affected servers (in lsp/server.ts)
HLS—NearestRoot(["stack.yaml","cabal.project","hie.yaml","*.cabal"])TerraformLS—NearestRoot([".terraform.lock.hcl","terraform.tfstate","*.tf"])JuliaLS—NearestRoot(["Project.toml","Manifest.toml","*.jl"])SourceKit—NearestRoot(["Package.swift","*.xcodeproj","*.xcworkspace"])
I will follow up with a PR that makes Filesystem.up scan the directory for wildcard targets (using include: "all" so directory-style markers like *.xcodeproj are also matched) and adds regression tests.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.