Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions ocaml-lsp-server/test/e2e-new/definition.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ open Test.Import

let print_locations = Test.print_option Locations.yojson_of_t

let rec censor_backtraces = function
| `Assoc fields ->
`Assoc
(List.map fields ~f:(fun (name, value) ->
if String.equal name "backtrace"
then name, `String "<censored>"
else name, censor_backtraces value))
| `List values -> `List (List.map values ~f:censor_backtraces)
| json -> json
;;

let definition client position =
let textDocument = TextDocumentIdentifier.create ~uri:Helpers.uri in
Client.request
Expand Down Expand Up @@ -53,6 +64,32 @@ let%expect_test "reports definition lookup failures without stopping the server"
|}]
;;

let%expect_test "definition of a nullary exception leaks Not_found" =
let source = "exception E\nE" in
Helpers.test source (fun client ->
let* result =
Fiber.collect_errors (fun () ->
definition client (Position.create ~line:1 ~character:1))
in
match result with
| Error [ { Exn_with_backtrace.exn = Jsonrpc.Response.Error.E error; backtrace = _ } ]
->
Jsonrpc.Response.Error.yojson_of_t error |> censor_backtraces |> Test.print_result;
Fiber.return ()
| Error errors -> Fiber.reraise_all errors
| Ok response ->
print_locations response;
Fiber.return ());
[%expect
{|
{
"data": { "exn": "Not_found", "backtrace": "<censored>" },
"code": -32603,
"message": "uncaught exception"
}
|}]
;;

let%expect_test "returns location of a definition" =
let source =
{ocaml|let x = 43
Expand Down
Loading