Skip to content

Commit ffec52a

Browse files
authored
fix: Windows LSP URIs using backslashes (Biome initialization failure) (anomalyco#5317)
1 parent 342595e commit ffec52a

3 files changed

Lines changed: 11 additions & 8 deletions

File tree

packages/opencode/src/config/config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Log } from "../util/log"
22
import path from "path"
3+
import { pathToFileURL } from "url"
34
import os from "os"
45
import z from "zod"
56
import { Filesystem } from "../util/filesystem"
@@ -297,7 +298,7 @@ export namespace Config {
297298
dot: true,
298299
cwd: dir,
299300
})) {
300-
plugins.push("file://" + item)
301+
plugins.push(pathToFileURL(item).href)
301302
}
302303
return plugins
303304
}

packages/opencode/src/lsp/client.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { BusEvent } from "@/bus/bus-event"
22
import { Bus } from "@/bus"
33
import path from "path"
4+
import { pathToFileURL, fileURLToPath } from "url"
45
import { createMessageConnection, StreamMessageReader, StreamMessageWriter } from "vscode-jsonrpc/node"
56
import type { Diagnostic as VSCodeDiagnostic } from "vscode-languageserver-types"
67
import { Log } from "../util/log"
@@ -46,7 +47,7 @@ export namespace LSPClient {
4647

4748
const diagnostics = new Map<string, Diagnostic[]>()
4849
connection.onNotification("textDocument/publishDiagnostics", (params) => {
49-
const path = new URL(params.uri).pathname
50+
const path = fileURLToPath(params.uri)
5051
l.info("textDocument/publishDiagnostics", {
5152
path,
5253
})
@@ -68,20 +69,20 @@ export namespace LSPClient {
6869
connection.onRequest("workspace/workspaceFolders", async () => [
6970
{
7071
name: "workspace",
71-
uri: "file://" + input.root,
72+
uri: pathToFileURL(input.root).href,
7273
},
7374
])
7475
connection.listen()
7576

7677
l.info("sending initialize")
7778
await withTimeout(
7879
connection.sendRequest("initialize", {
79-
rootUri: "file://" + input.root,
80+
rootUri: pathToFileURL(input.root).href,
8081
processId: input.server.process.pid,
8182
workspaceFolders: [
8283
{
8384
name: "workspace",
84-
uri: "file://" + input.root,
85+
uri: pathToFileURL(input.root).href,
8586
},
8687
],
8788
initializationOptions: {
@@ -154,7 +155,7 @@ export namespace LSPClient {
154155
})
155156
await connection.sendNotification("textDocument/didChange", {
156157
textDocument: {
157-
uri: `file://` + input.path,
158+
uri: pathToFileURL(input.path).href,
158159
version: next,
159160
},
160161
contentChanges: [{ text }],
@@ -166,7 +167,7 @@ export namespace LSPClient {
166167
diagnostics.delete(input.path)
167168
await connection.sendNotification("textDocument/didOpen", {
168169
textDocument: {
169-
uri: `file://` + input.path,
170+
uri: pathToFileURL(input.path).href,
170171
languageId,
171172
version: 0,
172173
text,

packages/opencode/src/lsp/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Bus } from "@/bus"
33
import { Log } from "../util/log"
44
import { LSPClient } from "./client"
55
import path from "path"
6+
import { pathToFileURL } from "url"
67
import { LSPServer } from "./server"
78
import z from "zod"
89
import { Config } from "../config/config"
@@ -270,7 +271,7 @@ export namespace LSP {
270271
return run((client) => {
271272
return client.connection.sendRequest("textDocument/hover", {
272273
textDocument: {
273-
uri: `file://${input.file}`,
274+
uri: pathToFileURL(input.file).href,
274275
},
275276
position: {
276277
line: input.line,

0 commit comments

Comments
 (0)