55672
|
1 |
(* Title: Pure/Isar/completion.ML
|
|
2 |
Author: Makarius
|
|
3 |
|
55674
|
4 |
Semantic completion within the formal context.
|
55672
|
5 |
*)
|
|
6 |
|
|
7 |
signature COMPLETION =
|
|
8 |
sig
|
55687
|
9 |
type T
|
|
10 |
val make: Position.T -> string list -> T
|
55672
|
11 |
val none: T
|
55687
|
12 |
val report: T -> unit
|
55672
|
13 |
end;
|
|
14 |
|
|
15 |
structure Completion: COMPLETION =
|
|
16 |
struct
|
|
17 |
|
55687
|
18 |
abstype T = Completion of {pos: Position.T, total: int, names: string list}
|
|
19 |
with
|
55672
|
20 |
|
55687
|
21 |
fun dest (Completion args) = args;
|
55672
|
22 |
|
55687
|
23 |
fun make pos names =
|
|
24 |
Completion
|
|
25 |
{pos = pos,
|
|
26 |
total = length names,
|
|
27 |
names = take (Options.default_int "completion_limit") names};
|
55672
|
28 |
|
|
29 |
end;
|
55687
|
30 |
|
|
31 |
val none = make Position.none [];
|
|
32 |
|
|
33 |
fun report completion =
|
|
34 |
let val {pos, total, names} = dest completion in
|
|
35 |
if Position.is_reported pos andalso not (null names) then
|
|
36 |
let
|
|
37 |
val props =
|
|
38 |
(Markup.totalN, Markup.print_int total) ::
|
|
39 |
(map Markup.print_int (1 upto length names) ~~ names);
|
|
40 |
val markup = (Markup.completionN, Position.properties_of pos @ props);
|
|
41 |
in Output.report (Markup.markup markup "") end
|
|
42 |
else ()
|
|
43 |
end;
|
|
44 |
|
|
45 |
end;
|