From 0263826f4e78c850e1a4332e28f73a40cbaea10b Mon Sep 17 00:00:00 2001 From: xvw Date: Mon, 19 Feb 2024 17:11:05 +0100 Subject: [PATCH 1/2] Add test for `jump` to `module` --- tests/test-dirs/motion/jump.t | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/test-dirs/motion/jump.t b/tests/test-dirs/motion/jump.t index fc32437d8a..81594e2095 100644 --- a/tests/test-dirs/motion/jump.t +++ b/tests/test-dirs/motion/jump.t @@ -13,6 +13,24 @@ "notifications": [] } + $ $MERLIN single jump -target module -position 2:3 -filename test.ml < module T = struct + > 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 < Date: Mon, 19 Feb 2024 17:14:31 +0100 Subject: [PATCH 2/2] Add `jump` for `module-type` (like for `module`) --- CHANGES.md | 1 + src/analysis/jump.ml | 5 +++++ src/frontend/ocamlmerlin/new/new_commands.ml | 4 ++-- tests/test-dirs/motion/jump.t | 15 +++++++++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index db6d0be252..38c12b8d15 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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) diff --git a/src/analysis/jump.ml b/src/analysis/jump.ml index 18063d0a36..780bce6319 100644 --- a/src/analysis/jump.ml +++ b/src/analysis/jump.ml @@ -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 @@ -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 diff --git a/src/frontend/ocamlmerlin/new/new_commands.ml b/src/frontend/ocamlmerlin/new/new_commands.ml index 6483aac3b7..a1b753dd7d 100644 --- a/src/frontend/ocamlmerlin/new/new_commands.ml +++ b/src/frontend/ocamlmerlin/new/new_commands.ml @@ -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 " diff --git a/tests/test-dirs/motion/jump.t b/tests/test-dirs/motion/jump.t index 81594e2095..d2fdbb9013 100644 --- a/tests/test-dirs/motion/jump.t +++ b/tests/test-dirs/motion/jump.t @@ -29,6 +29,21 @@ "notifications": [] } + $ $MERLIN single jump -target module-type -position 2:3 -filename test.ml < module type T = sig + > type t + > end + > EOF + { + "class": "return", + "value": { + "pos": { + "line": 1, + "col": 0 + } + }, + "notifications": [] + } Same line should fail: