From 6bda99068c552a4c24dd86494e30574c7c38a1f8 Mon Sep 17 00:00:00 2001 From: Bao Zhiyuan <71200607+bzy-debug@users.noreply.github.com> Date: Wed, 18 Oct 2023 13:35:39 +0800 Subject: [PATCH] Fix uri to_string (#1197) The current implementation is not the same as uri.ts see microsoft/vscode-uri@96acdc0/src/uri.ts#L601 the ts code just checks if authority is empty, while ocaml code checks if authority is "file" Co-authored-by: Bao Zhiyuan --- CHANGES.md | 2 ++ lsp/src/uri0.ml | 3 ++- lsp/test/uri_tests.ml | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 666c1bd37..169923877 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,6 +13,8 @@ - Improve type-on-hover and type-annotate efficiency by only formatting the type of the first enclosing. (#1191, #1196) +- Fix the encoding of URI's to match how vscode does it (#1197) + ## Features - Display text of references in doc strings (#1166) diff --git a/lsp/src/uri0.ml b/lsp/src/uri0.ml index 158dc2a34..b04d4ab41 100644 --- a/lsp/src/uri0.ml +++ b/lsp/src/uri0.ml @@ -96,7 +96,8 @@ let to_string { scheme; authority; path } = Buffer.add_string buff scheme; Buffer.add_char buff ':'); - if authority = "file" || scheme = "file" then Buffer.add_string buff "//"; + if (not (String.is_empty authority)) || scheme = "file" then + Buffer.add_string buff "//"; (*TODO: implement full logic: https://github.com/microsoft/vscode-uri/blob/96acdc0be5f9d5f2640e1c1f6733bbf51ec95177/src/uri.ts#L605 *) diff --git a/lsp/test/uri_tests.ml b/lsp/test/uri_tests.ml index 8d5888b81..e8f4d776d 100644 --- a/lsp/test/uri_tests.ml +++ b/lsp/test/uri_tests.ml @@ -216,6 +216,7 @@ let%expect_test "of_string -> to_string" = ; "" ; "file://LöC%2FAL/host:8080/projects/" ; "file:///pro%2Fjects/" + ; "vscode://mount/test.ml" ]; [%expect {| @@ -230,6 +231,7 @@ let%expect_test "of_string -> to_string" = -> file:/// file://LöC%2FAL/host:8080/projects/ -> file://l%C3%B6c%2Fal/host%3A8080/projects/ file:///pro%2Fjects/ -> file:///pro/jects/ + vscode://mount/test.ml -> vscode://mount/test.ml Windows: file://shares/pröjects/c%23/#l12 -> file://shares/pr%C3%B6jects/c%23/ file://sh%c3%a4res/path -> file://sh%C3%A4res/path @@ -241,6 +243,7 @@ let%expect_test "of_string -> to_string" = -> file:/// file://LöC%2FAL/host:8080/projects/ -> file://l%C3%B6c%2Fal/host%3A8080/projects/ file:///pro%2Fjects/ -> file:///pro/jects/ + vscode://mount/test.ml -> vscode://mount/test.ml |}] let%expect_test "of_string -> to_path" =