Skip to content

Commit 6b3214d

Browse files
authored
Merge branch 'main' into sig_help_looping_parameter
2 parents 04c31f9 + 468e4b8 commit 6b3214d

File tree

216 files changed

+14511
-9892
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

216 files changed

+14511
-9892
lines changed

.github/workflows/flambda-backend.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ jobs:
7272
if: steps.cache.outputs.cache-hit != 'true'
7373
working-directory: flambda-backend
7474
run: |
75-
opam switch create 4.14.0 --yes
76-
opam switch link 4.14.0 --yes
77-
opam install --yes dune.3.19.1 menhir.20231231
75+
opam switch create 5.4.0 --yes
76+
opam switch link 5.4.0 --yes
77+
opam install --yes dune.3.20.2 menhir.20231231
7878
7979
- name: Configure, build, and install flambda-backend
8080
if: steps.cache.outputs.cache-hit != 'true'

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ unreleased
1010
- Add initial support for project-wide renaming: occurrences can now return
1111
all usages of all related definitions. (#1877)
1212
- Fix issues with ident validation and Lid comparison for occurrences (#1924)
13+
- Fix record field autocompletion (https://github.com/ocaml/merlin/pull/2028)
1314
+ ocaml-index
1415
- Bump magic number after index file format change. Index can now be read lazilly (#1886)
1516

doc/dev/PROTOCOL.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,54 @@ The type is described in another file, and the result will be the following obje
544544
}
545545
```
546546

547+
### `locate-types -position <position>`
548+
549+
-position <position> The position of the type to be located
550+
551+
Checks the type of the item at the given position. Unlike `locate-type`, if the type is
552+
expressed via multiple paths (ex: the type is `int list` or `(int foo * string) -> unit`),
553+
it will return a tree that represents the type. Each entry in the tree will contains the
554+
definition location of that type.
555+
556+
The below schema defines the response object (where `response` is the type of the object
557+
returned):
558+
```javascript
559+
response = tree | "Invalid context"
560+
561+
tree = {
562+
"data": node_data,
563+
"children": [tree]
564+
}
565+
566+
node_data =
567+
| [ "Arrow" ]
568+
| [ "Tuple" ]
569+
| [ "Object" ]
570+
| [ "Poly_variant" ]
571+
| [ "Type_ref", { "type": string, "result": [ "Found", file, position ] } ]
572+
573+
file = string
574+
575+
position = {
576+
"pos_fname": string,
577+
"pos_lnum": int,
578+
"pos_bol": int,
579+
"pos_cnum": int
580+
}
581+
```
582+
583+
The type is described in another file, and the result will be the following object:
584+
585+
```javascript
586+
{
587+
'file': string, // the file where the type is defined
588+
'pos': {
589+
'start': position, // the start of the region where the type is defined
590+
'end': position // the end of the region where the type is defined
591+
}
592+
}
593+
```
594+
547595
### `signature-help -position <position>`
548596

549597
-position <position> The position where to request additional information for signature help

src/analysis/completion.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ let classify_node = function
136136
| Open_declaration _ -> `Module
137137
| Include_declaration _ -> `Module
138138
| Include_description _ -> `Module
139-
| Mode _ | Modality _ ->
139+
| Mode _ | Modality _ | Mod_bound _ ->
140140
(* CR-someday: Have proper completion for modes and modalities *)
141141
`Expression
142142
| Jkind_annotation _ ->

src/analysis/construct.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,11 @@ module Gen = struct
223223
| Mty_signature sig_items ->
224224
let env = Env.add_signature sig_items env in
225225
Mod.structure @@ structure env sig_items
226-
| Mty_functor (param, out) ->
226+
| Mty_functor (param, out, _) ->
227227
let param =
228228
match param with
229229
| Unit -> Parsetree.Unit
230-
| Named (id, in_) ->
230+
| Named (id, in_, _) ->
231231
Parsetree.Named
232232
( Location.mknoloc (Option.map ~f:Ident.name id),
233233
Ptyp_of_type.module_type in_,
@@ -524,7 +524,7 @@ module Gen = struct
524524
val_loc = Location.none;
525525
val_attributes = [];
526526
val_zero_alloc = Zero_alloc.default;
527-
val_modalities = Mode.Modality.id;
527+
val_modalities = Mode.Modality.(of_const Const.id);
528528
val_uid = Uid.mk ~current_unit:(Env.get_unit_name ())
529529
}
530530
in

src/analysis/context.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ let inspect_expression ~cursor ~lid e : t =
122122
Constructor (cd, lid_loc.loc)
123123
else Module_path
124124
else Module_path
125-
| Texp_ident (p, lid_loc, _, _, _) ->
125+
| Texp_ident (p, lid_loc, _, _, _, _) ->
126126
let name = Path.last p in
127127
log ~title:"inspect_context" "name is: [%s]" name;
128128
if name = "*type-error*" then

src/analysis/destruct.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ let rec get_every_pattern loc = function
308308
(* We are still in the same branch, going up. *)
309309
get_every_pattern loc parents
310310
| Expression
311-
{ exp_desc = Typedtree.Texp_ident (Path.Pident id, _, _, _, _); _ }
311+
{ exp_desc = Typedtree.Texp_ident (Path.Pident id, _, _, _, _, _); _ }
312312
when Ident.name id = "*type-error*" -> raise Ill_typed
313313
| Expression { exp_desc = Typedtree.Texp_function { params; _ }; _ } ->
314314
begin

src/analysis/inlay_hints.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ let pattern_has_constraint (type a) (pattern : a Typedtree.general_pattern) =
1313
| Typedtree.Tpat_constraint _ -> true
1414
| Typedtree.Tpat_type (_, _)
1515
| Typedtree.Tpat_open (_, _, _)
16-
| Typedtree.Tpat_unpack -> false)
16+
| Typedtree.Tpat_unpack | Typedtree.Tpat_inspected_type _ -> false)
1717
pattern.pat_extra
1818

1919
let structure_iterator hint_let_binding hint_pattern_binding

src/analysis/kind_enclosing.ml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
open Std
2+
open Type_utils
3+
4+
module Kind_info = struct
5+
type t = { kind : Types.jkind_l; env : Env.t }
6+
7+
let mk ~kind ~env = { kind; env }
8+
9+
let from_type ~env ty = { kind = Ctype.estimate_type_jkind env ty; env }
10+
11+
let to_string ~(verbosity : Mconfig.Verbosity.t) { kind; env } =
12+
let kind =
13+
Jkind.normalize ~mode:Require_best
14+
~context:(Ctype.mk_jkind_context_check_principal env)
15+
kind
16+
in
17+
let print_with_verbosity ~jkind_verbosity kind =
18+
Printtyp.wrap_printing_env ~verbosity env (fun () ->
19+
Format.asprintf "%a"
20+
(Jkind.format_verbose ~verbosity:jkind_verbosity)
21+
kind)
22+
in
23+
let jkind_verbosity : Jkind.Format_verbosity.t =
24+
match Mconfig.Verbosity.to_int ~for_smart:0 verbosity with
25+
| 0 -> Not_verbose
26+
| 1 ->
27+
(* When verbosity=1, we should show the [Expanded] jkind. But the [Expanded] jkind
28+
may be the same as the [Not_verbose] jkind, in which case we want to skip
29+
directly to the [Expanded_with_all_mod_bounds] jkind. *)
30+
(* Printing jkinds without with bounds is cheap. *)
31+
let kind_without_with_bounds =
32+
{ kind with jkind = { kind.jkind with with_bounds = No_with_bounds } }
33+
in
34+
let unexpanded_kind =
35+
print_with_verbosity ~jkind_verbosity:Not_verbose
36+
kind_without_with_bounds
37+
in
38+
let expanded_kind =
39+
print_with_verbosity ~jkind_verbosity:Expanded
40+
kind_without_with_bounds
41+
in
42+
if String.equal unexpanded_kind expanded_kind then
43+
Expanded_with_all_mod_bounds
44+
else Expanded
45+
| _ -> Expanded_with_all_mod_bounds
46+
in
47+
print_with_verbosity ~jkind_verbosity kind
48+
end
49+
50+
let loc_contains_cursor (loc : Location.t) ~cursor =
51+
Lexing.compare_pos loc.loc_start cursor < 0
52+
&& Lexing.compare_pos cursor loc.loc_end < 0
53+
54+
let enclosings_of_node ~cursor (env, (node : Browse_raw.node)) :
55+
(Location.t * Kind_info.t) list =
56+
match node with
57+
| Pattern pattern ->
58+
[ (pattern.pat_loc, Kind_info.from_type ~env pattern.pat_type) ]
59+
| Expression expr ->
60+
[ (expr.exp_loc, Kind_info.from_type ~env expr.exp_type) ]
61+
| Core_type core_type ->
62+
let constr_enclosings =
63+
match core_type.ctyp_desc with
64+
| Ttyp_constr (path, ident, _) when loc_contains_cursor ident.loc ~cursor
65+
->
66+
(* TODO: The env here contains placeholder jkinds for types declared in the same
67+
recursive block, which causes under-approximations to be returned in some
68+
cases. *)
69+
let decl = Env.find_type path env in
70+
[ (ident.loc, Kind_info.mk ~kind:decl.type_jkind ~env) ]
71+
| _ -> []
72+
in
73+
constr_enclosings
74+
@ [ (core_type.ctyp_loc, Kind_info.from_type ~env core_type.ctyp_type) ]
75+
| Type_declaration decl ->
76+
[ (decl.typ_loc, Kind_info.mk ~kind:decl.typ_type.type_jkind ~env) ]
77+
| _ -> []
78+
79+
let from_mbrowse mbrowse ~cursor : (Location.t * Kind_info.t) list =
80+
List.concat_map mbrowse ~f:(enclosings_of_node ~cursor)

src/analysis/kind_enclosing.mli

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
(** Provides information about the kind of the thing the cursor is on. If the cursor is
2+
on an expression, it returns the kind of the type of the expression. If the cursor is
3+
on a type, it returns the kind of the type. If the cursor is on a kind abbreviation,
4+
it returns the expansion of the kind abbreviation. *)
5+
6+
module Kind_info : sig
7+
type t
8+
9+
val to_string : verbosity:Mconfig.Verbosity.t -> t -> string
10+
end
11+
12+
val from_mbrowse :
13+
Mbrowse.t -> cursor:Lexing.position -> (Location.t * Kind_info.t) list

0 commit comments

Comments
 (0)