-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test(uri): add an e2e test for uri #771
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
stdune | ||
fiber | ||
yojson | ||
ppx_yojson_conv_lib | ||
lev_fiber | ||
lev | ||
spawn | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
open Test.Import | ||
|
||
let%expect_test "start/stop" = | ||
let handler = | ||
let on_request (type r) _ (r : r Lsp.Server_request.t) : | ||
(r Lsp_fiber.Rpc.Reply.t * unit) Fiber.t = | ||
match r with | ||
| ShowDocumentRequest p -> | ||
print_endline "client: received show document parms"; | ||
let json = | ||
ShowDocumentParams.yojson_of_t { p with uri = "<redacted>" } | ||
in | ||
Yojson.Safe.to_channel stdout json; | ||
print_endline ""; | ||
print_endline "metrics contents:"; | ||
print_endline (Stdune.Io.String_path.read_file p.uri); | ||
let res = ShowDocumentResult.create ~success:true in | ||
Fiber.return (Lsp_fiber.Rpc.Reply.now res, ()) | ||
| _ -> assert false | ||
in | ||
let on_request = { Client.Handler.on_request } in | ||
Client.Handler.make ~on_request () | ||
in | ||
( Test.run ~handler @@ fun client -> | ||
let run_client () = | ||
let capabilities = ClientCapabilities.create () in | ||
Client.start client (InitializeParams.create ~capabilities ()) | ||
in | ||
let run = | ||
let* (_ : InitializeResult.t) = Client.initialized client in | ||
let view_metrics = | ||
ExecuteCommandParams.create ~command:"ocamllsp/view-metrics" () | ||
in | ||
let+ res = Client.request client (ExecuteCommand view_metrics) in | ||
print_endline "server: receiving response"; | ||
Yojson.Safe.to_channel stdout res; | ||
print_endline "" | ||
in | ||
Fiber.fork_and_join_unit run_client (fun () -> run >>> Client.stop client) | ||
); | ||
[%expect | ||
{| | ||
client: received show document parms | ||
{"uri":"<redacted>","takeFocus":true} | ||
metrics contents: | ||
{"traceEvents":[]} | ||
server: receiving response | ||
null |}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
open Test.Import | ||
|
||
let%expect_test "uri" = | ||
let notif_received = Fiber.Ivar.create () in | ||
let handler = | ||
let on_notification _ (notification : Lsp.Server_notification.t) = | ||
(match notification with | ||
| PublishDiagnostics d -> | ||
print_endline "client: received publish diagnostics notification"; | ||
Printf.printf "uri received from the server: %s\n" (d.uri |> DocumentUri.to_string) | ||
| ShowMessage _ | ||
| LogMessage _ | ||
| TelemetryNotification _ | ||
| CancelRequest _ | ||
| WorkDoneProgress _ | ||
| UnknownNotification _ -> ()); | ||
let* () = Fiber.Ivar.fill notif_received () in | ||
Fiber.return () | ||
in | ||
Client.Handler.make ~on_notification () | ||
in | ||
( Test.run ~handler @@ fun client -> | ||
let run_client () = | ||
let capabilities = ClientCapabilities.create () in | ||
Client.start client (InitializeParams.create ~capabilities ()) | ||
in | ||
let run = | ||
let* (_ : InitializeResult.t) = Client.initialized client in | ||
let uri = DocumentUri.of_path "src/néw/Mödel + Other Thîngß/test.ml" in | ||
Printf.printf "uri sent to the server: %s\n" (DocumentUri.to_string uri); | ||
let textDocument = | ||
TextDocumentItem.create ~uri ~languageId:"ocaml" ~text:"" ~version:0 | ||
in | ||
let params = DidOpenTextDocumentParams.create ~textDocument in | ||
let* () = Client.notification client (TextDocumentDidOpen params) in | ||
Fiber.Ivar.read notif_received | ||
in | ||
Fiber.fork_and_join_unit run_client (fun () -> run >>> Client.stop client) | ||
); | ||
[%expect | ||
{| | ||
uri sent to the server: file:///src/néw/Mödel + Other Thîngß/test.ml | ||
client: received publish diagnostics notification | ||
uri received from the server: file:///src/néw/Mödel + Other Thîngß/test.ml |}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import outdent from "outdent"; | ||
import * as rpc from "vscode-jsonrpc/node"; | ||
import * as LanguageServer from "../src/LanguageServer"; | ||
import * as Protocol from "vscode-languageserver-protocol"; | ||
import * as Types from "vscode-languageserver-types"; | ||
import { URI } from "vscode-uri"; | ||
|
||
describe("uri", () => { | ||
let languageServer: rpc.MessageConnection; | ||
const uri = URI.file("src/néw/Mödel + Other Thîngß/test.ml").toString(); | ||
|
||
function openDocument(source: string) { | ||
languageServer.sendNotification( | ||
Protocol.DidOpenTextDocumentNotification.type, | ||
{ | ||
textDocument: Types.TextDocumentItem.create(uri, "ocaml", 0, source), | ||
}, | ||
); | ||
} | ||
|
||
beforeEach(async () => { | ||
languageServer = await LanguageServer.startAndInitialize(); | ||
}); | ||
|
||
afterEach(async () => { | ||
await LanguageServer.exit(languageServer); | ||
}); | ||
|
||
it("handles uri with special characters", async () => { | ||
let receivedDiganostics: Promise<Protocol.PublishDiagnosticsParams> = | ||
new Promise((resolve, _reject) => | ||
languageServer.onNotification( | ||
Protocol.PublishDiagnosticsNotification.type, | ||
(params) => { | ||
resolve(params); | ||
}, | ||
), | ||
); | ||
openDocument(outdent` | ||
let () = | ||
let x = 123 in | ||
() | ||
`); | ||
const params = await receivedDiganostics; | ||
|
||
expect(params.uri).toBe(uri); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It fails with: Expected: "file:///src/n%C3%A9w/M%C3%B6del%20%2B%20Other%20Th%C3%AEng%C3%9F/test.ml"
Received: "file:///src/n%C3%A9w/M%C3%B6del %2B Other Th%C3%AEng%C3%9F/test.ml" #739 should fix it but I'm not sure if we really need an e2e test for that since we already have OCaml tests for the URI parsing? |
||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it represents what happens in reality because our
DocumentUri.of_path
implementation isn't correct so the URI string that will be sent to the server is already "broken".What happens in real is that VSCode sends a valid URI string, and the server returns an incorrect one (due to an incorrect parsing).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I said, I'm not sure that an e2e test is useful for that. We already have unit tests for the URI parsing.