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

Add support for 5.3.0 #1850

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
74c8713
Fetch OCaml upstream ocaml/ocaml upstream
xvw Sep 16, 2024
d0821cc
Upgrade `gen_patch` (migration script)
xvw Sep 16, 2024
df1c22a
Be more smart on patch application
xvw Sep 16, 2024
a68460c
Apply valid patches
xvw Sep 17, 2024
4e5690e
Apply a first bunch of patches
xvw Sep 17, 2024
9407959
Fix conflict and patch type incoherence
xvw Oct 1, 2024
4106c68
Missing Msupport occurences
xvw Oct 1, 2024
27ac672
Update Parser
xvw Oct 1, 2024
c6778cc
Revert parser upgrade
voodoos Oct 1, 2024
c1c8532
Re-apply parser changes
voodoos Oct 1, 2024
c4601a3
Rename token
voodoos Oct 1, 2024
8991496
Remove commented code
voodoos Oct 1, 2024
d2b0236
Restore files
xvw Oct 1, 2024
007d7eb
Split Doc representation of Printtyp in a dedicated module
xvw Oct 2, 2024
40c08e7
Apply some patches
xvw Oct 2, 2024
e72b963
Restore source un pprintast
xvw Oct 2, 2024
2eeedd1
Remove rejected useless files
xvw Oct 2, 2024
0ef4371
Deduce unit info from configuration
voodoos Oct 2, 2024
c6b48dd
Merge pull request #4 from voodoos/503-preview
xvw Oct 2, 2024
7779299
Fix string_of_label usage
xvw Oct 2, 2024
bb5c542
Upgrade compiler matrix
xvw Oct 2, 2024
9249247
Fix ocaml version bound
xvw Oct 2, 2024
626e3f8
Bump Magic Numbers
xvw Oct 2, 2024
2b137f1
Fix ocamlversion bump
xvw Oct 2, 2024
a048536
Fix Bump Magic number
xvw Oct 2, 2024
e590b9e
Promote test (for review)
xvw Oct 2, 2024
6915044
test: move ppx dependent tests in correct folder
voodoos Oct 4, 2024
29fdd02
Get the CI running
voodoos Oct 4, 2024
b167e66
Remove ocaml constraint from merlin package
voodoos Oct 4, 2024
4e125f3
Add some utils for API compatibility
voodoos Oct 4, 2024
e2bfcb4
Prevent formatting of format_doc
voodoos Oct 4, 2024
fdc607a
CI: disable fmt check and try to enable ocaml-lsp compat
voodoos Oct 4, 2024
0223fc1
fix lsp ci
voodoos Oct 4, 2024
3438e34
remove conflict with base-effect
voodoos Oct 4, 2024
563316a
Pull latest changes from upstream
voodoos Oct 15, 2024
02cf198
Apply latest changes
voodoos Oct 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
17 changes: 5 additions & 12 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ jobs:
- ubuntu-latest
- windows-latest
ocaml-compiler:
- 5.2.x
- ocaml-base-compiler.5.3.0~alpha1
# The type of runner that the job will run on
runs-on: ${{ matrix.os }}

# Some tests requiring specific ppxes are disabled by default
env:
MERLIN_TESTS: all
MERLIN_TESTS: no-ppx

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
Expand All @@ -62,19 +62,12 @@ jobs:
- name: Install dependencies
run: |
opam pin menhirLib 20201216 --no-action
opam install --yes ppx_string ppx_compare
opam install . --deps-only --with-test --yes
opam install menhir csexp alcotest yojson conf-jq ocamlfind --yes

- name: Build and test in release mode (windows)
if: matrix.os == 'windows-latest'
- name: Build and test in release mode
run: |
opam exec -- dune runtest -p merlin-lib,dot-merlin-reader,ocaml-index,merlin

- name: Build and test in release mode (macos/linux)
if: matrix.os != 'windows-latest'
run: |
opam install . --with-test --yes

- name: Build in dev mode to check parser changes
if: matrix.os == 'ubuntu-latest'
run: |
Expand All @@ -84,7 +77,7 @@ jobs:


