From 2852b6ab1eb000a7f9ecb7aa5c22d2e6fe23083a Mon Sep 17 00:00:00 2001 From: David Sancho Moreno Date: Wed, 7 May 2025 00:58:51 +0200 Subject: [PATCH 01/15] setup doesn't work, time to push --- ocaml-lsp-server/src/document.ml | 4 ++++ ocaml-lsp-server/src/ocamlformat.ml | 3 +++ ocaml-lsp-server/src/ocamlformat.mli | 3 ++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ocaml-lsp-server/src/document.ml b/ocaml-lsp-server/src/document.ml index ec1ec2956..ad532dfdb 100644 --- a/ocaml-lsp-server/src/document.ml +++ b/ocaml-lsp-server/src/document.ml @@ -32,6 +32,7 @@ module Syntax = struct | Menhir | Cram | Dune + | Mlx let human_name = function | Ocaml -> "OCaml" @@ -40,6 +41,7 @@ module Syntax = struct | Menhir -> "Menhir/ocamlyacc" | Cram -> "Cram" | Dune -> "Dune" + | Mlx -> "OCaml.mlx" ;; let all = @@ -52,6 +54,7 @@ module Syntax = struct ; "dune", Dune ; "dune-project", Dune ; "dune-workspace", Dune + ; "ocaml.mlx", Mlx ] ;; @@ -61,6 +64,7 @@ module Syntax = struct | s -> (match Filename.extension s with | ".eliomi" | ".eliom" | ".mli" | ".ml" -> Ok Ocaml + | ".mlx" -> Ok Mlx | ".rei" | ".re" -> Ok Reason | ".mll" -> Ok Ocamllex | ".mly" -> Ok Menhir diff --git a/ocaml-lsp-server/src/ocamlformat.ml b/ocaml-lsp-server/src/ocamlformat.ml index 28437f21f..cebdb8e91 100644 --- a/ocaml-lsp-server/src/ocamlformat.ml +++ b/ocaml-lsp-server/src/ocamlformat.ml @@ -100,8 +100,10 @@ let message = function type formatter = | Reason of Document.Kind.t | Ocaml of Uri.t + | Mlx of Uri.t let args = function + | Mlx | Ocaml uri -> [ sprintf "--name=%s" (Uri.to_path uri); "-" ] | Reason kind -> [ "--parse"; "re"; "--print"; "re" ] @@ -114,6 +116,7 @@ let args = function let binary_name t = match t with | Ocaml _ -> "ocamlformat" + | Mlx _ -> "ocamlformat-mlx" | Reason _ -> "refmt" ;; diff --git a/ocaml-lsp-server/src/ocamlformat.mli b/ocaml-lsp-server/src/ocamlformat.mli index 0d6edc6c1..186f692ba 100644 --- a/ocaml-lsp-server/src/ocamlformat.mli +++ b/ocaml-lsp-server/src/ocamlformat.mli @@ -1,6 +1,7 @@ (** Generic formatting facility for OCaml and Reason sources. - Relies on [ocamlformat] for OCaml and [refmt] for reason *) + Relies on [ocamlformat] for OCaml, [ocamlformat-mlx] for OCaml.mlx, and + [refmt] for Reason. *) open Import From 97803ab64bc2d516db73a35d3ae7476acc351dc4 Mon Sep 17 00:00:00 2001 From: David Sancho Moreno Date: Wed, 7 May 2025 01:02:35 +0200 Subject: [PATCH 02/15] run ci --- .github/workflows/build-and-test.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 61b15b91e..7c52ec38a 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -2,12 +2,6 @@ name: Build and Test on: pull_request: - push: - branches: - - master - schedule: - # Prime the caches every Monday - - cron: 0 1 * * MON jobs: build-and-test: From f796300b83af9484f8e892981467590f0df6ace5 Mon Sep 17 00:00:00 2001 From: David Sancho Moreno Date: Wed, 7 May 2025 01:41:09 +0200 Subject: [PATCH 03/15] Enable ocamlformat --- ocaml-lsp-server/src/document.ml | 4 +++- ocaml-lsp-server/src/document.mli | 1 + ocaml-lsp-server/src/ocamlformat.ml | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ocaml-lsp-server/src/document.ml b/ocaml-lsp-server/src/document.ml index ad532dfdb..c07492cc6 100644 --- a/ocaml-lsp-server/src/document.ml +++ b/ocaml-lsp-server/src/document.ml @@ -256,7 +256,7 @@ let make wheel config pipeline (doc : DidOpenTextDocumentParams.t) ~position_enc let tdoc = Text_document.make ~position_encoding doc in let syntax = Syntax.of_text_document tdoc in match syntax with - | Ocaml | Reason -> make_merlin wheel config pipeline tdoc syntax + | Ocaml | Reason | Mlx -> make_merlin wheel config pipeline tdoc syntax | Ocamllex | Menhir | Cram | Dune -> Fiber.return (Other { tdoc; syntax })) ;; @@ -440,6 +440,8 @@ let get_impl_intf_counterparts m uri = in match Syntax.of_fname fname with | Dune | Cram -> [] + (* TODO: Unsure about this, keeping it empty for now *) + | Mlx -> [] | Ocaml -> (match kind with | Intf -> [ ml; mly; mll; eliom; re ] diff --git a/ocaml-lsp-server/src/document.mli b/ocaml-lsp-server/src/document.mli index 735bfd659..6585b6f0b 100644 --- a/ocaml-lsp-server/src/document.mli +++ b/ocaml-lsp-server/src/document.mli @@ -10,6 +10,7 @@ module Syntax : sig | Menhir | Cram | Dune + | Mlx val human_name : t -> string val markdown_name : t -> string diff --git a/ocaml-lsp-server/src/ocamlformat.ml b/ocaml-lsp-server/src/ocamlformat.ml index cebdb8e91..4d84d3aa3 100644 --- a/ocaml-lsp-server/src/ocamlformat.ml +++ b/ocaml-lsp-server/src/ocamlformat.ml @@ -103,7 +103,7 @@ type formatter = | Mlx of Uri.t let args = function - | Mlx + | Mlx uri | Ocaml uri -> [ sprintf "--name=%s" (Uri.to_path uri); "-" ] | Reason kind -> [ "--parse"; "re"; "--print"; "re" ] @@ -131,6 +131,7 @@ let formatter doc = match Document.syntax doc with | (Dune | Cram | Ocamllex | Menhir) as s -> Error (Unsupported_syntax s) | Ocaml -> Ok (Ocaml (Document.uri doc)) + | Mlx -> Ok (Mlx (Document.uri doc)) | Reason -> Ok (Reason From a4ea7888b62467458c8a268be65056fd1d4319d8 Mon Sep 17 00:00:00 2001 From: David Sancho Moreno Date: Wed, 7 May 2025 01:41:22 +0200 Subject: [PATCH 04/15] Keep ci as before --- .github/workflows/build-and-test.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 7c52ec38a..61b15b91e 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -2,6 +2,12 @@ name: Build and Test on: pull_request: + push: + branches: + - master + schedule: + # Prime the caches every Monday + - cron: 0 1 * * MON jobs: build-and-test: From 15638a3bc40b5ea8c777d16f5f3a2d08eb82bb77 Mon Sep 17 00:00:00 2001 From: David Sancho Moreno Date: Wed, 7 May 2025 01:43:53 +0200 Subject: [PATCH 05/15] Resolve doubt about get_impl_intf_counterparts --- ocaml-lsp-server/src/document.ml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/ocaml-lsp-server/src/document.ml b/ocaml-lsp-server/src/document.ml index c07492cc6..1efbf24dc 100644 --- a/ocaml-lsp-server/src/document.ml +++ b/ocaml-lsp-server/src/document.ml @@ -425,8 +425,8 @@ let close t = let get_impl_intf_counterparts m uri = let fpath = Uri.to_path uri in let fname = Filename.basename fpath in - let ml, mli, eliom, eliomi, re, rei, mll, mly = - "ml", "mli", "eliom", "eliomi", "re", "rei", "mll", "mly" + let ml, mli, eliom, eliomi, re, rei, mll, mly, mlx = + "ml", "mli", "eliom", "eliomi", "re", "rei", "mll", "mly", "mlx" in let exts_to_switch_to = let kind = @@ -441,14 +441,17 @@ let get_impl_intf_counterparts m uri = match Syntax.of_fname fname with | Dune | Cram -> [] (* TODO: Unsure about this, keeping it empty for now *) - | Mlx -> [] + | Mlx -> + (match kind with + | Intf -> [ re; ml; mly; mll ] + | Impl -> [ rei; mli; mly; mll ]) | Ocaml -> (match kind with - | Intf -> [ ml; mly; mll; eliom; re ] + | Intf -> [ ml; mly; mll; eliom; re; mlx ] | Impl -> [ mli; mly; mll; eliomi; rei ]) | Reason -> (match kind with - | Intf -> [ re; ml ] + | Intf -> [ re; ml; mlx ] | Impl -> [ rei; mli ]) | Ocamllex -> [ mli; rei ] | Menhir -> [ mli; rei ] From 0988f2b9b0ea6822ed0f8a970b7eaf807605f772 Mon Sep 17 00:00:00 2001 From: David Sancho Moreno Date: Tue, 16 Sep 2025 10:21:49 +0200 Subject: [PATCH 06/15] Add mlx as exts_to_switch_to --- ocaml-lsp-server/src/document.ml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ocaml-lsp-server/src/document.ml b/ocaml-lsp-server/src/document.ml index 1efbf24dc..e34f80784 100644 --- a/ocaml-lsp-server/src/document.ml +++ b/ocaml-lsp-server/src/document.ml @@ -440,11 +440,10 @@ let get_impl_intf_counterparts m uri = in match Syntax.of_fname fname with | Dune | Cram -> [] - (* TODO: Unsure about this, keeping it empty for now *) | Mlx -> (match kind with - | Intf -> [ re; ml; mly; mll ] - | Impl -> [ rei; mli; mly; mll ]) + | Intf -> [ re; ml; mly; mll; mlx ] + | Impl -> [ rei; mli; mly; mll; mlx ]) | Ocaml -> (match kind with | Intf -> [ ml; mly; mll; eliom; re; mlx ] From 53098aa5d8980a7d74bd6b4599537a4e47fab0c5 Mon Sep 17 00:00:00 2001 From: David Sancho Moreno Date: Fri, 3 Oct 2025 13:51:01 +0200 Subject: [PATCH 07/15] Kind ensures --impl is passed to ocamlformat-mlx --- ocaml-lsp-server/src/document.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ocaml-lsp-server/src/document.ml b/ocaml-lsp-server/src/document.ml index e34f80784..cce899da2 100644 --- a/ocaml-lsp-server/src/document.ml +++ b/ocaml-lsp-server/src/document.ml @@ -8,7 +8,7 @@ module Kind = struct let of_fname_opt p = match Filename.extension p with - | ".ml" | ".eliom" | ".re" -> Some Impl + | ".ml" | ".eliom" | ".re" | ".mlx" -> Some Impl | ".mli" | ".eliomi" | ".rei" -> Some Intf | _ -> None ;; From 306363cdcf960593b4788213cdef539417c3cd43 Mon Sep 17 00:00:00 2001 From: David Sancho Moreno Date: Fri, 3 Oct 2025 13:51:21 +0200 Subject: [PATCH 08/15] Reorder get_impl_intf_counterparts --- ocaml-lsp-server/src/document.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ocaml-lsp-server/src/document.ml b/ocaml-lsp-server/src/document.ml index cce899da2..989178381 100644 --- a/ocaml-lsp-server/src/document.ml +++ b/ocaml-lsp-server/src/document.ml @@ -442,8 +442,8 @@ let get_impl_intf_counterparts m uri = | Dune | Cram -> [] | Mlx -> (match kind with - | Intf -> [ re; ml; mly; mll; mlx ] - | Impl -> [ rei; mli; mly; mll; mlx ]) + | Intf -> [ ml; mly; mll; mlx; re ] + | Impl -> [ rei; mli; mly; mll; rei ]) | Ocaml -> (match kind with | Intf -> [ ml; mly; mll; eliom; re; mlx ] From ab22e06746d356b7ac41490c2066211bdef685cc Mon Sep 17 00:00:00 2001 From: David Sancho Moreno Date: Fri, 3 Oct 2025 13:51:30 +0200 Subject: [PATCH 09/15] Enable mlx as interference --- ocaml-lsp-server/src/inference.ml | 1 + 1 file changed, 1 insertion(+) diff --git a/ocaml-lsp-server/src/inference.ml b/ocaml-lsp-server/src/inference.ml index d51401e31..c313b7bd2 100644 --- a/ocaml-lsp-server/src/inference.ml +++ b/ocaml-lsp-server/src/inference.ml @@ -71,6 +71,7 @@ let language_id_of_fname s = | ".mli" | ".eliomi" -> "ocaml.interface" | ".ml" | ".eliom" -> "ocaml" | ".rei" | ".re" -> "reason" + | ".mlx" -> "ocaml.mlx" | ".mll" -> "ocaml.ocamllex" | ".mly" -> "ocaml.menhir" | ext -> Code_error.raise "unsupported file extension" [ "extension", String ext ] From f1605c40eb1d88d628f7ae344ed44eb0747ac55f Mon Sep 17 00:00:00 2001 From: David Sancho Moreno Date: Fri, 3 Oct 2025 14:02:20 +0200 Subject: [PATCH 10/15] Ensure ocamlformat-mlx has --impl for mlx --- ocaml-lsp-server/src/ocamlformat.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ocaml-lsp-server/src/ocamlformat.ml b/ocaml-lsp-server/src/ocamlformat.ml index 4d84d3aa3..41d332a5a 100644 --- a/ocaml-lsp-server/src/ocamlformat.ml +++ b/ocaml-lsp-server/src/ocamlformat.ml @@ -103,8 +103,8 @@ type formatter = | Mlx of Uri.t let args = function - | Mlx uri | Ocaml uri -> [ sprintf "--name=%s" (Uri.to_path uri); "-" ] + | Mlx uri -> [ sprintf "--name=%s" (Uri.to_path uri); "-"; "--impl" ] | Reason kind -> [ "--parse"; "re"; "--print"; "re" ] @ From 7955b4c65cfb9e1014ad79a3a8c55c7651a804dc Mon Sep 17 00:00:00 2001 From: David Sancho Moreno Date: Fri, 3 Oct 2025 14:05:07 +0200 Subject: [PATCH 11/15] Enable code_actions for mlx --- ocaml-lsp-server/src/code_actions.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ocaml-lsp-server/src/code_actions.ml b/ocaml-lsp-server/src/code_actions.ml index 662599eea..c2f7b9060 100644 --- a/ocaml-lsp-server/src/code_actions.ml +++ b/ocaml-lsp-server/src/code_actions.ml @@ -125,7 +125,7 @@ let compute server (params : CodeActionParams.t) = (match Document.syntax doc with | Ocamllex | Menhir | Cram | Dune -> Fiber.return (Reply.now (actions (dune_actions @ open_related)), state) - | Ocaml | Reason -> + | Ocaml | Reason | Mlx -> let reply () = let+ code_action_results = compute_ocaml_code_actions params state doc in List.concat [ code_action_results; dune_actions; open_related; merlin_jumps ] From 455cd57f12ba0943f2807da43287da8d56823390 Mon Sep 17 00:00:00 2001 From: David Sancho Moreno Date: Fri, 3 Oct 2025 14:06:06 +0200 Subject: [PATCH 12/15] Pass impl first --- ocaml-lsp-server/src/ocamlformat.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ocaml-lsp-server/src/ocamlformat.ml b/ocaml-lsp-server/src/ocamlformat.ml index 41d332a5a..4c6ce3757 100644 --- a/ocaml-lsp-server/src/ocamlformat.ml +++ b/ocaml-lsp-server/src/ocamlformat.ml @@ -104,7 +104,7 @@ type formatter = let args = function | Ocaml uri -> [ sprintf "--name=%s" (Uri.to_path uri); "-" ] - | Mlx uri -> [ sprintf "--name=%s" (Uri.to_path uri); "-"; "--impl" ] + | Mlx uri -> [ "--impl"; sprintf "--name=%s" (Uri.to_path uri); "-" ] | Reason kind -> [ "--parse"; "re"; "--print"; "re" ] @ From bc39395221b50abdad044dbe424d906b9d954af8 Mon Sep 17 00:00:00 2001 From: David Sancho Moreno Date: Fri, 3 Oct 2025 17:03:44 +0200 Subject: [PATCH 13/15] Support mlx for merlin diagnostics --- ocaml-lsp-server/src/ocaml_lsp_server.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ocaml-lsp-server/src/ocaml_lsp_server.ml b/ocaml-lsp-server/src/ocaml_lsp_server.ml index ec7f8e119..39e58db09 100644 --- a/ocaml-lsp-server/src/ocaml_lsp_server.ml +++ b/ocaml-lsp-server/src/ocaml_lsp_server.ml @@ -203,7 +203,7 @@ let set_diagnostics detached diagnostics doc = in Diagnostics.set diagnostics (`Merlin (uri, [ no_reason_merlin ])); async (fun () -> Diagnostics.send diagnostics (`One uri)) - | Reason | Ocaml -> + | Reason | Ocaml | Mlx -> async (fun () -> let* () = Diagnostics.merlin_diagnostics diagnostics merlin in Diagnostics.send diagnostics (`One uri))) From faa56daa7beffe6bcb1c2a3a39dbc8c8d7644b7d Mon Sep 17 00:00:00 2001 From: David Sancho Moreno Date: Wed, 15 Oct 2025 21:55:55 +0800 Subject: [PATCH 14/15] Add changelog entry --- CHANGES.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index b6cb7ef52..f28bcb8f2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,10 @@ # unreleased +## Features + +- Add support for `.mlx` files, including formatting via `ocamlformat-mlx` and + most OCaml LSP features (diagnostics, code actions, hover, etc.) (#1528) + ## Fixes - Fix hover on method calls not showing the type. (#1553, fixes #1552) From 60acf9f692b5815176c0198a7bec668a51588036 Mon Sep 17 00:00:00 2001 From: David Sancho Moreno Date: Thu, 6 Nov 2025 15:59:48 +0100 Subject: [PATCH 15/15] Move mlx's changelog entry into unreleased --- CHANGES.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 4b78736ac..2fdb0bc02 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,6 +3,7 @@ ## Features - Make `code-lens` for nested let bindings configurable (#1567) +- Add support for `.mlx` files, including formatting via `ocamlformat-mlx` and most OCaml LSP features (diagnostics, code actions, hover, etc.) (#1528) ## Fixes @@ -16,11 +17,6 @@ # 1.23.1 -## Features - -- Add support for `.mlx` files, including formatting via `ocamlformat-mlx` and - most OCaml LSP features (diagnostics, code actions, hover, etc.) (#1528) - ## Fixes - Fix hover on method calls not showing the type. (#1553, fixes #1552)