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

4.17 414 backport #1837

Merged
merged 24 commits into from
Sep 26, 2024
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3b91b41
[B] SOURCE_ROOT, UNIT_NAME and WRAPPING_PREFIX
voodoos Sep 25, 2024
b52d18d
[B] #1795: Fix #1794: Add `-unboxed-types` and `-no-unboxed-types` to…
voodoos Sep 25, 2024
c02a023
[B] #1804 vim: remove references to MerlinPhrase
voodoos Sep 25, 2024
140bb29
[B] #1806 Ignore new Menhir deprecations
voodoos Sep 25, 2024
d0b018d
[B] #1800 Refinement in the presence of optional arguments
voodoos Sep 25, 2024
1f57d7f
[B] #1807 Check always that default args are option
voodoos Sep 25, 2024
463eb71
[B] #1803 Fix ignorance of STDLIB in .merlin
voodoos Sep 25, 2024
2b01e1f
[B] #1745 Expand PPX nodes
voodoos Sep 25, 2024
e1ef844
[B] #1810 Produce a better error message when a flag spec appears mul…
voodoos Sep 25, 2024
d7968d6
[B] #1812 Inlay hint upstreaming
voodoos Sep 25, 2024
3b7f685
[B] #1814 Some UI improvement for `emacs/merlin-search`
voodoos Sep 25, 2024
198d6f5
[B] #1811 Exposes some helper for reducing direct typedtree usage in Lsp
voodoos Sep 25, 2024
db0b37e
[B] #1720 Signature Help
voodoos Sep 25, 2024
681c3c8
Compat with new occurrences api
voodoos Sep 25, 2024
83efbfa
Setup codebase formatting and fix a few comments.
voodoos Sep 25, 2024
e6786db
Format the codebase
voodoos Sep 25, 2024
c6fb925
Add commit to ignored revs
voodoos Sep 25, 2024
19e7220
[B] #1828 Search by type feature, a kind of sherlodoc in Merlin
voodoos Sep 25, 2024
c83e2e3
Promote fixed test after Dune upgrade
voodoos Sep 25, 2024
dc5e372
Silence ld warnings in tests
voodoos Sep 25, 2024
c04d859
Enable github CI
voodoos Sep 25, 2024
b82b038
[B] #1839 Fix ignorance of SOURCE_ROOT directive
voodoos Sep 25, 2024
98616bd
Make deps explicit
patrick-nicodemus Sep 25, 2024
315ccfa
[B] #1841 Document missing commands in PROTOCOL.md
voodoos Sep 26, 2024
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
Next Next commit
[B] SOURCE_ROOT, UNIT_NAME and WRAPPING_PREFIX
voodoos committed Sep 25, 2024
commit 3b91b41d81f3928e3b57bd6803abc3cd97fe0d8f
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
unreleased
==========

