Skip to content

Commit 07ba12b

Browse files
authored
fix: update DocumentSelector definition (#1068)
Signed-off-by: Rudi Grinberg <[email protected]>
1 parent 829f1b2 commit 07ba12b

File tree

6 files changed

+12
-87
lines changed

6 files changed

+12
-87
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
([#1049](https://github.com/ocaml/ocaml-lsp/pull/1049), fixes
2020
[#1034](https://github.com/ocaml/ocaml-lsp/issues/1034))
2121

22+
- Fix the type of DocumentSelector in cram document registration (#1068)
23+
2224
## Features
2325
- Add "Remove type annotation" code action. (#1039)
2426

lsp/bin/metamodel/metaModel.json

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13917,17 +13917,8 @@
1391713917
"type": {
1391813918
"kind": "array",
1391913919
"element": {
13920-
"kind": "or",
13921-
"items": [
13922-
{
13923-
"kind": "base",
13924-
"name": "string"
13925-
},
13926-
{
13927-
"kind": "reference",
13928-
"name": "DocumentFilter"
13929-
}
13930-
]
13920+
"kind": "reference",
13921+
"name": "DocumentFilter"
1393113922
}
1393213923
},
1393313924
"documentation": "A document selector is the combination of one or many document filters.\n\n@sample `let sel:DocumentSelector = [{ language: 'typescript' }, { language: 'json', pattern: '**∕tsconfig.json' }]`;\n\nThe use of a string as a document filter is deprecated @since 3.16.0.",

lsp/src/types.ml

Lines changed: 3 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -4878,85 +4878,19 @@ module DocumentFilter = struct
48784878
end
48794879

48804880
module DocumentSelector = struct
4881-
type t = [ `String of string | `DocumentFilter of DocumentFilter.t ] list
4882-
[@@deriving_inline yojson]
4881+
type t = DocumentFilter.t list [@@deriving_inline yojson]
48834882

48844883
let _ = fun (_ : t) -> ()
48854884

48864885
let t_of_yojson =
48874886
(let _tp_loc = "lsp/src/types.ml.DocumentSelector.t" in
4888-
fun t ->
4889-
list_of_yojson
4890-
(fun yojson ->
4891-
try
4892-
match yojson with
4893-
| `List [ `String atom ] as _yojson -> (
4894-
match atom with
4895-
| "String" ->
4896-
Ppx_yojson_conv_lib.Yojson_conv_error.ptag_takes_args
4897-
_tp_loc
4898-
_yojson
4899-
| "DocumentFilter" ->
4900-
Ppx_yojson_conv_lib.Yojson_conv_error.ptag_takes_args
4901-
_tp_loc
4902-
_yojson
4903-
| _ -> Ppx_yojson_conv_lib.Yojson_conv_error.no_variant_match ())
4904-
| `List (`String atom :: yojson_args) as _yojson -> (
4905-
match atom with
4906-
| "String" as _tag -> (
4907-
match yojson_args with
4908-
| [ v0 ] ->
4909-
let v0 = string_of_yojson v0 in
4910-
`String v0
4911-
| _ ->
4912-
Ppx_yojson_conv_lib.Yojson_conv_error.ptag_incorrect_n_args
4913-
_tp_loc
4914-
_tag
4915-
_yojson)
4916-
| "DocumentFilter" as _tag -> (
4917-
match yojson_args with
4918-
| [ v0 ] ->
4919-
let v0 = DocumentFilter.t_of_yojson v0 in
4920-
`DocumentFilter v0
4921-
| _ ->
4922-
Ppx_yojson_conv_lib.Yojson_conv_error.ptag_incorrect_n_args
4923-
_tp_loc
4924-
_tag
4925-
_yojson)
4926-
| _ -> Ppx_yojson_conv_lib.Yojson_conv_error.no_variant_match ())
4927-
| `List (`List _ :: _) as yojson ->
4928-
Ppx_yojson_conv_lib.Yojson_conv_error
4929-
.nested_list_invalid_poly_var
4930-
_tp_loc
4931-
yojson
4932-
| `List [] as yojson ->
4933-
Ppx_yojson_conv_lib.Yojson_conv_error.empty_list_invalid_poly_var
4934-
_tp_loc
4935-
yojson
4936-
| _ as yojson ->
4937-
Ppx_yojson_conv_lib.Yojson_conv_error.unexpected_stag
4938-
_tp_loc
4939-
yojson
4940-
with Ppx_yojson_conv_lib.Yojson_conv_error.No_variant_match ->
4941-
Ppx_yojson_conv_lib.Yojson_conv_error.no_matching_variant_found
4942-
_tp_loc
4943-
yojson)
4944-
t
4887+
fun t -> list_of_yojson DocumentFilter.t_of_yojson t
49454888
: Ppx_yojson_conv_lib.Yojson.Safe.t -> t)
49464889

49474890
let _ = t_of_yojson
49484891

49494892
let yojson_of_t =
4950-
(fun v ->
4951-
yojson_of_list
4952-
(function
4953-
| `String v0 ->
4954-
let v0 = yojson_of_string v0 in
4955-
`List [ `String "String"; v0 ]
4956-
| `DocumentFilter v0 ->
4957-
let v0 = DocumentFilter.yojson_of_t v0 in
4958-
`List [ `String "DocumentFilter"; v0 ])
4959-
v
4893+
(fun v -> yojson_of_list DocumentFilter.yojson_of_t v
49604894
: t -> Ppx_yojson_conv_lib.Yojson.Safe.t)
49614895

49624896
let _ = yojson_of_t

lsp/src/types.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ module DocumentFilter : sig
839839
end
840840

841841
module DocumentSelector : sig
842-
type t = [ `String of string | `DocumentFilter of DocumentFilter.t ] list
842+
type t = DocumentFilter.t list
843843

844844
include Json.Jsonable.S with type t := t
845845
end

ocaml-lsp-server/src/document_store.ml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,8 @@ let register_request t uris =
7575
let id = code_action_id uri in
7676
let registerOptions =
7777
let documentSelector =
78-
[ `DocumentFilter
79-
(`TextDocumentFilter
80-
(TextDocumentFilter.create ~pattern:(Uri.to_path uri) ()))
78+
[ `TextDocumentFilter
79+
(TextDocumentFilter.create ~pattern:(Uri.to_path uri) ())
8180
]
8281
in
8382
CodeActionRegistrationOptions.create

ocaml-lsp-server/src/ocaml_lsp_server.ml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,8 @@ let on_initialize server (ip : InitializeParams.t) =
288288
let documentSelector =
289289
[ "cram"; "dune"; "dune-project"; "dune-workspace" ]
290290
|> List.map ~f:(fun language ->
291-
`DocumentFilter
292-
(`TextDocumentFilter
293-
(TextDocumentFilter.create ~language ())))
291+
`TextDocumentFilter
292+
(TextDocumentFilter.create ~language ()))
294293
in
295294
TextDocumentRegistrationOptions.create ~documentSelector ()
296295
|> TextDocumentRegistrationOptions.yojson_of_t

0 commit comments

Comments
 (0)