Просмотр исходного кода

fix: Windows LSP URIs using backslashes (Biome initialization failure) (#5317)

Adán 2 месяцев назад
Родитель
Сommit
ffec52a17c

+ 2 - 1
packages/opencode/src/config/config.ts

@@ -1,5 +1,6 @@
 import { Log } from "../util/log"
 import path from "path"
+import { pathToFileURL } from "url"
 import os from "os"
 import z from "zod"
 import { Filesystem } from "../util/filesystem"
@@ -297,7 +298,7 @@ export namespace Config {
       dot: true,
       cwd: dir,
     })) {
-      plugins.push("file://" + item)
+      plugins.push(pathToFileURL(item).href)
     }
     return plugins
   }

+ 7 - 6
packages/opencode/src/lsp/client.ts

@@ -1,6 +1,7 @@
 import { BusEvent } from "@/bus/bus-event"
 import { Bus } from "@/bus"
 import path from "path"
+import { pathToFileURL, fileURLToPath } from "url"
 import { createMessageConnection, StreamMessageReader, StreamMessageWriter } from "vscode-jsonrpc/node"
 import type { Diagnostic as VSCodeDiagnostic } from "vscode-languageserver-types"
 import { Log } from "../util/log"
@@ -46,7 +47,7 @@ export namespace LSPClient {
 
     const diagnostics = new Map<string, Diagnostic[]>()
     connection.onNotification("textDocument/publishDiagnostics", (params) => {
-      const path = new URL(params.uri).pathname
+      const path = fileURLToPath(params.uri)
       l.info("textDocument/publishDiagnostics", {
         path,
       })
@@ -68,7 +69,7 @@ export namespace LSPClient {
     connection.onRequest("workspace/workspaceFolders", async () => [
       {
         name: "workspace",
-        uri: "file://" + input.root,
+        uri: pathToFileURL(input.root).href,
       },
     ])
     connection.listen()
@@ -76,12 +77,12 @@ export namespace LSPClient {
     l.info("sending initialize")
     await withTimeout(
       connection.sendRequest("initialize", {
-        rootUri: "file://" + input.root,
+        rootUri: pathToFileURL(input.root).href,
         processId: input.server.process.pid,
         workspaceFolders: [
           {
             name: "workspace",
-            uri: "file://" + input.root,
+            uri: pathToFileURL(input.root).href,
           },
         ],
         initializationOptions: {
@@ -154,7 +155,7 @@ export namespace LSPClient {
             })
             await connection.sendNotification("textDocument/didChange", {
               textDocument: {
-                uri: `file://` + input.path,
+                uri: pathToFileURL(input.path).href,
                 version: next,
               },
               contentChanges: [{ text }],
@@ -166,7 +167,7 @@ export namespace LSPClient {
           diagnostics.delete(input.path)
           await connection.sendNotification("textDocument/didOpen", {
             textDocument: {
-              uri: `file://` + input.path,
+              uri: pathToFileURL(input.path).href,
               languageId,
               version: 0,
               text,

+ 2 - 1
packages/opencode/src/lsp/index.ts

@@ -3,6 +3,7 @@ import { Bus } from "@/bus"
 import { Log } from "../util/log"
 import { LSPClient } from "./client"
 import path from "path"
+import { pathToFileURL } from "url"
 import { LSPServer } from "./server"
 import z from "zod"
 import { Config } from "../config/config"
@@ -270,7 +271,7 @@ export namespace LSP {
     return run((client) => {
       return client.connection.sendRequest("textDocument/hover", {
         textDocument: {
-          uri: `file://${input.file}`,
+          uri: pathToFileURL(input.file).href,
         },
         position: {
           line: input.line,