Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 7 additions & 8 deletions src/commands/new_commands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down Expand Up @@ -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 <pos> is mandatory"
| #Msource.position as pos ->
| #Msource.position as pos ->
run buffer (Query_protocol.Syntax_document pos)
end
;
Expand Down
6 changes: 6 additions & 0 deletions src/commands/new_commands.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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