Skip to content
Merged
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
25 changes: 17 additions & 8 deletions src/config/options.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,21 @@ let rec element_paths (element: element): string list =
| String _
| Boolean
| Integer _
| Number _
| Monomorphic_array _ ->
| Number _ ->
[""]
| Monomorphic_array _ ->
[""; "[+]"; "[-]"; "[*]"]
| Object object_specs ->
List.concat_map (fun (name, field_element, _, _) ->
List.map (fun path -> name ^ "." ^ path) (element_paths field_element)
List.map (fun path -> "." ^ name ^ path) (element_paths field_element)
) object_specs.properties
| _ ->
Logs.Format.error "%a" Json_schema.pp (create element);
failwith "element_paths"

let schema_paths (schema: schema): string list =
element_paths (root schema)
|> List.map BatString.rchop (* remove trailing '.' *)
|> List.map BatString.lchop (* remove first '.' *)

let paths = schema_paths schema

Expand All @@ -48,9 +49,17 @@ let rec element_completions (element: element): (string * string list) list =
in
match element.kind with
| Integer _
| Number _
| Monomorphic_array _ ->
| Number _ ->
default_completion ()
| Monomorphic_array (array_element, array_specs) ->
let array_element_completions =
element_completions array_element
|> List.concat_map (fun (path, cs) ->
assert (path = ""); (* Arrays of objects/arrays not supported. Currently we only have arrays of strings.*)
[("[+]", cs); ("[-]", cs); ("[*]", cs)]
)
in
default_completion () @ array_element_completions
| Boolean ->
[("", ["false"; "true"])]
| String string_specs ->
Expand All @@ -68,15 +77,15 @@ let rec element_completions (element: element): (string * string list) list =
end
| Object object_specs ->
List.concat_map (fun (name, field_element, _, _) ->
List.map (fun (path, cs) -> (name ^ "." ^ path, cs)) (element_completions field_element)
List.map (fun (path, cs) -> ("." ^ name ^ path, cs)) (element_completions field_element)
) object_specs.properties
| _ ->
Logs.Format.error "%a" Json_schema.pp (create element);
failwith "element_completions"

let schema_completions (schema: schema): (string * string list) list =
element_completions (root schema)
|> List.map (BatTuple.Tuple2.map1 BatString.rchop) (* remove trailing '.' *)
|> List.map (BatTuple.Tuple2.map1 BatString.lchop) (* remove first '.' *)

let completions = schema_completions schema

Expand Down
Loading