11import { BusEvent } from "@/bus/bus-event"
22import { Bus } from "@/bus"
33import path from "path"
4+ import { pathToFileURL , fileURLToPath } from "url"
45import { createMessageConnection , StreamMessageReader , StreamMessageWriter } from "vscode-jsonrpc/node"
56import type { Diagnostic as VSCodeDiagnostic } from "vscode-languageserver-types"
67import { 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,
0 commit comments