@@ -45,16 +45,16 @@ let send_msg t value ~(webview : WebView.t) =
45
45
46
46
module Pp_path : sig
47
47
type kind =
48
- | Structure
49
- | Signature
48
+ | Structure of [ `Ocaml | `Reason ]
49
+ | Signature of [ `Ocaml | `Reason ]
50
50
| Unknown
51
51
52
52
val get_kind : document :TextDocument .t -> kind
53
53
val get_pp_path : document :TextDocument .t -> string
54
54
end = struct
55
55
type kind =
56
- | Structure
57
- | Signature
56
+ | Structure of [ `Ocaml | `Reason ]
57
+ | Signature of [ `Ocaml | `Reason ]
58
58
| Unknown
59
59
60
60
let relative_document_path ~document =
@@ -66,8 +66,10 @@ end = struct
66
66
let get_kind ~document =
67
67
let relative = relative_document_path ~document in
68
68
match Stdlib.Filename. extension relative with
69
- | ".ml" -> Structure
70
- | ".mli" -> Signature
69
+ | ".ml" -> Structure `Ocaml
70
+ | ".re" -> Structure `Reason
71
+ | ".mli" -> Signature `Ocaml
72
+ | ".rei" -> Signature `Reason
71
73
| _ -> Unknown
72
74
;;
73
75
@@ -80,8 +82,12 @@ end = struct
80
82
let fname_opt =
81
83
match get_kind ~document with
82
84
| Unknown -> None
83
- | Structure -> Some (String. chop_suffix_exn ~suffix: " .ml" relative ^ " .pp.ml" )
84
- | Signature -> Some (String. chop_suffix_exn ~suffix: " .mli" relative ^ " .pp.mli" )
85
+ | Structure `Ocaml ->
86
+ Some (String. chop_suffix_exn ~suffix: " .ml" relative ^ " .pp.ml" )
87
+ | Signature `Ocaml ->
88
+ Some (String. chop_suffix_exn ~suffix: " .mli" relative ^ " .pp.mli" )
89
+ | Structure `Reason -> Some (relative ^ " .pp.ml" )
90
+ | Signature `Reason -> Some (relative ^ " .pp.mli" )
85
91
in
86
92
(match fname_opt with
87
93
| Some fname ->
@@ -111,8 +117,8 @@ let transform_to_ast instance ~document ~webview =
111
117
let origin_json =
112
118
let text = TextDocument. getText document () in
113
119
match Pp_path. get_kind ~document with
114
- | Structure -> make_value (Dumpast. transform text `Impl )
115
- | Signature -> make_value (Dumpast. transform text `Intf )
120
+ | Structure _ -> make_value (Dumpast. transform text `Impl )
121
+ | Signature _ -> make_value (Dumpast. transform text `Intf )
116
122
| Unknown -> raise (User_error " Unknown file extension" )
117
123
in
118
124
send_msg " ast" (Jsonoo. t_to_js origin_json) ~webview
@@ -321,9 +327,16 @@ let open_pp_doc instance ~document =
321
327
match fetch_pp_code ~document with
322
328
| Error e -> Promise. return (Error e)
323
329
| Ok pp_pp_str ->
330
+ let file_name =
331
+ match Pp_path. get_kind ~document with
332
+ | Structure `Reason ->
333
+ String. chop_suffix_exn ~suffix: " .re" (TextDocument. fileName document) ^ " .ml"
334
+ | Signature `Reason ->
335
+ String. chop_suffix_exn ~suffix: " .rei" (TextDocument. fileName document) ^ " .mli"
336
+ | _ -> TextDocument. fileName document
337
+ in
324
338
let * doc =
325
- Workspace. openTextDocument
326
- (`Uri (Uri. parse (" post-ppx: " ^ TextDocument. fileName document ^ " ?" ) () ))
339
+ Workspace. openTextDocument (`Uri (Uri. parse (" post-ppx: " ^ file_name ^ " ?" ) () ))
327
340
in
328
341
Ast_editor_state. associate_origin_and_pp
329
342
ast_editor_state
0 commit comments