Skip to content

Commit f46c221

Browse files
committed
Handle error cases in definition_query
1 parent b7faaf2 commit f46c221

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

ocaml-lsp-server/src/definition_query.ml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,23 @@ open Import
22
open Fiber.O
33

44
let location_of_merlin_loc uri : _ -> (_, string) result = function
5-
| `At_origin -> Ok None
6-
| `Builtin _ -> Ok None
5+
| `At_origin -> Error "Already at definition point"
6+
| `Builtin s ->
7+
Error
8+
(sprintf
9+
"%S is a builtin, and it is therefore impossible to jump to its definition"
10+
s)
711
| `File_not_found s -> Error (sprintf "File_not_found: %s" s)
8-
| `Invalid_context -> Ok None
12+
| `Invalid_context -> Error "Not a valid identifier"
913
| `Not_found (ident, where) ->
1014
let msg =
11-
let msg = sprintf "%s not found." ident in
15+
let msg = sprintf "%S not found." ident in
1216
match where with
1317
| None -> msg
1418
| Some w -> sprintf "%s last looked in %s" msg w
1519
in
1620
Error msg
17-
| `Not_in_env m -> Error (sprintf "not in environment: %s" m)
21+
| `Not_in_env m -> Error (sprintf "Not in environment: %s" m)
1822
| `Found (path, lex_position) ->
1923
Ok
2024
(Position.of_lexical_position lex_position
@@ -56,7 +60,6 @@ let run kind (state : State.t) uri position =
5660
(Jsonrpc.Response.Error.make
5761
~code:Jsonrpc.Response.Error.Code.RequestFailed
5862
~message:(sprintf "Request \"Jump to %s\" failed." kind)
59-
~data:
60-
(`String (sprintf "'Locate' query to merlin returned error: %s" err_msg))
63+
~data:(`String (sprintf "Locate: %s" err_msg))
6164
()))
6265
;;

0 commit comments

Comments
 (0)