Skip to content

Commit 87d4877

Browse files
committed
Move typed_hole from ocaml-lsp
1 parent 9f0a6b5 commit 87d4877

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/analysis/typed_hole.ml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
let syntax_repr = "_"
2+
let can_be_hole s = String.equal syntax_repr s
3+
4+
(* the pattern matching below is taken and modified (minimally, to adapt the
5+
return type) from [Query_commands.dispatch]'s [Construct] branch;
6+
7+
If we directly dispatched [Construct] command to merlin, we'd be doing
8+
useless computations: we need info whether the expression at the cursor is a
9+
hole, we don't need constructed expressions yet.
10+
11+
Ideally, merlin should return a callback [option], which is [Some] when the
12+
context is applicable. *)
13+
let is_a_hole = function
14+
| (_, Browse_raw.Module_expr { mod_desc = Tmod_typed_hole; _ }) :: (_, _) :: _
15+
| (_, Browse_raw.Expression { exp_desc = Texp_typed_hole; _ }) :: _ -> true
16+
| [] | (_, _) :: _ -> false
17+
;;

src/analysis/typed_hole.mli

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
(** This module should be used to work with typed holes. The main goal is to
2+
hide syntactic representation of a typed hole, which may change in future *)
3+
4+
(** checks whether the current string matches the syntax representation of a
5+
typed hole *)
6+
val can_be_hole : string -> bool
7+
8+
(** [is_a_hole nodes] checks whether the leaf node [1] is a typed hole
9+
10+
Note: this function is extracted from merlin sources handling [Construct]
11+
command in [merlin/src/frontend/query_commands.ml]
12+
13+
[1] leaf node is the head of the list, as
14+
[Mbrowse.t = (Env.t * Browse_raw.node) list]*)
15+
val is_a_hole : Mbrowse.t -> bool

0 commit comments

Comments
 (0)