Skip to content

Commit

Permalink
refactor: remove uses of [Stdune.List]
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <[email protected]>

<!-- ps-id: 8cf5536e-698b-4c53-90ce-114d68a8f87a -->

Signed-off-by: Rudi Grinberg <[email protected]>
  • Loading branch information
rgrinberg committed Feb 23, 2025
1 parent b203fb4 commit c641cc3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
10 changes: 4 additions & 6 deletions ocaml-lsp-server/src/code_actions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,10 @@ let compute_ocaml_code_actions (params : CodeActionParams.t) state doc =
]
in
let batchable, non_batchable =
List.partition_map
~f:(fun ca ->
match ca.run with
| `Batchable f -> Left f
| `Non_batchable f -> Right f)
enabled_actions
List.partition_map enabled_actions ~f:(fun ca ->
match ca.run with
| `Batchable f -> Base.Either.First f
| `Non_batchable f -> Second f)
in
let* batch_results =
if List.is_empty batchable
Expand Down
25 changes: 23 additions & 2 deletions ocaml-lsp-server/src/import.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,34 @@ include struct
end

module List = struct
include Stdune.List
open Base.List
include Base.List

let compare xs ys ~compare =
Base.List.compare (fun x y -> Ordering.to_int (compare x y)) xs ys
;;

let sort xs ~compare = sort xs ~compare:(fun x y -> Ordering.to_int (compare x y))
let fold_left2 xs ys ~init ~f = Stdlib.List.fold_left2 f init xs ys
let assoc xs key = Assoc.find ~equal:Poly.equal xs key
let assoc_opt xs key = assoc xs key
let mem t x ~equal = mem t x ~equal
let map t ~f = map t ~f
let concat_map t ~f = concat_map t ~f
let flatten t = Stdlib.List.flatten t
let filter_map t ~f = filter_map t ~f
let fold_left t ~init ~f = fold_left t ~init ~f
let findi xs ~f = findi xs ~f
let find_opt xs ~f = find xs ~f

let sort_uniq xs ~compare =
Stdlib.List.sort_uniq (fun x y -> Ordering.to_int (compare x y)) xs
;;

let for_all xs ~f = for_all xs ~f
let find_mapi xs ~f = find_mapi xs ~f
let sub xs ~pos ~len = sub xs ~pos ~len
let hd_exn t = hd_exn t
let hd_opt t = hd t
let nth_exn t n = nth_exn t n
let hd t = hd t
let filter t ~f = filter t ~f
Expand Down
4 changes: 2 additions & 2 deletions ocaml-lsp-server/src/ocaml_lsp_server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ let on_request
match req with
| Client_request.UnknownRequest { meth; params } ->
(match
List.assoc
[ ( Req_switch_impl_intf.meth
, fun ~params state ->
Fiber.of_thunk (fun () ->
Expand All @@ -536,8 +537,7 @@ let on_request
, Semantic_highlighting.Debug.on_request_full )
; ( Req_hover_extended.meth
, fun ~params _ -> Req_hover_extended.on_request ~params rpc )
]
|> List.assoc_opt meth
] meth
with
| None ->
Jsonrpc.Response.Error.raise
Expand Down
4 changes: 1 addition & 3 deletions ocaml-lsp-server/src/workspace_symbol.ml
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,7 @@ let run server (state : State.t) (params : WorkspaceSymbolParams.t) =
| Error `Cancelled -> assert false
| Error (`Exn exn) -> Exn_with_backtrace.reraise exn)
in
List.partition_map symbols_results ~f:(function
| Ok r -> Left r
| Error e -> Right e)
List.partition_result symbols_results
in
let+ () =
match errors with
Expand Down

0 comments on commit c641cc3

Please sign in to comment.