Skip to content

Commit 2b9cd21

Browse files
authored
Merge pull request #1866 from voodoos/414-4.18-backports
Backports for release 4.18-414
2 parents 44c1124 + ee816ec commit 2b9cd21

File tree

30 files changed

+958
-159
lines changed

30 files changed

+958
-159
lines changed

.github/workflows/changelog.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Changelog check
22

33
on:
44
pull_request:
5-
branches: [ master ]
5+
branches: [ main ]
66
types: [ opened, synchronize, reopened, labeled, unlabeled ]
77

88
jobs:

CHANGES.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
merlin 4.18
2+
===========
3+
Tue Nov 26 17:30:42 CET 2024
4+
5+
+ merlin binary
6+
- Respect the `EXCLUDE_QUERY_DIR` configuration directive when looking for
7+
cmt files (#1854)
8+
- Fix exception in polarity search (#1858 fixes #1113)
9+
- Fix type-enclosing results instability. This reverts some overly
10+
aggressive deduplication that should be done on the client side. (#1864)
11+
12+
113
merlin 4.17.1
214
=============
315
Fri Sep 27 12:02:42 CEST 2024

dot-merlin-reader.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ build: [
1212
]
1313
depends: [
1414
"ocaml" {>= "4.14"}
15-
"dune" {>= "2.9.0"}
15+
"dune" {>= "3.0.0"}
1616
"merlin-lib" {>= "4.17"}
1717
"ocamlfind" {>= "1.6.0"}
1818
]

merlin-lib.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ depends: [
1313
"ocaml" {>= "4.14" & < "4.15"}
1414
"dune" {>= "2.9.0"}
1515
"csexp" {>= "1.5.1"}
16-
"alcotest" {with-test}
16+
"alcotest" {with-test & >= "1.3.0" }
1717
"menhir" {dev & >= "20201216"}
1818
"menhirLib" {dev & >= "20201216"}
1919
"menhirSdk" {dev & >= "20201216"}

merlin.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ depends: [
1414
"ocaml" {>= "4.14" & < "4.15"}
1515
"dune" {>= "2.9.0"}
1616
"merlin-lib" {= version}
17-
"dot-merlin-reader" {>= "4.17"}
17+
"dot-merlin-reader" {>= "4.17.1"}
1818
"yojson" {>= "2.0.0"}
1919
"conf-jq" {with-test}
2020
"ppxlib" {with-test}

src/analysis/misc_utils.ml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,55 @@ let parse_identifier (config, source) pos =
5959
"paths: [%s]"
6060
(String.concat ~sep:";" (List.map path ~f:(fun l -> l.Location.txt)));
6161
path
62+
63+
let reconstruct_identifier pipeline pos = function
64+
| None ->
65+
let config = Mpipeline.input_config pipeline in
66+
let source = Mpipeline.raw_source pipeline in
67+
let path = parse_identifier (config, source) pos in
68+
let reify dot =
69+
if
70+
dot = ""
71+
|| (dot.[0] >= 'a' && dot.[0] <= 'z')
72+
|| (dot.[0] >= 'A' && dot.[0] <= 'Z')
73+
then dot
74+
else "( " ^ dot ^ ")"
75+
in
76+
begin
77+
match path with
78+
| [] -> []
79+
| base :: tail ->
80+
let f { Location.txt = base; loc = bl } { Location.txt = dot; loc = dl }
81+
=
82+
let loc = Location_aux.union bl dl in
83+
let txt = base ^ "." ^ reify dot in
84+
Location.mkloc txt loc
85+
in
86+
[ List.fold_left tail ~init:base ~f ]
87+
end
88+
| Some (expr, offset) ->
89+
let loc_start =
90+
let l, c = Lexing.split_pos pos in
91+
Lexing.make_pos (l, c - offset)
92+
in
93+
let shift loc int =
94+
let l, c = Lexing.split_pos loc in
95+
Lexing.make_pos (l, c + int)
96+
in
97+
let add_loc source =
98+
let loc =
99+
{ Location.loc_start;
100+
loc_end = shift loc_start (String.length source);
101+
loc_ghost = false
102+
}
103+
in
104+
Location.mkloc source loc
105+
in
106+
let len = String.length expr in
107+
let rec aux acc i =
108+
if i >= len then List.rev_map ~f:add_loc (expr :: acc)
109+
else if expr.[i] = '.' then
110+
aux (String.sub expr ~pos:0 ~len:i :: acc) (succ i)
111+
else aux acc (succ i)
112+
in
113+
aux [] offset

src/analysis/misc_utils.mli

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,11 @@ val parenthesize_name : string -> string
2929
the location of each of its components. *)
3030
val parse_identifier :
3131
Mconfig.t * Msource.t -> Lexing.position -> string Location.loc list
32+
33+
(** [reconstruct_identifier pipeline pos] returns growing ranges around [pos] and the
34+
associated identifier. *)
35+
val reconstruct_identifier :
36+
Mpipeline.t ->
37+
Lexing.position ->
38+
(string * int) option ->
39+
string Location.loc list

src/analysis/polarity_search.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ let build_query ~positive ~negative env =
6868
incr r;
6969
None)
7070
else
71-
let set, _ = Env.find_type_by_name l env in
72-
Some (normalize_path env set)
71+
try
72+
let set, _ = Env.find_type_by_name l env in
73+
Some (normalize_path env set)
74+
with Not_found -> None
7375
in
7476
let pos_fun = ref 0 and neg_fun = ref 0 in
7577
let positive = List.filter_map positive ~f:(prepare pos_fun) in

src/analysis/type_enclosing.ml

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
open Std
2+
open Type_utils
23

34
let log_section = "type-enclosing"
45
let { Logger.log } = Logger.for_section log_section
@@ -7,11 +8,34 @@ type type_info =
78
| Modtype of Env.t * Types.module_type
89
| Type of Env.t * Types.type_expr
910
| Type_decl of Env.t * Ident.t * Types.type_declaration
11+
| Type_constr of Env.t * Types.constructor_description
1012
| String of string
1113

1214
type typed_enclosings =
1315
(Location.t * type_info * Query_protocol.is_tail_position) list
1416

17+
let print_type ~verbosity type_info =
18+
let ppf = Format.str_formatter in
19+
let wrap_printing_env = Printtyp.wrap_printing_env ~verbosity in
20+
match type_info with
21+
| Type (env, t) ->
22+
wrap_printing_env env (fun () ->
23+
print_type_with_decl ~verbosity env ppf t;
24+
Format.flush_str_formatter ())
25+
| Type_decl (env, id, t) ->
26+
wrap_printing_env env (fun () ->
27+
Printtyp.type_declaration env id ppf t;
28+
Format.flush_str_formatter ())
29+
| Type_constr (env, cd) ->
30+
wrap_printing_env env (fun () ->
31+
print_constr ~verbosity env ppf cd;
32+
Format.flush_str_formatter ())
33+
| Modtype (env, m) ->
34+
wrap_printing_env env (fun () ->
35+
Printtyp.modtype env ppf m;
36+
Format.flush_str_formatter ())
37+
| String s -> s
38+
1539
let from_nodes ~path =
1640
let aux (env, node, tail) =
1741
let open Browse_raw in
@@ -89,14 +113,10 @@ let from_reconstructed ~nodes ~cursor ~verbosity exprs =
89113
(* Retrieve the type from the AST when it is possible *)
90114
| Some (Context.Constructor (cd, loc)) ->
91115
log ~title:"from_reconstructed" "ctx: constructor %s" cd.cstr_name;
92-
let ppf, to_string = Format.to_string () in
93-
Type_utils.print_constr ~verbosity env ppf cd;
94-
Some (loc, String (to_string ()), `No)
116+
Some (loc, Type_constr (env, cd), `No)
95117
| Some (Context.Label { lbl_name; lbl_arg; _ }) ->
96118
log ~title:"from_reconstructed" "ctx: label %s" lbl_name;
97-
let ppf, to_string = Format.to_string () in
98-
Type_utils.print_type_with_decl ~verbosity env ppf lbl_arg;
99-
Some (loc, String (to_string ()), `No)
119+
Some (loc, Type (env, lbl_arg), `No)
100120
| Some Context.Constant -> None
101121
| _ -> (
102122
let context = Option.value ~default:Context.Expr context in

src/analysis/type_enclosing.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,14 @@ type type_info =
3838
| Modtype of Env.t * Types.module_type
3939
| Type of Env.t * Types.type_expr
4040
| Type_decl of Env.t * Ident.t * Types.type_declaration
41+
| Type_constr of Env.t * Types.constructor_description
4142
| String of string
4243

4344
type typed_enclosings =
4445
(Location.t * type_info * Query_protocol.is_tail_position) list
4546

47+
val print_type : verbosity:Mconfig.Verbosity.t -> type_info -> string
48+
4649
val from_nodes :
4750
path:(Env.t * Browse_raw.node * Query_protocol.is_tail_position) list ->
4851
typed_enclosings

0 commit comments

Comments
 (0)