Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport UNIT_NAME and WRAPPING_PREFIX directives #70

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
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
10 changes: 9 additions & 1 deletion src/dot-merlin/dot_merlin_reader.ml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ module Cache = File_cache.Make (struct
includes := String.trim (String.drop 2 line) :: !includes
else if String.is_prefixed ~by:"STDLIB " line then
tell (`STDLIB (String.drop 7 line))
else if String.is_prefixed ~by:"UNIT_NAME " line then
tell (`UNIT_NAME (String.drop 10 line))
else if String.is_prefixed ~by:"WRAPPING_PREFIX " line then
tell (`WRAPPING_PREFIX (String.drop 16 line))
else if String.is_prefixed ~by:"FINDLIB " line then
tell (`FINDLIB (String.drop 8 line))
else if String.is_prefixed ~by:"SUFFIX " line then
Expand Down Expand Up @@ -333,7 +337,11 @@ let prepend_config ~cwd ~cfg =
| `B _ | `S _ | `BH _ | `SH _ | `CMI _ | `CMT _ | `INDEX _ as directive ->
{ cfg with to_canonicalize = (cwd, directive) :: cfg.to_canonicalize }
| `EXT _ | `SUFFIX _ | `FLG _ | `READER _
| (`EXCLUDE_QUERY_DIR | `USE_PPX_CACHE | `UNKNOWN_TAG _) as directive ->
| (`EXCLUDE_QUERY_DIR
| `USE_PPX_CACHE
| `UNIT_NAME _
| `WRAPPING_PREFIX _
| `UNKNOWN_TAG _) as directive ->
{ cfg with pass_forward = directive :: cfg.pass_forward }
| `PKG ps ->
{ cfg with packages_to_load = ps @ cfg.packages_to_load }
Expand Down
6 changes: 6 additions & 0 deletions src/dot-protocol/merlin_dot_protocol.ml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ module Directive = struct
[ `EXT of string list
| `FLG of string list
| `STDLIB of string
| `UNIT_NAME of string
| `WRAPPING_PREFIX of string
| `SUFFIX of string
| `READER of string list
| `EXCLUDE_QUERY_DIR
Expand Down Expand Up @@ -94,6 +96,8 @@ module Sexp = struct
| "CMT" -> `CMT value
| "INDEX" -> `INDEX value
| "STDLIB" -> `STDLIB value
| "UNIT_NAME" -> `UNIT_NAME value
| "WRAPPING_PREFIX" -> `WRAPPING_PREFIX value
| "SUFFIX" -> `SUFFIX value
| "ERROR" -> `ERROR_MSG value
| "FLG" ->
Expand Down Expand Up @@ -126,6 +130,8 @@ module Sexp = struct
| `CMI s -> ("CMI", single s)
| `CMT s -> ("CMT", single s)
| `INDEX s -> ("INDEX", single s)
| `UNIT_NAME s -> ("UNIT_NAME", single s)
| `WRAPPING_PREFIX s -> ("WRAPPING_PREFIX", single s)
| `EXT ss -> ("EXT", [ List (atoms_of_strings ss) ])
| `FLG ss -> ("FLG", [ List (atoms_of_strings ss) ])
| `STDLIB s -> ("STDLIB", single s)
Expand Down
2 changes: 2 additions & 0 deletions src/dot-protocol/merlin_dot_protocol.mli
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ module Directive : sig
[ `EXT of string list
| `FLG of string list
| `STDLIB of string
| `UNIT_NAME of string
| `WRAPPING_PREFIX of string
| `SUFFIX of string
| `READER of string list
| `EXCLUDE_QUERY_DIR
Expand Down
21 changes: 20 additions & 1 deletion src/kernel/mconfig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ type merlin = {
extensions : string list;
suffixes : (string * string) list;
stdlib : string option;
unit_name : string option;
wrapping_prefix : string option;
reader : string list;
protocol : [`Json | `Sexp];
log_file : string option;
Expand Down Expand Up @@ -126,6 +128,8 @@ let dump_merlin x =
]) x.suffixes
);
"stdlib" , Json.option Json.string x.stdlib;
"unit_name" , Json.option Json.string x.unit_name;
"wrapping_prefix" , Json.option Json.string x.wrapping_prefix;
"reader" , `List (List.map ~f:Json.string x.reader);
"protocol" , (match x.protocol with
| `Json -> `String "json"
Expand Down Expand Up @@ -264,6 +268,11 @@ let get_external_config path t =
extensions = dot.extensions @ merlin.extensions;
suffixes = dot.suffixes @ merlin.suffixes;
stdlib = (if dot.stdlib = None then merlin.stdlib else dot.stdlib);
unit_name = (if dot.unit_name = None then merlin.unit_name else dot.unit_name);
wrapping_prefix =
if dot.wrapping_prefix = None
then merlin.wrapping_prefix
else dot.wrapping_prefix;
reader =
if dot.reader = []
then merlin.reader
Expand Down Expand Up @@ -802,6 +811,8 @@ let initial = {
extensions = [];
suffixes = [(".ml", ".mli"); (".re", ".rei")];
stdlib = None;
unit_name = None;
wrapping_prefix = None;
reader = [];
protocol = `Json;
log_file = None;
Expand Down Expand Up @@ -979,4 +990,12 @@ let global_modules ?(include_current=false) config = (

let filename t = t.query.filename

let unitname t = Misc.unitname t.query.filename
let unitname t =
match t.merlin.unit_name with
| Some name -> Misc.unitname name
| None ->
let basename = Misc.unitname t.query.filename in
begin match t.merlin.wrapping_prefix with
| Some prefix -> prefix ^ basename
| None -> basename
end
2 changes: 2 additions & 0 deletions src/kernel/mconfig.mli
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ type merlin = {
extensions : string list;
suffixes : (string * string) list;
stdlib : string option;
unit_name : string option;
wrapping_prefix : string option;
reader : string list;
protocol : [`Json | `Sexp];
log_file : string option;
Expand Down
10 changes: 10 additions & 0 deletions src/kernel/mconfig_dot.ml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ type config = {
extensions : string list;
suffixes : (string * string) list;
stdlib : string option;
unit_name : string option;
wrapping_prefix : string option;
reader : string list;
exclude_query_dir : bool;
use_ppx_cache : bool;
Expand All @@ -61,6 +63,8 @@ let empty_config = {
suffixes = [];
flags = [];
stdlib = None;
unit_name = None;
wrapping_prefix = None;
reader = [];
exclude_query_dir = false;
use_ppx_cache = false;
Expand Down Expand Up @@ -256,6 +260,10 @@ let prepend_config ~dir:cwd configurator (directives : directive list) config =
{config with flags = flags :: config.flags}, errors
| `STDLIB path ->
{config with stdlib = Some path}, errors
| `UNIT_NAME name ->
{config with unit_name = Some name}, errors
| `WRAPPING_PREFIX prefix ->
{config with wrapping_prefix = Some prefix}, errors
| `READER reader ->
{config with reader}, errors
| `EXCLUDE_QUERY_DIR ->
Expand Down Expand Up @@ -287,6 +295,8 @@ let postprocess_config config =
suffixes = clean config.suffixes;
flags = clean config.flags;
stdlib = config.stdlib;
unit_name = config.unit_name;
wrapping_prefix = config.wrapping_prefix;
reader = config.reader;
exclude_query_dir = config.exclude_query_dir;
use_ppx_cache = config.use_ppx_cache;
Expand Down
2 changes: 2 additions & 0 deletions src/kernel/mconfig_dot.mli
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ type config = {
extensions : string list;
suffixes : (string * string) list;
stdlib : string option;
unit_name : string option;
wrapping_prefix : string option;
reader : string list;
exclude_query_dir : bool;
use_ppx_cache : bool;
Expand Down
2 changes: 2 additions & 0 deletions tests/test-dirs/config/dot-merlin-reader/load-config.t
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
}
],
"stdlib": "lib/ocaml",
"unit_name": null,
"wrapping_prefix": null,
"reader": [],
"protocol": "json",
"log_file": null,
Expand Down
2 changes: 2 additions & 0 deletions tests/test-dirs/config/dot-merlin-reader/quoting.t
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
}
],
"stdlib": "lib/ocaml",
"unit_name": null,
"wrapping_prefix": null,
"reader": [],
"protocol": "json",
"log_file": null,
Expand Down
Loading