summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAnton <[email protected]>2025-08-29 22:55:20 -0700
committeropencode <[email protected]>2025-08-30 06:00:39 +0000
commit0c30a6f3030d755b406aaf4c8059c4e6d11570e2 (patch)
tree18c0ff6cce8ffeb498781c38373e292784c3bd9f
parent0c7a887dbc22525bc8fc9530e3e7b7edd805b7cb (diff)
downloadopencode-0c30a6f3030d755b406aaf4c8059c4e6d11570e2.tar.gz
opencode-0c30a6f3030d755b406aaf4c8059c4e6d11570e2.zip
Use a single rust LSP server instance for entire cargo workspace (#2292)
-rw-r--r--packages/opencode/src/lsp/server.ts30
1 files changed, 29 insertions, 1 deletions
diff --git a/packages/opencode/src/lsp/server.ts b/packages/opencode/src/lsp/server.ts
index 2636df967..da743628d 100644
--- a/packages/opencode/src/lsp/server.ts
+++ b/packages/opencode/src/lsp/server.ts
@@ -515,7 +515,35 @@ export namespace LSPServer {
export const RustAnalyzer: Info = {
id: "rust",
- root: NearestRoot(["Cargo.toml", "Cargo.lock"]),
+ root: async (file, app) => {
+ const crateRoot = await NearestRoot(["Cargo.toml", "Cargo.lock"])(file, app)
+ if (crateRoot === undefined) {
+ return undefined
+ }
+ let currentDir = crateRoot
+
+ while (currentDir !== path.dirname(currentDir)) {
+ // Stop at filesystem root
+ const cargoTomlPath = path.join(currentDir, "Cargo.toml")
+ try {
+ const cargoTomlContent = await Bun.file(cargoTomlPath).text()
+ if (cargoTomlContent.includes("[workspace]")) {
+ return currentDir
+ }
+ } catch (err) {
+ // File doesn't exist or can't be read, continue searching up
+ }
+
+ const parentDir = path.dirname(currentDir)
+ if (parentDir === currentDir) break // Reached filesystem root
+ currentDir = parentDir
+
+ // Stop if we've gone above the app root
+ if (!currentDir.startsWith(app.path.root)) break
+ }
+
+ return crateRoot
+ },
extensions: [".rs"],
async spawn(_, root) {
const bin = Bun.which("rust-analyzer")