Skip to content

Commit

Permalink
Make the CI pass on Windows
Browse files Browse the repository at this point in the history
The URI gem does not deal with drive letters well...
  • Loading branch information
mame committed Dec 3, 2024
1 parent 1e9d14c commit 558f82f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
1 change: 0 additions & 1 deletion lib/typeprof/lsp.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require "socket"
require "json"
require "uri"

require_relative "lsp/text"
require_relative "lsp/messages"
Expand Down
4 changes: 2 additions & 2 deletions lib/typeprof/lsp/messages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions lib/typeprof/lsp/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/lsp/lsp_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down

0 comments on commit 558f82f

Please sign in to comment.