Skip to content

Commit 70dfb78

Browse files
committed
go back in time to display holes, so name/notation scope is correct
1 parent a599809 commit 70dfb78

File tree

5 files changed

+55
-5
lines changed

5 files changed

+55
-5
lines changed

lib/core/global.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ let add_hole m loc ~vars ~termctx ~ty ~status ~li ~ri =
316316
( cmd.current_holes,
317317
{
318318
meta = Wrap m;
319-
printable = PHole (vars, termctx, ty);
319+
printable = PHole (Origin.current (), vars, termctx, ty);
320320
startpos = s.offset;
321321
endpos = e.offset;
322322
} );

lib/core/printable.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ open Util
22
open Term
33
open Value
44
open Reporter
5+
open Origin
56

67
let phead : head -> printable = function
78
| Const { name; _ } -> PConstant name
@@ -15,5 +16,5 @@ type printable +=
1516
| PNormal : ('a, 'b) Ctx.t * normal -> printable
1617
| (* When printing a hole we use a termctx, since that's what we store anyway, and we would also have to read back a value context anyway in order to unparse it. *)
1718
PHole :
18-
(string option, 'a) Bwv.t * ('a, 'b) termctx * ('b, kinetic) term
19+
Origin.t * (string option, 'a) Bwv.t * ('a, 'b) termctx * ('b, kinetic) term
1920
-> printable

lib/parser/command.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -721,8 +721,8 @@ let parse_single (content : string) : Whitespace.t list * Command.t option =
721721
| _ -> Core.Reporter.fatal (Anomaly "interactive parse doesn't start with Bof")
722722

723723
let show_hole = function
724-
| Global.Found_hole { meta; termctx; ty; vars; _ } ->
725-
emit (Hole (Meta.name meta, PHole (vars, termctx, ty)))
724+
| Global.Found_hole { instant; meta; termctx; ty; vars; _ } ->
725+
emit (Hole (Meta.name meta, PHole (Instant instant, vars, termctx, ty)))
726726

727727
let to_string : Command.t -> string = function
728728
| Axiom _ -> "axiom"

lib/parser/unparse.ml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ open Tbwd
55
open Bwd_extra
66
open Dim
77
open Core
8+
open Origin
89
open Term
910
open Notation
1011
open Builtins
@@ -1019,7 +1020,15 @@ let () =
10191020
`None
10201021
| PConstant name -> utf8string (String.concat "." (Scope.name_of name))
10211022
| PMeta v -> utf8string (Meta.name v)
1022-
| PHole (vars, Permute (p, ctx), ty) ->
1023+
| PHole (origin, vars, Permute (p, ctx), ty) ->
1024+
let run =
1025+
match origin with
1026+
(* If the hole comes from an earlier time, we rewind to that time before displaying, so that the correct notations and names will be in scope. *)
1027+
| Instant instant when origin <> Origin.current () ->
1028+
Origin.rewind_command_then_undo instant
1029+
(* Otherwise, we give up. Normally this would only happen when it's from the current origin (e.g. being created right now in a file) anyway. *)
1030+
| _ -> fun f -> f () in
1031+
run @@ fun () ->
10231032
let vars, names = Names.uniquify_vars vars in
10241033
let names, ctx = unparse_ctx names `Unlocked (Bwv.permute vars p) ctx in
10251034
let ty = unparse names ty No.Interval.entire No.Interval.entire in

test/black/hole_in_section.t

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
$ narya -fake-interact "section foo ≔ def A : Type ≔ sig () def B : A ≔ ? def C : A ≔ ? end show hole 0 show hole 1"
2+
→ info[I0007]
3+
○ section foo opened
4+
5+
→ info[I0000]
6+
constant A defined
7+
8+
→ info[I0000]
9+
constant B defined, containing 1 hole
10+
11+
→ info[I3003]
12+
○ hole ?0:
13+
14+
----------------------------------------------------------------------
15+
A
16+
17+
→ info[I0000]
18+
constant C defined, containing 1 hole
19+
20+
→ info[I3003]
21+
○ hole ?1:
22+
23+
----------------------------------------------------------------------
24+
A
25+
26+
→ info[I0008]
27+
○ section foo closed
28+
29+
→ info[I3003]
30+
○ hole ?0:
31+
32+
----------------------------------------------------------------------
33+
A
34+
35+
→ info[I3003]
36+
○ hole ?1:
37+
38+
----------------------------------------------------------------------
39+
A
40+

0 commit comments

Comments
 (0)