Skip to content

Commit

Permalink
Allow jump to module type (#1728)
Browse files Browse the repository at this point in the history
from xvw/allow-jump-to-module-type
  • Loading branch information
voodoos authored Feb 21, 2024
2 parents 288a4ae + 12b0906 commit 641fed0
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ merlin NEXT_VERSION
direct process launch on Windows. (#1723, fixes #1722)
- Add a query_num field to the `ocamlmerlin` responses to detect server crashes (#1716)
- Jump to cases within a match statement (#1726)
- Jump to `module-type` (#1728, partially fixes #1656)
+ editor modes
- vim: load merlin under the ocamlinterface and ocamllex filetypes (#1340)
- Fix merlinpp not using binary file open (#1725, fixes #1724)
Expand Down
5 changes: 5 additions & 0 deletions src/analysis/jump.ml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ let module_pred = function
| _ -> None
;;

let module_type_pred = function
| (Module_type_declaration _ as node) :: _ -> Some node
| _ -> None

let match_pred = function
| (Expression { exp_desc = Texp_match _ ; _ } as node) :: _ -> Some node
| _ -> None
Expand Down Expand Up @@ -172,6 +176,7 @@ let get typed_tree pos target =
"fun", fun_pred;
"let", let_pred;
"module", module_pred;
"module-type", module_type_pred;
"match", match_pred;
"match-next-case", match_pred;
"match-prev-case", match_pred;
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/ocamlmerlin/new/new_commands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ compiler settings in an IDE."
(marg_position (fun pos (target,_pos) -> (target,pos)));
]
~doc:"This command can be used to assist navigation in a source code buffer.
Target is a string that can contain one or more of the 'fun', 'let', 'module' \
and 'match' words.
Target is a string that can contain one or more of the 'fun', 'let', 'module', \
'module-type' and 'match' words.
It returns the starting position of the function, let definition, module or \
match expression that contains the cursor
"
Expand Down
33 changes: 33 additions & 0 deletions tests/test-dirs/motion/jump.t
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,39 @@
"notifications": []
}

$ $MERLIN single jump -target module -position 2:3 -filename test.ml <<EOF
> module T = struct
> type t
> end
> EOF
{
"class": "return",
"value": {
"pos": {
"line": 1,
"col": 0
}
},
"notifications": []
}

$ $MERLIN single jump -target module-type -position 2:3 -filename test.ml <<EOF
> module type T = sig
> type t
> end
> EOF
{
"class": "return",
"value": {
"pos": {
"line": 1,
"col": 0
}
},
"notifications": []
}


Same line should fail:

$ $MERLIN single jump -target let -position 1:8 -filename test.ml <<EOF
Expand Down

0 comments on commit 641fed0

Please sign in to comment.