diff --git a/lib/typeprof/lsp.rb b/lib/typeprof/lsp.rb index bdf55adaf..9977b4e9b 100644 --- a/lib/typeprof/lsp.rb +++ b/lib/typeprof/lsp.rb @@ -1,6 +1,5 @@ require "socket" require "json" -require "uri" require_relative "lsp/text" require_relative "lsp/messages" diff --git a/lib/typeprof/lsp/messages.rb b/lib/typeprof/lsp/messages.rb index 55e944412..603a497c9 100644 --- a/lib/typeprof/lsp/messages.rb +++ b/lib/typeprof/lsp/messages.rb @@ -72,7 +72,7 @@ class Message::Initialize < Message def run folders = @params[:workspaceFolders].map do |folder| folder => { uri:, } - URI(uri).path + TypeProf::LSP.file_uri_to_path(uri) end @server.add_workspaces(folders) @@ -146,7 +146,7 @@ class Message::TextDocument::DidOpen < Message def run @params => { textDocument: { uri:, version:, text: } } - path = URI(uri).path + path = TypeProf::LSP.file_uri_to_path(uri) return unless @server.target_path?(path) text = Text.new(path, text, version) diff --git a/lib/typeprof/lsp/util.rb b/lib/typeprof/lsp/util.rb index 2cab8345c..770b6b131 100644 --- a/lib/typeprof/lsp/util.rb +++ b/lib/typeprof/lsp/util.rb @@ -48,4 +48,14 @@ def self.load_json_with_comments(path, **opts) JSON.parse(json, **opts) end + + FILE_URL_PREFIX = File::ALT_SEPARATOR != "\\" ? "file://" : "file:///" + + def self.file_path_to_uri(path) + FILE_URL_PREFIX + File.expand_path(path) + end + + def self.file_uri_to_path(url) + url.delete_prefix(FILE_URL_PREFIX) + end end diff --git a/test/lsp/lsp_test.rb b/test/lsp/lsp_test.rb index 30b430372..1d909160e 100644 --- a/test/lsp/lsp_test.rb +++ b/test/lsp/lsp_test.rb @@ -39,7 +39,7 @@ def setup end def init(fixture) - @folder = "file://" + File.expand_path(File.join(__dir__, "..", "fixtures", fixture)) + "/" + @folder = TypeProf::LSP.file_path_to_uri(File.expand_path(File.join(__dir__, "..", "fixtures", fixture))) + "/" id = request("initialize", workspaceFolders: [{ uri: @folder }]) expect_response(id) do |recv| assert_equal({ name: "typeprof", version: TypeProf::VERSION }, recv[:serverInfo])