- name: Check that the changes are correctly formatted
if: matrix.os == 'ubuntu-latest'
if: matrix.os == 'none'
run: |
opam install ocamlformat.0.26.2
opam exec -- dune build @fmt
12 changes: 6 additions & 6 deletions .github/workflows/ocaml-lsp-compat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: Check ocaml-lsp compat
# events but only for the master branch
on:
push:
branches: [ master ]
branches: [ main ]
paths-ignore:
- '**.md'
- '**.txt'
Expand All @@ -14,7 +14,7 @@ on:
- 'vim/**'
- '**/emacs-lint.yml'
pull_request:
branches: [ master ]
branches: [ main ]
paths-ignore:
- '**.md'
- '**.txt'
Expand All @@ -34,7 +34,7 @@ jobs:
os:
- ubuntu-latest
ocaml-compiler:
- 5.2.x
- ocaml-base-compiler.5.3.0~alpha1
# The type of runner that the job will run on
runs-on: ${{ matrix.os }}

Expand All @@ -51,7 +51,7 @@ jobs:

- name: Check that Merlin and OCaml-LSP are co-installable
run: |
opam --cli=2.1 pin --with-version=dev --no-action https://github.com/voodoos/ocaml-lsp.git#5.2-preview
opam --cli=2.1 pin --with-version=5.0-502 --no-action .
opam install ocaml-lsp-server --with-test --ignore-constraints-on=ocamlformat
opam --cli=2.1 pin --with-version=dev --no-action https://github.com/voodoos/ocaml-lsp.git#merlin-503-compat
opam --cli=2.1 pin --with-version=5.3-503 --no-action .
opam install ocaml-lsp-server --ignore-constraints-on=ocamlformat

