From dc92735fab6250491344cf37cb0a0350d8e5f914 Mon Sep 17 00:00:00 2001 From: S-H-GAMELINKS Date: Thu, 24 Apr 2025 23:10:14 +0900 Subject: [PATCH 1/4] Fixed typeprof.conf.json could not be loaded on VSCode on Windows The problem was that the `url` processed by `uri_to_path` was like `c%3A/Users/shunh/vscode-typeprof-test`, and typeprof.conf.json could not be loaded. This meant that TypeProf could be launched as an LSP, but the results of type analysis were not displayed on VSCode. So, I changed that if `%3A` is included in the url returned by `uri_to_path`, it is replaced with `:`. --- lib/typeprof/lsp/server.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/typeprof/lsp/server.rb b/lib/typeprof/lsp/server.rb index 0d0d11e2..2d3dffd8 100644 --- a/lib/typeprof/lsp/server.rb +++ b/lib/typeprof/lsp/server.rb @@ -69,7 +69,13 @@ def path_to_uri(path) end def uri_to_path(url) - url.delete_prefix(@url_schema) + path = url.delete_prefix(@url_schema) + + if path.include?('%3A') + path.sub(/%3A/, ':') + else + path + end end #: (Array[String]) -> void From 4053377e3e79e4e32ca23f8afcb8c6ea1840b9a7 Mon Sep 17 00:00:00 2001 From: S-H-GAMELINKS Date: Fri, 25 Apr 2025 22:38:03 +0900 Subject: [PATCH 2/4] Use CGI.unescape_uri_component to unescape path for Windows --- lib/typeprof/lsp/server.rb | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/typeprof/lsp/server.rb b/lib/typeprof/lsp/server.rb index 2d3dffd8..cf9e5276 100644 --- a/lib/typeprof/lsp/server.rb +++ b/lib/typeprof/lsp/server.rb @@ -1,3 +1,5 @@ +require "cgi" + module TypeProf::LSP module ErrorCodes ParseError = -32700 @@ -69,13 +71,7 @@ def path_to_uri(path) end def uri_to_path(url) - path = url.delete_prefix(@url_schema) - - if path.include?('%3A') - path.sub(/%3A/, ':') - else - path - end + CGI.unescape_uri_component(url.delete_prefix(@url_schema)) end #: (Array[String]) -> void From 7f90ce46b2a5ea19846d4d9485de7d8211dc4b1f Mon Sep 17 00:00:00 2001 From: S-H-GAMELINKS Date: Sat, 26 Apr 2025 12:32:09 +0900 Subject: [PATCH 3/4] Changed escape the path in path_to_uri method, and unescape the uri in uri_to_path method --- lib/typeprof/lsp/server.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/typeprof/lsp/server.rb b/lib/typeprof/lsp/server.rb index cf9e5276..3ca67b5b 100644 --- a/lib/typeprof/lsp/server.rb +++ b/lib/typeprof/lsp/server.rb @@ -67,11 +67,11 @@ def initialize(core_options, reader, writer, url_schema: nil, publish_all_diagno #: (String) -> String def path_to_uri(path) - @url_schema + File.expand_path(path) + @url_schema + File.expand_path(path).split("/").map {|s| CGI.escape_uri_component(s) }.join("/") end - def uri_to_path(url) - CGI.unescape_uri_component(url.delete_prefix(@url_schema)) + def uri_to_path(uri) + uri.delete_prefix(@url_schema).split("/").map {|s| CGI.unescape_uri_component(s) }.join("/") end #: (Array[String]) -> void From 475230c561165e57f71b0960979921d769be7a7f Mon Sep 17 00:00:00 2001 From: S-H-GAMELINKS Date: Sat, 26 Apr 2025 19:04:47 +0900 Subject: [PATCH 4/4] Use CGI.escapeURIComponent and CGI.unescapeURIComponent for compatibility --- lib/typeprof/lsp/server.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/typeprof/lsp/server.rb b/lib/typeprof/lsp/server.rb index 3ca67b5b..3fd9419f 100644 --- a/lib/typeprof/lsp/server.rb +++ b/lib/typeprof/lsp/server.rb @@ -67,11 +67,11 @@ def initialize(core_options, reader, writer, url_schema: nil, publish_all_diagno #: (String) -> String def path_to_uri(path) - @url_schema + File.expand_path(path).split("/").map {|s| CGI.escape_uri_component(s) }.join("/") + @url_schema + File.expand_path(path).split("/").map {|s| CGI.escapeURIComponent(s) }.join("/") end def uri_to_path(uri) - uri.delete_prefix(@url_schema).split("/").map {|s| CGI.unescape_uri_component(s) }.join("/") + uri.delete_prefix(@url_schema).split("/").map {|s| CGI.unescapeURIComponent(s) }.join("/") end #: (Array[String]) -> void