Skip to content

Commit

Permalink
return a single position instead of a range
Browse files Browse the repository at this point in the history
  • Loading branch information
PizieDust committed Sep 18, 2024
1 parent 3068f87 commit dda8ffd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 43 deletions.
17 changes: 5 additions & 12 deletions ocaml-lsp-server/docs/ocamllsp/merlinJump-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,14 @@ export interface JumpParams extends TextDocumentPositionParams

```js
result: Jump | String
export interface Jump extends Location {
uri: string;
range: {
start: Position;
end: Position;
}
export interface Jump extends TextDocumentPositionParams {
}
```

- result:
- Type: Jump or string
- Description: If the jump is successful, a list of locations is returned where the first location is the most relevant one. If no relevant jump location is found, the result will be a string "no matching target" or an error message.
- Description: If the jump is successful, a position and document path is returned. If no relevant jump location is found, the result will be a string "no matching target" or an error message.
- Jump:
- Type: Location[], A list of Location objects representing the potential targets of the jump.
- Location:
- uri: The URI of the document where the jump target is located.
- range: The range within the document where the jump target is located. Both start and end positions are the same as the jump target location.
The Location type is the same type returned by `Goto` requests such as `goto-definition`, `goto-declaration` and `goto-typeDefinition`.
- Type: TextDocumentPositionParams
- `Position`: The position to jump to
- `TextDocumentIdentifier`: the document path which contains this position (ideally the same document as the request)
22 changes: 9 additions & 13 deletions ocaml-lsp-server/src/custom_requests/req_merlin_jump.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,10 @@ module JumpParams = struct
end

module Jump = struct
type t = [ `Location of Location.t list ]
type t = Lsp.Types.TextDocumentPositionParams.t

let yojson_of_t t = `List (List.map ~f:Location.yojson_of_t t)

let t_of_yojson json =
match json with
| `List lst ->
let locations = List.map ~f:Location.t_of_yojson lst in
`Location locations
| _ -> failwith "Invalid JSON for Jump.t"
;;
let yojson_of_t t = TextDocumentPositionParams.yojson_of_t t
let t_of_yojson json = Lsp.Types.TextDocumentPositionParams.t_of_yojson json
end

type t = Jump.t
Expand Down Expand Up @@ -78,7 +71,10 @@ let on_request ~params state =
(match Position.of_lexical_position pos with
| None -> Fiber.return `Null
| Some position ->
let range = { Range.start = position; end_ = position } in
let locs = [ { Location.range; uri } ] in
Fiber.return (Jump.yojson_of_t locs))))
let loc =
Lsp.Types.TextDocumentPositionParams.create
~position
~textDocument:(TextDocumentIdentifier.create ~uri)
in
Fiber.return (Jump.yojson_of_t loc))))
;;
26 changes: 8 additions & 18 deletions ocaml-lsp-server/test/e2e-new/merlin_jump.ml
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,10 @@ match x with
Util.test ~line ~character ~target ~source;
[%expect
{|
[
{
"range": {
"end": { "character": 2, "line": 4 },
"start": { "character": 2, "line": 4 }
},
"uri": "file:///test.ml"
}
] |}]
{
"position": { "character": 2, "line": 4 },
"textDocument": { "uri": "file:///test.ml" }
} |}]
;;

let%expect_test "Get location of a the module" =
Expand Down Expand Up @@ -83,15 +78,10 @@ end|}
Util.test ~line ~character ~target ~source;
[%expect
{|
[
{
"range": {
"end": { "character": 2, "line": 7 },
"start": { "character": 2, "line": 7 }
},
"uri": "file:///test.ml"
}
] |}]
{
"position": { "character": 2, "line": 7 },
"textDocument": { "uri": "file:///test.ml" }
} |}]
;;

let%expect_test "Same line should output no locations" =
Expand Down

0 comments on commit dda8ffd

Please sign in to comment.