From bb54e4c1be093fa075f120dcc5fcb02cfd4e4b80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulysse=20G=C3=A9rard?= Date: Mon, 10 Jun 2024 14:11:23 +0200 Subject: [PATCH 1/2] merlin-lib.commandsmerlin.commands: Add a `find_command_opt` Alternative to `find_command_opt` that doesn't raise --- src/commands/new_commands.ml | 15 +++++++-------- src/commands/new_commands.mli | 6 ++++++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/commands/new_commands.ml b/src/commands/new_commands.ml index 81e5ff1bc..4491ae9f2 100644 --- a/src/commands/new_commands.ml +++ b/src/commands/new_commands.ml @@ -81,12 +81,11 @@ let marg_completion_kind f = Marg.param "completion-kind" str ) -let rec find_command name = function - | [] -> raise Not_found - | (Command (name', _, _, _, _) as command) :: xs -> - if name = name' then - command - else find_command name xs +let command_is ~name (Command (name', _, _, _, _)) = String.equal name name' + +let find_command name = List.find ~f:(command_is ~name) + +let find_command_opt name = List.find_opt ~f:(command_is ~name) let run pipeline query = Logger.log ~section:"New_commands" ~title:"run(query)" @@ -236,9 +235,9 @@ Otherwise, Merlin looks for the documentation for the entity under the cursor (a ] ~default: `None begin fun buffer pos -> - match pos with + match pos with | `None -> failwith "-position is mandatory" - | #Msource.position as pos -> + | #Msource.position as pos -> run buffer (Query_protocol.Syntax_document pos) end ; diff --git a/src/commands/new_commands.mli b/src/commands/new_commands.mli index e8f766f82..7c62b49d8 100644 --- a/src/commands/new_commands.mli +++ b/src/commands/new_commands.mli @@ -35,4 +35,10 @@ type command = val all_commands : command list +(** [find_command name cmds] returns the command with name [name] in the list + [cmds] if it exists. Raises [Not_found] if it does not. *) val find_command : string -> command list -> command + +(** [find_command name cmds] optionaly returns the command with name [name] if + it is in the list [cmds]. *) +val find_command_opt : string -> command list -> command option From 3df384ae23e5366b896de0ae8b4f75c7673ecb12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulysse=20G=C3=A9rard?= Date: Mon, 10 Jun 2024 14:15:57 +0200 Subject: [PATCH 2/2] Add changelog entry for #1778 --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 035529470..26b274947 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,8 @@ UNRELEASED - A new `UNIT_NAME` configuration directive that can be used to tell Merlin the correct name of the current unit in the presence of wrapping (#1776) - Perform incremental indexation of the buffer when typing. (#1777) + - `merlin-lib.commands`: Add a `find_command_opt`` alternative to + `find_command` that does not raise (#1778) + editor modes - emacs: add basic support for project-wide occurrences (#1766) - vim: add basic support for project-wide occurrences (#1767, @Julow)