Skip to content

Commit ad5d25b

Browse files
smorimotoCopilot
andauthored
Standardise file extension ordering and add missing MLX command support (#1999)
* Add support for `*.mlx` in `activationEvents` of package.json Signed-off-by: Sora Morimoto <[email protected]> * Standardise file extension and language ID ordering Reorder file extensions and language IDs consistently to follow: `ml`, `mli`, `mll`, `mly`, `mlx`, `re`, `rei`. This ensures consistent ordering across keybindings, menus, language server configuration, and source code pattern matching. Signed-off-by: Sora Morimoto <[email protected]> * Add `ocaml.mlx` support to construct, `jump` and `search-by-type` commands Add `ocaml.mlx` language validation to `is_valid_text_doc` functions in `Construct`, `MerlinJump` and `Search_by_type` modules. This ensures these commands work correctly with MLX files. Also update error messages to include mlx files in the list of supported file types, matching the updated validation logic. Signed-off-by: Sora Morimoto <[email protected]> * Update CHANGELOG.md Signed-off-by: Sora Morimoto <[email protected]> * Use Filename.extension with pattern matching for extension check Replace multiple `String.is_suffix` checks with a single pattern match on `Filename.extension` to check for `.ml`, `.mlx`, and `.re` extensions. Signed-off-by: Sora Morimoto <[email protected]> * Correct comment in `insert_inferred_intf` Signed-off-by: Sora Morimoto <[email protected]> * Update CHANGELOG.md Co-authored-by: Copilot <[email protected]> * Update CHANGELOG.md Signed-off-by: Sora Morimoto <[email protected]> --------- Signed-off-by: Sora Morimoto <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent b703c47 commit ad5d25b

File tree

6 files changed

+57
-50
lines changed

6 files changed

+57
-50
lines changed

CHANGELOG.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,20 @@
22

33
## Unreleased
44

5-
- Add mlx language support to document selector
6-
- Enable AST editor for mlx files
7-
- Enable switching between implementation and interface for mlx files
8-
- Add keybindings for OCaml.mlx language
5+
- Add `ocaml.mlx` language support to document selector. (#1964)
6+
- Enable AST editor for MLX files. (#1964)
7+
- Enable switching between implementation and interface for MLX files. (#1964)
8+
- Add keybindings for `ocaml.mlx` language. (#1964)
9+
- Standardise file extension and language ID ordering across all configuration
10+
and source files. All comprehensive lists now follow the canonical order:
11+
`.ml`, `.mli`, `.mll`, `.mly`, `.mlx`, `.re`, `.rei`. When only a subset of
12+
extensions is relevant (e.g., in pattern matches), the same relative order is
13+
used, but some extensions may be omitted as appropriate. This affects activation
14+
events, keybindings, menus, language server configuration and pattern matching. (#1999)
15+
- Add `.mlx` workspace detection to `activationEvents` to ensure the extension
16+
activates when MLX files are present in the workspace. (#1999)
17+
- Add `ocaml.mlx` language support to `construct`, `jump` and `search-by-type`
18+
commands. These commands now correctly validate and work with MLX files. (#1999)
919

1020
## 1.32.4
1121

package.json

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -785,54 +785,54 @@
785785
{
786786
"command": "ocaml.switch-impl-intf",
787787
"key": "Alt+O",
788-
"when": "editorTextFocus && (editorLangId == ocaml || editorLangId == ocaml.interface || editorLangId == reason || editorLangId == ocaml.mlx)"
788+
"when": "editorTextFocus && (editorLangId == ocaml || editorLangId == ocaml.interface || editorLangId == ocaml.mlx || editorLangId == reason)"
789789
},
790790
{
791791
"command": "editor.action.codeAction",
792792
"key": "Alt+D",
793793
"args": {
794794
"kind": "destruct (enumerate cases)"
795795
},
796-
"when": "editorTextFocus && (editorLangId == ocaml || editorLangId == reason || editorLangId == ocaml.mlx)"
796+
"when": "editorTextFocus && (editorLangId == ocaml || editorLangId == ocaml.mlx || editorLangId == reason)"
797797
},
798798
{
799799
"command": "ocaml.construct",
800800
"key": "Alt+C",
801801
"args": {
802802
"kind": "construct"
803803
},
804-
"when": "editorTextFocus && (editorLangId == ocaml || editorLangId == reason || editorLangId == ocaml.mlx)"
804+
"when": "editorTextFocus && (editorLangId == ocaml || editorLangId == ocaml.mlx || editorLangId == reason)"
805805
},
806806
{
807807
"command": "ocaml.jump",
808808
"key": "Alt+J",
809809
"args": {
810810
"kind": "jump"
811811
},
812-
"when": "editorTextFocus && (editorLangId == ocaml || editorLangId == ocaml.interface || editorLangId == reason || editorLangId == ocaml.mlx)"
812+
"when": "editorTextFocus && (editorLangId == ocaml || editorLangId == ocaml.interface || editorLangId == ocaml.mlx || editorLangId == reason)"
813813
},
814814
{
815815
"command": "editor.action.codeAction",
816816
"key": "Alt+P",
817817
"args": {
818818
"kind": "inferred_intf"
819819
},
820-
"when": "editorTextFocus && (editorLangId == ocaml.interface || editorLangId == reason || editorLangId == ocaml.mlx)"
820+
"when": "editorTextFocus && (editorLangId == ocaml.interface || editorLangId == ocaml.mlx || editorLangId == reason)"
821821
},
822822
{
823823
"command": "ocaml.evaluate-selection",
824824
"key": "Shift+Enter",
825-
"when": "editorTextFocus && (editorLangId == ocaml || editorLangId == ocaml.interface || editorLangId == reason || editorLangId == ocaml.mlx)"
825+
"when": "editorTextFocus && (editorLangId == ocaml || editorLangId == ocaml.interface || editorLangId == ocaml.mlx || editorLangId == reason)"
826826
},
827827
{
828828
"command": "ocaml.next-hole",
829829
"key": "Alt+Y",
830-
"when": "editorTextFocus && (editorLangId == ocaml || editorLangId == ocaml.interface || editorLangId == reason || editorLangId == ocaml.ocamllex || editorLangId == ocaml.mlx)"
830+
"when": "editorTextFocus && (editorLangId == ocaml || editorLangId == ocaml.interface || editorLangId == ocaml.ocamllex || editorLangId == ocaml.mlx || editorLangId == reason)"
831831
},
832832
{
833833
"command": "ocaml.prev-hole",
834834
"key": "Shift+Alt+Y",
835-
"when": "editorTextFocus && (editorLangId == ocaml || editorLangId == ocaml.interface || editorLangId == reason || editorLangId == ocaml.ocamllex || editorLangId == ocaml.mlx)"
835+
"when": "editorTextFocus && (editorLangId == ocaml || editorLangId == ocaml.interface || editorLangId == ocaml.ocamllex || editorLangId == ocaml.mlx || editorLangId == reason)"
836836
},
837837
{
838838
"command": "ocaml.reveal-ast-node",
@@ -847,7 +847,7 @@
847847
{
848848
"command": "ocaml.search-by-type",
849849
"key": "Alt+F",
850-
"when": "editorTextFocus && (editorLangId == ocaml || editorLangId == ocaml.interface || editorLangId == reason || editorLangId == ocaml.mlx)"
850+
"when": "editorTextFocus && (editorLangId == ocaml || editorLangId == ocaml.interface || editorLangId == ocaml.mlx || editorLangId == reason)"
851851
},
852852
{
853853
"command": "ocaml.type-selection",
@@ -1039,13 +1039,13 @@
10391039
"configuration": "./languages/menhir.json"
10401040
},
10411041
{
1042-
"id": "atd",
1042+
"id": "ocaml.mlx",
10431043
"aliases": [
1044-
"ATD",
1045-
"atd"
1044+
"OCaml.mlx",
1045+
"ocaml.mlx"
10461046
],
10471047
"extensions": [
1048-
".atd"
1048+
".mlx"
10491049
],
10501050
"configuration": "./languages/ocaml.json"
10511051
},
@@ -1061,6 +1061,17 @@
10611061
],
10621062
"configuration": "./languages/reason.json"
10631063
},
1064+
{
1065+
"id": "atd",
1066+
"aliases": [
1067+
"ATD",
1068+
"atd"
1069+
],
1070+
"extensions": [
1071+
".atd"
1072+
],
1073+
"configuration": "./languages/ocaml.json"
1074+
},
10641075
{
10651076
"id": "cram",
10661077
"aliases": [
@@ -1071,25 +1082,14 @@
10711082
"extensions": [
10721083
".t"
10731084
]
1074-
},
1075-
{
1076-
"id": "ocaml.mlx",
1077-
"aliases": [
1078-
"OCaml.mlx",
1079-
"ocaml.mlx"
1080-
],
1081-
"extensions": [
1082-
".mlx"
1083-
],
1084-
"configuration": "./languages/ocaml.json"
10851085
}
10861086
],
10871087
"menus": {
10881088
"editor/context": [
10891089
{
10901090
"command": "ocaml.evaluate-selection",
10911091
"group": "OCaml",
1092-
"when": "editorTextFocus && (editorLangId == ocaml || editorLangId == ocaml.interface || editorLangId == reason || editorLangId == ocaml.mlx)"
1092+
"when": "editorTextFocus && (editorLangId == ocaml || editorLangId == ocaml.interface || editorLangId == ocaml.mlx || editorLangId == reason)"
10931093
},
10941094
{
10951095
"command": "ocaml.reveal-ast-node",
@@ -1104,11 +1104,11 @@
11041104
},
11051105
{
11061106
"command": "ocaml.next-hole",
1107-
"when": "editorTextFocus && (editorLangId == ocaml || editorLangId == ocaml.interface || editorLangId == reason || editorLangId == ocaml.mlx)"
1107+
"when": "editorTextFocus && (editorLangId == ocaml || editorLangId == ocaml.interface || editorLangId == ocaml.mlx || editorLangId == reason)"
11081108
},
11091109
{
11101110
"command": "ocaml.prev-hole",
1111-
"when": "editorTextFocus && (editorLangId == ocaml || editorLangId == ocaml.interface || editorLangId == reason || editorLangId == ocaml.mlx)"
1111+
"when": "editorTextFocus && (editorLangId == ocaml || editorLangId == ocaml.interface || editorLangId == ocaml.mlx || editorLangId == reason)"
11121112
},
11131113
{
11141114
"command": "ocaml.refresh-switches",
@@ -1168,7 +1168,7 @@
11681168
},
11691169
{
11701170
"command": "ocaml.search-by-type",
1171-
"when": "editorLangId == ocaml || editorLangId == ocaml.interface || editorLangId == reason || editorLangId == ocaml.mlx"
1171+
"when": "editorLangId == ocaml || editorLangId == ocaml.interface || editorLangId == ocaml.mlx || editorLangId == reason"
11721172
},
11731173
{
11741174
"command": "ocaml.navigate-typed-holes",
@@ -1179,7 +1179,7 @@
11791179
{
11801180
"command": "ocaml.switch-impl-intf",
11811181
"key": "Alt+O",
1182-
"when": "editorTextFocus && (editorLangId == ocaml || editorLangId == ocaml.interface || editorLangId == reason || editorLangId == ocaml.mlx)",
1182+
"when": "editorTextFocus && (editorLangId == ocaml || editorLangId == ocaml.interface || editorLangId == ocaml.mlx || editorLangId == reason)",
11831183
"group": "navigation"
11841184
}
11851185
],
@@ -1341,6 +1341,7 @@
13411341
"workspaceContains:**/*.mli",
13421342
"workspaceContains:**/*.mll",
13431343
"workspaceContains:**/*.mly",
1344+
"workspaceContains:**/*.mlx",
13441345
"workspaceContains:**/*.re",
13451346
"workspaceContains:**/*.rei",
13461347
"onDebugResolve:ocaml.earlybird"

src/ast_editor.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ end = struct
6767
let relative = relative_document_path ~document in
6868
match Stdlib.Filename.extension relative with
6969
| ".ml" -> Structure `Ocaml
70-
| ".re" -> Structure `Reason
71-
| ".mlx" -> Structure `Ocaml
7270
| ".mli" -> Signature `Ocaml
71+
| ".mlx" -> Structure `Ocaml
72+
| ".re" -> Structure `Reason
7373
| ".rei" -> Signature `Reason
7474
| _ -> Unknown
7575
;;

src/extension_commands.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ module Construct = struct
661661

662662
let is_valid_text_doc textdoc =
663663
match TextDocument.languageId textdoc with
664-
| "ocaml" | "ocaml.interface" | "reason" | "ocaml.ocamllex" -> true
664+
| "ocaml" | "ocaml.interface" | "ocaml.ocamllex" | "ocaml.mlx" | "reason" -> true
665665
| _ -> false
666666
;;
667667

@@ -738,7 +738,7 @@ module Construct = struct
738738
show_message
739739
`Error
740740
"Invalid file type. This command only works in ocaml files, ocaml interface \
741-
files, reason files or ocamllex files."
741+
files, ocamllex files, mlx files or reason files."
742742
| Some text_editor ->
743743
(match Extension_instance.lsp_client instance with
744744
| None -> show_message `Warn "ocamllsp is not running"
@@ -765,7 +765,7 @@ module MerlinJump = struct
765765

766766
let is_valid_text_doc textdoc =
767767
match TextDocument.languageId textdoc with
768-
| "ocaml" | "ocaml.interface" | "reason" | "ocaml.ocamllex" -> true
768+
| "ocaml" | "ocaml.interface" | "ocaml.ocamllex" | "ocaml.mlx" | "reason" -> true
769769
| _ -> false
770770
;;
771771

@@ -931,7 +931,7 @@ module MerlinJump = struct
931931
show_message
932932
`Error
933933
"Invalid file type. This command only works in ocaml files, ocaml interface \
934-
files or reason files."
934+
files, ocamllex files, mlx files or reason files."
935935
| Some text_editor ->
936936
(match Extension_instance.lsp_client instance with
937937
| None -> show_message `Warn "ocamllsp is not running"
@@ -958,7 +958,7 @@ module Search_by_type = struct
958958

959959
let is_valid_text_doc textdoc =
960960
match TextDocument.languageId textdoc with
961-
| "ocaml" | "ocaml.interface" | "reason" | "ocaml.ocamllex" -> true
961+
| "ocaml" | "ocaml.interface" | "ocaml.ocamllex" | "ocaml.mlx" | "reason" -> true
962962
| _ -> false
963963
;;
964964

@@ -1135,7 +1135,7 @@ module Search_by_type = struct
11351135
show_message
11361136
`Error
11371137
"Invalid file type. This command only works in ocaml files, ocaml interface \
1138-
files, reason files or ocamllex files."
1138+
files, ocamllex files, mlx files or reason files."
11391139
| Some text_editor ->
11401140
(match Extension_instance.lsp_client instance with
11411141
| None -> show_message `Warn "ocamllsp is not running"

src/extension_instance.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ end = struct
168168
; language "ocaml.interface"
169169
; language "ocaml.ocamllex"
170170
; language "ocaml.menhir"
171-
; language "reason"
172171
; language "ocaml.mlx"
172+
; language "reason"
173173
|]
174174
in
175175
let (lazy outputChannel) = Output.language_server_output_channel in

src/switch_impl_intf.ml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,9 @@ open Import
22

33
let insert_inferred_intf ~source_uri client text_editor =
44
let open Promise.Syntax in
5-
match
6-
String.is_suffix source_uri ~suffix:".ml"
7-
|| String.is_suffix source_uri ~suffix:".re"
8-
|| String.is_suffix source_uri ~suffix:".mlx"
9-
with
10-
| false -> Promise.return ()
11-
| true ->
12-
(* If the source file was a .ml or .re, infer the interface *)
5+
match Stdlib.Filename.extension source_uri with
6+
| ".ml" | ".mlx" | ".re" ->
7+
(* If the source file was a .ml, .mlx or .re, infer the interface *)
138
let* inferred_intf =
149
Custom_requests.send_request client Custom_requests.inferIntf source_uri
1510
in
@@ -24,6 +19,7 @@ let insert_inferred_intf ~source_uri client text_editor =
2419
()
2520
in
2621
if not edit_applied then show_message `Error "Unable to insert inferred interface"
22+
| _ -> Promise.return ()
2723
;;
2824

2925
let request_switch client document =

0 commit comments

Comments
 (0)