Skip to content

Commit

Permalink
Add jump for module-type (like for module)
Browse files Browse the repository at this point in the history
  • Loading branch information
xvw committed Feb 19, 2024
1 parent 0263826 commit bd5d20d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ merlin NEXT_VERSION
- Fix `FLG -pp ppx.exe -as-pp/-dump-ast` use of invalid shell redirection when
direct process launch on Windows. (#1723, fixes #1722)
- Add a query_num field to the `ocamlmerlin` responses to detect server crashes (#1716)
- 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 @@ -89,6 +89,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 @@ -139,6 +143,7 @@ let get typed_tree pos target =
"fun", fun_pred;
"let", let_pred;
"module", module_pred;
"module-type", module_type_pred;
"match", match_pred;
] in
let targets = Str.split (Str.regexp "[, ]") target in
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
15 changes: 15 additions & 0 deletions tests/test-dirs/motion/jump.t
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@
"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:
Expand Down

0 comments on commit bd5d20d

Please sign in to comment.