2 changes: 1 addition & 1 deletion merlin-lib.opam
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ build: [
["dune" "build" "-p" name "-j" jobs]
]
depends: [
"ocaml" {>= "5.2" & < "5.3"}
"ocaml" {>="5.3" & <"5.4"}
"dune" {>= "3.0.0"}
"csexp" {>= "1.5.1"}
"alcotest" {with-test}
Expand Down
2 changes: 0 additions & 2 deletions merlin.opam
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ build: [
["dune" "runtest" "-p" name "-j" jobs] {with-test}
]
depends: [
"ocaml" {>= "5.2" & < "5.3"}
"dune" {>= "3.0.0"}
"merlin-lib" {= version}
"dot-merlin-reader" {>= "5.2"}
Expand All @@ -22,7 +21,6 @@ depends: [
]
conflicts: [
"seq" {!= "base"}
"base-effects"
]
synopsis:
"Editor helper, provides completion, typing and source browsing in Vim and Emacs"
Expand Down
5 changes: 3 additions & 2 deletions src/analysis/ast_iterators.ml
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,9 @@ let iter_on_defs ~uid_to_locs_tbl =
match exp_extra with
| Texp_newtype' (typ_id, typ_name, uid) ->
log "Found newtype %s wit id %a (%a)\n%!" typ_name.txt Logger.fmt
(Fun.flip Ident.print_with_scope typ_id) Logger.fmt (fun fmt ->
Location.print_loc fmt typ_name.loc);
(Fun.flip (Format_doc.compat Ident.print_with_scope) typ_id)
Logger.fmt
(fun fmt -> Location.print_loc fmt typ_name.loc);
register_uid uid typ_name;
()
| _ -> ());
Expand Down
34 changes: 18 additions & 16 deletions src/analysis/construct.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,28 @@ module Util = struct
let construct s =
Ast_helper.Exp.construct (Location.mknoloc (Longident.Lident s)) None
in
let const_string str = Ast_helper.Const.string str in
let const_integer ?suffix str = Ast_helper.Const.integer ?suffix str in
let const_float ?suffix str = Ast_helper.Const.float ?suffix str in
let const_char c = Ast_helper.Const.char c in
let ident s =
Ast_helper.Exp.ident (Location.mknoloc (Longident.Lident s))
in
List.iter
~f:(fun (k, v) -> Hashtbl.add tbl k v)
Parsetree.
[ (Predef.path_int, constant (Pconst_integer ("0", None)));
(Predef.path_float, constant (Pconst_float ("0.0", None)));
(Predef.path_char, constant (Pconst_char 'c'));
( Predef.path_string,
constant (Pconst_string ("", Location.none, None)) );
(Predef.path_bool, construct "false");
(Predef.path_unit, construct "()");
(Predef.path_exn, ident "exn");
(Predef.path_array, Ast_helper.Exp.array []);
(Predef.path_nativeint, constant (Pconst_integer ("0", Some 'n')));
(Predef.path_int32, constant (Pconst_integer ("0", Some 'l')));
(Predef.path_int64, constant (Pconst_integer ("0", Some 'L')));
(Predef.path_lazy_t, Ast_helper.Exp.lazy_ (construct "()"))
]
[ (Predef.path_int, constant (const_integer "0"));
(Predef.path_float, constant (const_float "0.0"));
(Predef.path_char, constant (const_char 'c'));
(Predef.path_string, constant (const_string ""));
(Predef.path_bool, construct "false");
(Predef.path_unit, construct "()");
(Predef.path_exn, ident "exn");
(Predef.path_array, Ast_helper.Exp.array []);
(Predef.path_nativeint, constant (const_integer ~suffix:'n' "0"));
(Predef.path_int32, constant (const_integer ~suffix:'l' "0"));
(Predef.path_int64, constant (const_integer ~suffix:'L' "0"));
(Predef.path_lazy_t, Ast_helper.Exp.lazy_ (construct "()"))
]
in
tbl

Expand Down Expand Up @@ -495,7 +497,7 @@ module Gen = struct
val_kind = Val_reg;
val_loc = Location.none;
val_attributes = [];
val_uid = Uid.mk ~current_unit:(Env.get_unit_name ())
val_uid = Uid.mk ~current_unit:(Env.get_current_unit ())
}
in
let env =
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/destruct.ml
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ let rec get_match = function
get_match parents
| Expression m -> (
match m.Typedtree.exp_desc with
| Typedtree.Texp_match (e, _, _) -> (m, e.exp_type)
| Typedtree.Texp_match (e, _, _, _) -> (m, e.exp_type)
| Typedtree.Texp_function _ -> (
let typ = m.exp_type in
(* Function must have arrow type. This arrow type
Expand Down
4 changes: 2 additions & 2 deletions src/analysis/env_lookup.ml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ let by_longident (nss : Namespace.inferred list) ident env =
"got constructor, fetching path and loc in type namespace";
let path, loc = path_and_loc_of_cstr cd env in
log ~title:"lookup" "found path: %a" Logger.fmt (fun fmt ->
Path.print fmt path);
(Format_doc.compat Path.print) fmt path);
let path = Path.Pdot (path, cd.cstr_name) in
raise (Found (path, Constructor, cd.cstr_uid, loc))
| `Constr ->
Expand Down Expand Up @@ -142,7 +142,7 @@ let by_longident (nss : Namespace.inferred list) ident env =
with Found (path, namespace, decl_uid, loc) ->
log ~title:"env_lookup"
"found: '%a' in namespace %s with decl_uid %a\nat loc %a" Logger.fmt
(fun fmt -> Path.print fmt path)
(fun fmt -> (Format_doc.compat Path.print) fmt path)
(Shape.Sig_component_kind.to_string namespace)
Logger.fmt
(fun fmt -> Shape.Uid.print fmt decl_uid)
Expand Down
3 changes: 2 additions & 1 deletion src/analysis/index_occurrences.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ let decl_of_path_or_lid env namespace path lid =
let iterator ~current_buffer_path ~index ~stamp ~reduce_for_uid =
let add uid loc = Stamped_hashtable.add index ~stamp (uid, loc) () in
let f ~namespace env path (lid : Longident.t Location.loc) =
log ~title:"index_buffer" "Path: %a" Logger.fmt (Fun.flip Path.print path);
log ~title:"index_buffer" "Path: %a" Logger.fmt
(Fun.flip (Format_doc.compat Path.print) path);
let not_ghost { Location.loc = { loc_ghost; _ }; _ } = not loc_ghost in
let lid = { lid with loc = set_fname ~file:current_buffer_path lid.loc } in
let index_decl () =
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/inlay_hints.ml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ let structure_iterator hint_let_binding hint_pattern_binding
| Texp_letop { body; _ } ->
let () = log ~title:"expression" "on let-op" in
case_iterator hint_let_binding iterator body
| Texp_match (expr, cases, _) ->
| Texp_match (expr, cases, _, _) ->
let () = log ~title:"expression" "on match" in
let () = iterator.expr iterator expr in
List.iter ~f:(case_iterator hint_pattern_binding iterator) cases
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/jump.ml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ let rec skip_non_moving pos = function

let get_cases_from_match node =
match node with
| Expression { exp_desc = Texp_match (_, cases, _); _ } -> cases
| Expression { exp_desc = Texp_match (_, cases, _, _); _ } -> cases
| _ -> []

let find_case_pos cases pos direction =
Expand Down
6 changes: 3 additions & 3 deletions src/analysis/locate.ml
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ let find_loc_of_uid ~config ~local_defs uid comp_unit =
log ~title "The declaration has no location.";
`None
in
if Env.get_unit_name () = comp_unit then begin
if Env.get_current_unit_name () = comp_unit then begin
log ~title "We look for %a in the current compilation unit." Logger.fmt
(fun fmt -> Shape.Uid.print fmt uid);
log ~title "Looking for %a in the uid_to_loc table" Logger.fmt (fun fmt ->
Expand Down Expand Up @@ -784,7 +784,7 @@ let doc_from_uid ~config ~loc uid =
begin
match uid with
| (Shape.Uid.Item { comp_unit; _ } | Shape.Uid.Compilation_unit comp_unit)
when Env.get_unit_name () <> comp_unit ->
when Env.get_current_unit_name () <> comp_unit ->
log ~title:"get_doc"
"the doc (%a) you're looking for is in another\n\
\ compilation unit (%s)" Logger.fmt
Expand Down Expand Up @@ -846,7 +846,7 @@ let get_doc ~config:mconfig ~env ~local_defs ~comments ~pos =
match path with
| `Completion_entry (namespace, path, _loc) ->
log ~title:"get_doc" "completion: looking for the doc of '%a'"
Logger.fmt (fun fmt -> Path.print fmt path);
Logger.fmt (fun fmt -> (Format_doc.compat Path.print) fmt path);

let from_path = from_path ~config ~env ~local_defs ~namespace path in
begin
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/occurrences.ml
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ let locs_of ~config ~env ~typer_result ~pos ~scope path =
let def_uid_is_in_current_unit =
let uid_comp_unit = comp_unit_of_uid def_uid in
Option.value_map ~default:false uid_comp_unit
~f:(String.equal @@ Env.get_unit_name ())
~f:(String.equal @@ Env.get_current_unit_name ())
in
let status =
match (scope, String.Set.to_list out_of_sync_files) with
Expand Down
5 changes: 5 additions & 0 deletions src/analysis/parsetree_utils.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
open Parsetree

type nonrec constant_desc = constant_desc

let constant_desc c = c.pconst_desc
8 changes: 8 additions & 0 deletions src/analysis/parsetree_utils.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(** Utilities to provide a slightly more stable Parsetree API for alternative
clients like [ocaml-lsp]. *)

open Parsetree

type nonrec constant_desc = constant_desc

val constant_desc : constant -> constant_desc
4 changes: 2 additions & 2 deletions src/analysis/tail_analysis.ml
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ let expr_tail_positions = function
| Texp_extension_constructor _
| Texp_letop _
| Texp_hole -> []
| Texp_match (_, cs, _) -> List.map cs ~f:(fun c -> Case c)
| Texp_try (_, cs) -> List.map cs ~f:(fun c -> Case c)
| Texp_match (_, cs, _, _) -> List.map cs ~f:(fun c -> Case c)
| Texp_try (_, cs, _) -> List.map cs ~f:(fun c -> Case c)
| Texp_letmodule (_, _, _, _, e)
| Texp_letexception (_, e)
| Texp_let (_, _, e)
Expand Down
5 changes: 3 additions & 2 deletions src/analysis/type_utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ let print_cstr_desc ppf cstr_desc =
let print_constr ppf env lid =
let cstr_desc = Env.find_constructor_by_name lid.Asttypes.txt env in
(* FIXME: support Reader printer *)
print_cstr_desc ppf cstr_desc
(Format_doc.compat print_cstr_desc) ppf cstr_desc

exception Fallback
let type_in_env ?(verbosity = Verbosity.default) ?keywords ~context env ppf expr
Expand Down Expand Up @@ -344,7 +344,8 @@ let type_in_env ?(verbosity = Verbosity.default) ?keywords ~context env ppf expr
false))

let print_constr ~verbosity env ppf cd =
Printtyp.wrap_printing_env env ~verbosity @@ fun () -> print_cstr_desc ppf cd
Printtyp.wrap_printing_env env ~verbosity @@ fun () ->
(Format_doc.compat print_cstr_desc) ppf cd

(* From doc-ock
https://github.com/lpw25/doc-ock/blob/master/src/docOckAttrs.ml *)
Expand Down
27 changes: 27 additions & 0 deletions src/analysis/typedtree_utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,30 @@ let pat_alias_pat_id_and_loc = function
| Typedtree.{ pat_desc = Tpat_alias (pat, id, loc, _); _ } ->
Some (pat, id, loc)
| _ -> None

open Typedtree

type texp_match =
{ expr : expression;
computation_cases : computation case list;
value_cases : value case list;
partial : partial
}

type texp_try =
{ expr : expression;
value_cases : value case list;
effect_cases : value case list
}

let texp_match_of_expr expr =
match expr.exp_desc with
| Texp_match (expr, computation_cases, value_cases, partial) ->
Some { expr; computation_cases; value_cases; partial }
| _ -> None

let texp_try_of_expr expr =
match expr.exp_desc with
| Texp_try (expr, value_cases, effect_cases) ->
Some { expr; value_cases; effect_cases }
| _ -> None
18 changes: 18 additions & 0 deletions src/analysis/typedtree_utils.mli
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,21 @@ val pat_var_id_and_loc :
val pat_alias_pat_id_and_loc :
Typedtree.pattern ->
(Typedtree.pattern * Ident.t * string Location.loc) option

open Typedtree

type texp_match =
{ expr : expression;
computation_cases : computation case list;
value_cases : value case list;
partial : partial
}

type texp_try =
{ expr : expression;
value_cases : value case list;
effect_cases : value case list
}

val texp_match_of_expr : expression -> texp_match option
val texp_try_of_expr : expression -> texp_try option
3 changes: 2 additions & 1 deletion src/config/gen_config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ let ocamlversion :
| `OCaml_4_03_0 | `OCaml_4_04_0 | `OCaml_4_05_0 | `OCaml_4_06_0
| `OCaml_4_07_0 | `OCaml_4_07_1 | `OCaml_4_08_0 | `OCaml_4_09_0
| `OCaml_4_10_0 | `OCaml_4_11_0 | `OCaml_4_12_0 | `OCaml_4_13_0
| `OCaml_4_14_0 | `OCaml_5_0_0 | `OCaml_5_1_0 | `OCaml_5_2_0 ] = %s
| `OCaml_4_14_0 | `OCaml_5_0_0 | `OCaml_5_1_0 | `OCaml_5_2_0
| `OCaml_5_3_0 ] = %s
|}
ocaml_version_val
2 changes: 1 addition & 1 deletion src/kernel/extension.ml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ let ext_meta =
\ end"
];
public_def = [];
keywords = [ (">.", GREATERDOT) ];
keywords = [ (">.", METAOCAML_BRACKET_CLOSE) ];
packages = []
}

Expand Down
12 changes: 12 additions & 0 deletions src/kernel/mconfig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -838,3 +838,15 @@ let unitname t =
| Some prefix -> prefix ^ basename
| None -> basename
end

let intf_or_impl t =
let extension = Filename.extension t.query.filename in
try
List.find_map t.merlin.suffixes ~f:(fun (impl, intf) ->
if String.equal extension impl then Some Unit_info.Impl
else if String.equal extension intf then Some Unit_info.Intf
else None)
with Not_found -> Unit_info.Impl

let unit_info t =
Unit_info.make ~source_file:t.query.filename (intf_or_impl t) (unitname t)
Loading
Loading