Skip to content

Commit

Permalink
Add ability to specify listings target in build tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
nberth committed Aug 7, 2024
1 parent 638153f commit a61eeeb
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 20 deletions.
12 changes: 10 additions & 2 deletions package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions src/lsp/superbol_free_lib/vscode_extension.ml
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,16 @@ let contributes =

Manifest.PROPERTY.null_string "cobc-path"
~title:"GnuCOBOL Compiler Executable"
~description:"Path to the GnuCOBOL compiler executable; when `null`, \
defaults to the value of \"superbol.cobc-path\" from \
the workspace configuration, if defined, to \"cobc\" \
otherwise.";
~markdownDescription:
"Path to the GnuCOBOL compiler executable; when `null`, defaults \
to the value of \"superbol.cobc-path\" from the workspace \
configuration, if defined, to \"cobc\" otherwise.";

Manifest.PROPERTY.null_string "listings-target"
~title:"Output file or directory for preprocessed program listings"
~markdownDescription:
"Path to a directory where preprocessed program listings are \
generated; no listing is saved when `null`";

Manifest.PROPERTY.array "extra-args"
~description:"Additional arguments passed to `cobc`";
Expand Down
36 changes: 22 additions & 14 deletions src/vscode/superbol-vscode-platform/superbol_tasks.ml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ let attributes_spec ~debug ~coverage ~executable =
[%js.of: bool], executable);
"cobc-path", C ([%js.to: string or_undefined],
[%js.of: string], "cobc");
"listings-target", C ([%js.to: string option or_undefined],
[%js.of: string option], None);
"extra-args", C ([%js.to: string list or_undefined],
[%js.of: string list], []);
]
Expand All @@ -47,13 +49,8 @@ let attr_bool_flag key ~ok ?(ko = Fun.id) ~attributes args =
| None when Superbol_workspace.bool key -> ok args
| _ -> ko args

let string_arg ?(allow_empty = false) ~mk s args =
if s = "" && not allow_empty then args else mk s :: args

(* let attr_string ?allow_empty key ~mk ~attributes args = *)
(* match List.assoc_opt key attributes with *)
(* | Some s -> string_arg ([%js.to: string] s) ?allow_empty ~mk args *)
(* | None -> args *)
let string_arg ?(allow_empty = false) ~append s args =
if s = "" && not allow_empty then args else append s args

let config_string key ~config =
string_arg @@
Expand All @@ -66,11 +63,18 @@ let config_strings key ~config ~append =
with Not_found -> Superbol_workspace.strings key
| Jsonoo.Decode_error _ -> [] (* Warning: silenced decode errors for now *)

let attr_strings key ~append ~attributes args =
let attr_strings key ?(append = List.append) ~attributes args =
match List.assoc_opt key attributes with
| Some l -> append ([%js.to: string list] l) args
| None -> args

let attr_string_opt key ~append ~attributes args =
match List.assoc_opt key attributes with
| None -> args
| Some s -> match [%js.to: string option] s with
| None -> args
| Some s -> string_arg s ~allow_empty:false ~append args

(* let config_strings key ~config:_ ~append args = *)
(* append (Superbol_workspace.string_list key) args *)

Expand Down Expand Up @@ -119,22 +123,26 @@ let cobc_execution ?config attributes =
List.append args
end |>
config_strings "cobol.copyexts" ~config
~append:begin fun exts args ->
List.append args @@ List.flatten @@ List.map (fun e -> ["-ext"; e]) exts
~append:begin fun exts ->
List.append @@ List.flatten @@ List.map (fun e -> ["-ext"; e]) exts
end |>
config_string "cobol.dialect" ~config
~mk:(function "gnucobol" -> "-std=default" | s -> "-std=" ^ s) |>
~append:begin function
| "gnucobol" -> List.cons "-std=default"
| s -> List.cons ("-std=" ^ s)
end|>
config_string "cobol.source-format" ~config
~mk:((^) "-fformat=") |>
~append:(fun f -> List.cons ("-fformat=" ^ f)) |>
attr_bool_flag "for-debug" ~attributes
~ok:(fun args -> "-fsource-location" :: "-ftraceall" :: "-g" :: args) |>
~ok:(List.append ["-fsource-location"; "-ftraceall"; "-g"]) |>
attr_bool_flag "for-coverage" ~attributes
~ok:(List.cons "--coverage") |>
attr_bool_flag "executable" ~attributes
~ok:(List.cons "-x")
~ko:(List.cons "-m") |>
attr_string_opt "listings-target" ~attributes
~append:(fun t -> List.append ["-P"; t]) |>
attr_strings "extra-args" ~attributes
~append:(fun args' args -> args @ args')
in
`ShellExecution (ShellExecution.makeCommandArgs ()
~command:(`String cobc)
Expand Down

0 comments on commit a61eeeb

Please sign in to comment.