Skip to content

Commit

Permalink
Move typed_hole from ocaml-lsp
Browse files Browse the repository at this point in the history
  • Loading branch information
liam923 committed Jan 31, 2025
1 parent 9f0a6b5 commit 87d4877
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/analysis/typed_hole.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
let syntax_repr = "_"
let can_be_hole s = String.equal syntax_repr s

(* the pattern matching below is taken and modified (minimally, to adapt the
return type) from [Query_commands.dispatch]'s [Construct] branch;
If we directly dispatched [Construct] command to merlin, we'd be doing
useless computations: we need info whether the expression at the cursor is a
hole, we don't need constructed expressions yet.
Ideally, merlin should return a callback [option], which is [Some] when the
context is applicable. *)
let is_a_hole = function
| (_, Browse_raw.Module_expr { mod_desc = Tmod_typed_hole; _ }) :: (_, _) :: _
| (_, Browse_raw.Expression { exp_desc = Texp_typed_hole; _ }) :: _ -> true
| [] | (_, _) :: _ -> false
;;
15 changes: 15 additions & 0 deletions src/analysis/typed_hole.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(** This module should be used to work with typed holes. The main goal is to
hide syntactic representation of a typed hole, which may change in future *)

(** checks whether the current string matches the syntax representation of a
typed hole *)
val can_be_hole : string -> bool

(** [is_a_hole nodes] checks whether the leaf node [1] is a typed hole
Note: this function is extracted from merlin sources handling [Construct]
command in [merlin/src/frontend/query_commands.ml]
[1] leaf node is the head of the list, as
[Mbrowse.t = (Env.t * Browse_raw.node) list]*)
val is_a_hole : Mbrowse.t -> bool

0 comments on commit 87d4877

Please sign in to comment.