anomalyco / anomalyco/opencode

LSP root detection silently falls back to workspace root for wildcard markers

Open
#41,168 0 comments 0 reactions 1 assignee View on GitHub

@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

  1. Open a Haskell project with a cabal package nested under packages/mylib/mylib.cabal.
  2. Inspect the root that haskell-language-server is given.
  3. It resolves to the workspace root instead of packages/mylib.

Affected servers (in lsp/server.ts)

  • HLSNearestRoot(["stack.yaml","cabal.project","hie.yaml","*.cabal"])
  • TerraformLSNearestRoot([".terraform.lock.hcl","terraform.tfstate","*.tf"])
  • JuliaLSNearestRoot(["Project.toml","Manifest.toml","*.jl"])
  • SourceKitNearestRoot(["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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.