diff --git a/ocamlmerlin_mlx/ocamlmerlin_mlx.ml b/ocamlmerlin_mlx/ocamlmerlin_mlx.ml index f43981d..d75afbc 100644 --- a/ocamlmerlin_mlx/ocamlmerlin_mlx.ml +++ b/ocamlmerlin_mlx/ocamlmerlin_mlx.ml @@ -1,21 +1,35 @@ open Merlin_extend open Merlin_extend.Extend_protocol.Reader -open Ocaml_parsing +open Mlx_ocaml_parsing open Mlx_kernel -module Conv = Ppxlib_ast.Convert(Ppxlib_ast__Versions.OCaml_501)(Ppxlib_ast.Compiler_version) - -let conv_signature intf = - let intf: Astlib.Ast_501.Parsetree.signature = Obj.magic intf in - let intf = Conv.copy_signature intf in - let intf: Ocaml_parsing.Parsetree.signature = Obj.magic intf in - intf - -let conv_structure impl = - let impl: Astlib.Ast_501.Parsetree.structure = Obj.magic impl in - let impl = Conv.copy_structure impl in - let impl: Ocaml_parsing.Parsetree.structure = Obj.magic impl in - impl +(* Some notes on usage of Obj.magic here... + - we copy parsetree.ml from merlin' 501 branch which copies AST from OCaml's + 5.1.x branch. TODO: instead we should inject ppxlib's Ast_501 module there + - then finally the currently installed merlin-extend should have the same + AST as the one used by compiled. TODO: figure out why compiler doesn't see + that... +*) +module Conv = struct + module Conv = + Ppxlib_ast.Convert + (Ppxlib_ast__Versions.OCaml_501) + (Ppxlib_ast.Compiler_version) + + let conv_signature (intf : Mlx_ocaml_parsing.Parsetree.signature) : + Ocaml_parsing.Parsetree.signature = + let intf : Astlib.Ast_501.Parsetree.signature = Obj.magic intf in + let intf = Conv.copy_signature intf in + let intf : Ocaml_parsing.Parsetree.signature = Obj.magic intf in + intf + + let conv_structure (impl : Mlx_ocaml_parsing.Parsetree.structure) : + Ocaml_parsing.Parsetree.structure = + let impl : Astlib.Ast_501.Parsetree.structure = Obj.magic impl in + let impl = Conv.copy_structure impl in + let impl : Ocaml_parsing.Parsetree.structure = Obj.magic impl in + impl +end let parse_string filename str = let src = Msource.make str in @@ -81,17 +95,18 @@ module Mlx_reader = struct List.filter_map to_extension_node res.lexer_errors in match res.parsetree with - | `Interface intf -> Signature (conv_signature intf) + | `Interface intf -> Signature (Conv.conv_signature intf) | `Implementation impl -> - Structure (conv_structure impl @ parser_errors @ lexer_errors) + Structure + (Conv.conv_structure (impl @ parser_errors @ lexer_errors)) let for_completion t _pos = { complete_labels = true }, parse t let parse_line _ _ text = let res = parse_string "*buffer*" text in match res.parsetree with - | `Interface intf -> Signature (conv_signature intf) - | `Implementation impl -> Structure (conv_structure impl) + | `Interface intf -> Signature (Conv.conv_signature intf) + | `Implementation impl -> Structure (Conv.conv_structure impl) let ident_at _ _ = [] let pretty_print _ppf _ = ()