+ merlin binary
- A new `WRAPPING_PREFIX` configuration directive that can be used to tell Merlin
what to append to the current unit name in the presence of wrapping (#1788)
+ editor modes
- vim: fix python-3.12 syntax warnings in merlin.py (#1798)

17 changes: 16 additions & 1 deletion src/dot-merlin/dot_merlin_reader.ml
Original file line number Diff line number Diff line change
@@ -92,6 +92,12 @@ 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:"SOURCE_ROOT " line then
tell (`SOURCE_ROOT (String.drop 12 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
@@ -305,6 +311,7 @@ type config = {
pass_forward : Merlin_dot_protocol.Directive.no_processing_required list;
to_canonicalize : (string * Merlin_dot_protocol.Directive.include_path) list;
stdlib : string option;
source_root : string option;
packages_to_load : string list;
findlib : string option;
findlib_path : string list;
@@ -315,6 +322,7 @@ let empty_config = {
pass_forward = [];
to_canonicalize = [];
stdlib = None;
source_root = None;
packages_to_load = [];
findlib = None;
findlib_path = [];
@@ -327,7 +335,11 @@ let prepend_config ~cwd ~cfg =
| `B _ | `S _ | `CMI _ | `CMT _ 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 }
@@ -339,6 +351,9 @@ let prepend_config ~cwd ~cfg =
log ~title:"conflicting paths for stdlib" "%s\n%s" p canon_path
end;
{ cfg with stdlib = Some canon_path }
| `SOURCE_ROOT path ->
let canon_path = canonicalize_filename ~cwd path in
{ cfg with source_root = Some canon_path }
| `FINDLIB path ->
let canon_path = canonicalize_filename ~cwd path in
begin match cfg.stdlib with
10 changes: 10 additions & 0 deletions src/dot-protocol/merlin_dot_protocol.ml
Original file line number Diff line number Diff line change
@@ -37,6 +37,9 @@ module Directive = struct
[ `EXT of string list
| `FLG of string list
| `STDLIB of string
| `SOURCE_ROOT of string
| `UNIT_NAME of string
| `WRAPPING_PREFIX of string
| `SUFFIX of string
| `READER of string list
| `EXCLUDE_QUERY_DIR
@@ -85,6 +88,9 @@ module Sexp = struct
| "CMI" -> `CMI value
| "CMT" -> `CMT value
| "STDLIB" -> `STDLIB value
| "SOURCE_ROOT" -> `SOURCE_ROOT value
| "UNIT_NAME" -> `UNIT_NAME value
| "WRAPPING_PREFIX" -> `WRAPPING_PREFIX value
| "SUFFIX" -> `SUFFIX value
| "ERROR" -> `ERROR_MSG value
| "FLG" ->
@@ -114,6 +120,10 @@ module Sexp = struct
| `S s -> ("S", single s)
| `CMI s -> ("CMI", single s)
| `CMT s -> ("CMT", single s)
| `INDEX s -> ("INDEX", single s)
| `SOURCE_ROOT s -> ("SOURCE_ROOT", 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)
3 changes: 3 additions & 0 deletions src/dot-protocol/merlin_dot_protocol.mli
Original file line number Diff line number Diff line change
@@ -49,6 +49,9 @@ module Directive : sig
[ `EXT of string list
| `FLG of string list
| `STDLIB of string
| `SOURCE_ROOT of string
| `UNIT_NAME of string
| `WRAPPING_PREFIX of string
| `SUFFIX of string
| `READER of string list
| `EXCLUDE_QUERY_DIR
27 changes: 26 additions & 1 deletion src/kernel/mconfig.ml
Original file line number Diff line number Diff line change
@@ -77,6 +77,9 @@ type merlin = {
extensions : string list;
suffixes : (string * string) list;
stdlib : string option;
source_root : string option;
unit_name : string option;
wrapping_prefix : string option;
reader : string list;
protocol : [`Json | `Sexp];
log_file : string option;
@@ -115,6 +118,9 @@ let dump_merlin x =
]) x.suffixes
);
"stdlib" , Json.option Json.string x.stdlib;
"source_root" , Json.option Json.string x.source_root;
"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"
@@ -243,6 +249,14 @@ let merge_merlin_config dot merlin ~failures ~config_path =
extensions = dot.extensions @ merlin.extensions;
suffixes = dot.suffixes @ merlin.suffixes;
stdlib = (if dot.stdlib = None then merlin.stdlib else dot.stdlib);
source_root =
(if dot.source_root = None then merlin.source_root else dot.source_root);
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
@@ -624,6 +638,9 @@ let initial = {
extensions = [];
suffixes = [(".ml", ".mli"); (".re", ".rei")];
stdlib = None;
source_root = None;
unit_name = None;
wrapping_prefix = None;
reader = [];
protocol = `Json;
log_file = None;
@@ -796,4 +813,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
5 changes: 4 additions & 1 deletion src/kernel/mconfig.mli
Original file line number Diff line number Diff line change
@@ -35,6 +35,9 @@ type merlin = {
extensions : string list;
suffixes : (string * string) list;
stdlib : string option;
source_root : string option;
unit_name : string option;
wrapping_prefix : string option;
reader : string list;
protocol : [`Json | `Sexp];
log_file : string option;
@@ -57,7 +60,7 @@ val dump_merlin : merlin -> json

(** {1 Some flags affecting queries} *)

module Verbosity : sig
module Verbosity : sig
type t = Smart | Lvl of int

(** the default value for verbosity, i.e., [Lvl 0] *)
15 changes: 15 additions & 0 deletions src/kernel/mconfig_dot.ml
Original file line number Diff line number Diff line change
@@ -41,6 +41,9 @@ type config = {
extensions : string list;
suffixes : (string * string) list;
stdlib : string option;
source_root : string option;
unit_name : string option;
wrapping_prefix : string option;
reader : string list;
exclude_query_dir : bool;
use_ppx_cache : bool;
@@ -55,6 +58,9 @@ let empty_config = {
suffixes = [];
flags = [];
stdlib = None;
source_root = None;
unit_name = None;
wrapping_prefix = None;
reader = [];
exclude_query_dir = false;
use_ppx_cache = false;
@@ -246,6 +252,12 @@ 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
| `SOURCE_ROOT path ->
{config with source_root = 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 ->
@@ -274,6 +286,9 @@ let postprocess_config config =
suffixes = clean config.suffixes;
flags = clean config.flags;
stdlib = config.stdlib;
source_root = config.source_root;
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;
3 changes: 3 additions & 0 deletions src/kernel/mconfig_dot.mli
Original file line number Diff line number Diff line change
@@ -43,6 +43,9 @@ type config = {
extensions : string list;
suffixes : (string * string) list;
stdlib : string option;
source_root : string option;
unit_name : string option;
wrapping_prefix : string option;
reader : string list;
exclude_query_dir : bool;
use_ppx_cache : bool;
63 changes: 63 additions & 0 deletions tests/test-dirs/config/dot-merlin-reader/load-config.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
This test comes from: https://github.com/janestreet/merlin-jst/pull/59

$ cat > .merlin <<EOF
> B build/dir
> S source/dir
> BH build-hidden/dir
> SH source-hidden/dir
> EOF

$ FILE=$(pwd)/test.ml; dot-merlin-reader <<EOF | sed 's#[0-9]*:#?:#g'
> (4:File${#FILE}:$FILE)
> EOF
((?:B?:$TESTCASE_ROOT/build/dir)(?:S?:$TESTCASE_ROOT/source/dir)(?:ERROR?:Unknown tag in .merlin?: BH)(?:ERROR?:Unknown tag in .merlin?: SH))

$ echo | $MERLIN single dump-configuration -filename test.ml 2> /dev/null | jq '.value.merlin'
{
"build_path": [
"$TESTCASE_ROOT/build/dir"
],
"source_path": [
"$TESTCASE_ROOT/source/dir"
],
"cmi_path": [],
"cmt_path": [],
"flags_applied": [],
"extensions": [],
"suffixes": [
{
"impl": ".ml",
"intf": ".mli"
},
{
"impl": ".re",
"intf": ".rei"
}
],
"stdlib": null,
"source_root": null,
"unit_name": null,
"wrapping_prefix": null,
"reader": [],
"protocol": "json",
"log_file": null,
"log_sections": [],
"flags_to_apply": [],
"failures": [
"Unknown tag in .merlin: SH",
"Unknown tag in .merlin: BH"
],
"assoc_suffixes": [
{
"extension": ".re",
"reader": "reason"
},
{
"extension": ".rei",
"reader": "reason"
}
],
"cache_lifespan": "5"
}

$ rm .merlin
3 changes: 3 additions & 0 deletions tests/test-dirs/config/dot-merlin-reader/quoting.t
Original file line number Diff line number Diff line change
@@ -51,6 +51,9 @@
}
],
"stdlib": null,
"source_root": null,
"unit_name": null,
"wrapping_prefix": null,
"reader": [],
"protocol": "json",
"log_file": null,