From 073f6c79818c14226cc3cff227f38da1bb037385 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulysse=20G=C3=A9rard?= Date: Fri, 4 Oct 2024 12:41:49 +0200 Subject: [PATCH] Use compat lib where required --- ocaml-lsp-server/src/code_actions/action_extract.ml | 9 +++++++-- ocaml-lsp-server/src/folding_range.ml | 3 ++- ocaml-lsp-server/src/semantic_highlighting.ml | 6 ++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/ocaml-lsp-server/src/code_actions/action_extract.ml b/ocaml-lsp-server/src/code_actions/action_extract.ml index 00358f213..7946c50f4 100644 --- a/ocaml-lsp-server/src/code_actions/action_extract.ml +++ b/ocaml-lsp-server/src/code_actions/action_extract.ml @@ -1,6 +1,7 @@ open Import open Option.O module H = Ocaml_parsing.Ast_helper +module Typedtree_utils = Merlin_analysis.Typedtree_utils let range_contains_loc range loc = match Range.of_loc_opt loc with @@ -75,8 +76,12 @@ let tightest_enclosing_binder_position typedtree range = | Texp_open (_, body) -> found_if_expr_contains body | Texp_letop { body; _ } -> found_if_case_contains [ body ] | Texp_function (_, Tfunction_cases { cases; _ }) -> found_if_case_contains cases - | Texp_match (_, cases, _) -> found_if_case_contains cases - | Texp_try (_, cases) -> found_if_case_contains cases + | Texp_match _ -> + let m = Typedtree_utils.texp_match_of_expr expr |> Option.value_exn in + found_if_case_contains m.computation_cases + | Texp_try _ -> + let t = Typedtree_utils.texp_try_of_expr expr |> Option.value_exn in + found_if_case_contains t.value_cases | _ -> ()) in let structure_item_iter (iter : I.iterator) (item : Typedtree.structure_item) = diff --git a/ocaml-lsp-server/src/folding_range.ml b/ocaml-lsp-server/src/folding_range.ml index 546adf835..29d5926ba 100644 --- a/ocaml-lsp-server/src/folding_range.ml +++ b/ocaml-lsp-server/src/folding_range.ml @@ -159,7 +159,8 @@ let fold_over_parsetree (parsetree : Mreader.parsetree) = | Ppat_exception _ | Ppat_extension _ | Ppat_open _ - | Ppat_any -> Ast_iterator.default_iterator.pat self p + | Ppat_any + | _ -> Ast_iterator.default_iterator.pat self p in let expr (self : Ast_iterator.iterator) (expr : Parsetree.expression) = match expr.pexp_desc with diff --git a/ocaml-lsp-server/src/semantic_highlighting.ml b/ocaml-lsp-server/src/semantic_highlighting.ml index 622c1cdc7..b97323b7a 100644 --- a/ocaml-lsp-server/src/semantic_highlighting.ml +++ b/ocaml-lsp-server/src/semantic_highlighting.ml @@ -1,6 +1,7 @@ open Import open Fiber.O module Array_view = Lsp.Private.Array_view +module Parsetree_utils = Merlin_analysis.Parsetree_utils (* TODO: @@ -508,7 +509,7 @@ end = struct let const loc (constant : Parsetree.constant) = let token_type = - match constant with + match Parsetree_utils.constant_desc constant with | Parsetree.Pconst_integer _ | Pconst_float _ -> Token_type.of_builtin Number | Pconst_char _ | Pconst_string _ -> Token_type.of_builtin String in @@ -718,7 +719,8 @@ end = struct | Ppat_tuple _ | Ppat_lazy _ | Ppat_any - | Ppat_interval _ -> `Default_iterator + | Ppat_interval _ + | _ -> `Default_iterator with | `Default_iterator -> Ast_iterator.default_iterator.pat self pat | `Custom_iterator -> self.attributes self ppat_attributes