Skip to content

Commit ad4d4a8

Browse files
authored
Merge pull request #2 from Josef-Thorne-A/Add-ocamlformat-mlx
fixing pattern matching errors and type discrepancies
2 parents 15638a3 + 91404ff commit ad4d4a8

File tree

3 files changed

+27
-23
lines changed

3 files changed

+27
-23
lines changed

ocaml-lsp-server/src/code_actions.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ let compute server (params : CodeActionParams.t) =
125125
(match Document.syntax doc with
126126
| Ocamllex | Menhir | Cram | Dune ->
127127
Fiber.return (Reply.now (actions (dune_actions @ open_related)), state)
128-
| Ocaml | Reason ->
128+
| Ocaml | Reason | Mlx ->
129129
let reply () =
130130
let+ code_action_results = compute_ocaml_code_actions params state doc in
131131
List.concat [ code_action_results; dune_actions; open_related; merlin_jumps ]

ocaml-lsp-server/src/ocaml_lsp_server.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ let set_diagnostics detached diagnostics doc =
203203
in
204204
Diagnostics.set diagnostics (`Merlin (uri, [ no_reason_merlin ]));
205205
async (fun () -> Diagnostics.send diagnostics (`One uri))
206-
| Reason | Ocaml ->
206+
| Reason | Ocaml | Mlx ->
207207
async (fun () ->
208208
let* () = Diagnostics.merlin_diagnostics diagnostics merlin in
209209
Diagnostics.send diagnostics (`One uri)))

ocaml-lsp-server/src/workspace_symbol.ml

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,18 @@ end = struct
7070
open Browse_raw
7171
open Browse_tree
7272

73-
let id_of_patt = function
74-
| { pat_desc = Tpat_var (id, _, _); _ } -> Some id
73+
let name_of_patt = function
74+
| { pat_desc = Tpat_var (_, name, _); _ } -> Some name
7575
| _ -> None
7676
;;
7777

78-
let mk ?(children = []) ~location ~deprecated outline_kind id =
78+
let mk ?(children = []) ~location ~deprecated outline_kind (id : string Location.loc) =
7979
{ Query_protocol.outline_kind
8080
; outline_type = None
8181
; location
82+
; selection = id.loc
8283
; children
83-
; outline_name = Ident.name id
84+
; outline_name = id.txt
8485
; deprecated
8586
}
8687
;;
@@ -96,30 +97,30 @@ end = struct
9697
match node.t_node with
9798
| Value_binding vb ->
9899
let deprecated = Type_utils.is_deprecated vb.vb_attributes in
99-
(match id_of_patt vb.vb_pat with
100+
(match name_of_patt vb.vb_pat with
100101
| None -> None
101-
| Some ident -> Some (mk ~location ~deprecated `Value ident))
102+
| Some name -> Some (mk ~location ~deprecated `Value name))
102103
| Value_description vd ->
103104
let deprecated = Type_utils.is_deprecated vd.val_attributes in
104-
Some (mk ~location ~deprecated `Value vd.val_id)
105+
Some (mk ~location ~deprecated `Value vd.val_name)
105106
| Module_declaration md ->
106107
let children = get_mod_children node in
107-
(match md.md_id with
108-
| None -> None
109-
| Some id ->
108+
(match md.md_name with
109+
| { txt = None; _ } -> None
110+
| { txt = Some txt; loc } ->
110111
let deprecated = Type_utils.is_deprecated md.md_attributes in
111-
Some (mk ~children ~location ~deprecated `Module id))
112+
Some (mk ~children ~location ~deprecated `Module { txt; loc }))
112113
| Module_binding mb ->
113114
let children = get_mod_children node in
114-
(match mb.mb_id with
115-
| None -> None
116-
| Some id ->
115+
(match mb.mb_name with
116+
| { txt = None; _ } -> None
117+
| { txt = Some txt; loc } ->
117118
let deprecated = Type_utils.is_deprecated mb.mb_attributes in
118-
Some (mk ~children ~location ~deprecated `Module id))
119+
Some (mk ~children ~location ~deprecated `Module { txt; loc }))
119120
| Module_type_declaration mtd ->
120121
let children = get_mod_children node in
121122
let deprecated = Type_utils.is_deprecated mtd.mtd_attributes in
122-
Some (mk ~deprecated ~children ~location `Modtype mtd.mtd_id)
123+
Some (mk ~deprecated ~children ~location `Modtype mtd.mtd_name)
123124
| Type_declaration td ->
124125
let children =
125126
List.concat_map (Lazy.force node.t_children) ~f:(fun child ->
@@ -129,16 +130,16 @@ end = struct
129130
match x.t_node with
130131
| Constructor_declaration c ->
131132
let deprecated = Type_utils.is_deprecated c.cd_attributes in
132-
mk `Constructor c.cd_id ~deprecated ~location:c.cd_loc
133+
mk `Constructor c.cd_name ~deprecated ~location:c.cd_loc
133134
| Label_declaration ld ->
134135
let deprecated = Type_utils.is_deprecated ld.ld_attributes in
135-
mk `Label ld.ld_id ~deprecated ~location:ld.ld_loc
136+
mk `Label ld.ld_name ~deprecated ~location:ld.ld_loc
136137
| _ -> assert false
137138
(* ! *))
138139
| _ -> [])
139140
in
140141
let deprecated = Type_utils.is_deprecated td.typ_attributes in
141-
Some (mk ~children ~location ~deprecated `Type td.typ_id)
142+
Some (mk ~children ~location ~deprecated `Type td.typ_name)
142143
| Type_extension te ->
143144
let name = Path.name te.tyext_path in
144145
let children =
@@ -151,16 +152,17 @@ end = struct
151152
; outline_kind = `Type
152153
; outline_type = None
153154
; location
155+
; selection = te.tyext_txt.loc
154156
; children
155157
; deprecated
156158
}
157159
| Extension_constructor ec ->
158160
let deprecated = Type_utils.is_deprecated ec.ext_attributes in
159-
Some (mk ~location `Exn ec.ext_id ~deprecated)
161+
Some (mk ~location `Exn ec.ext_name ~deprecated)
160162
| Class_declaration cd ->
161163
let children = List.concat_map (Lazy.force node.t_children) ~f:get_class_elements in
162164
let deprecated = Type_utils.is_deprecated cd.ci_attributes in
163-
Some (mk ~children ~location `Class cd.ci_id_class_type ~deprecated)
165+
Some (mk ~children ~location `Class cd.ci_id_name ~deprecated)
164166
| _ -> None
165167

166168
and get_class_elements node =
@@ -178,6 +180,7 @@ end = struct
178180
; outline_kind
179181
; outline_type = None
180182
; location = str_loc.Location.loc
183+
; selection = str_loc.Location.loc
181184
; children = []
182185
; deprecated
183186
}
@@ -218,6 +221,7 @@ let outline_kind kind : SymbolKind.t =
218221
| `Type -> String
219222
| `Exn -> Constructor
220223
| `Class -> Class
224+
| `ClassType -> Interface
221225
| `Method -> Method
222226
;;
223227

0 commit comments

Comments
 (0)