Skip to content

Commit

Permalink
Fix parens around function types in signature help (#1296)
Browse files Browse the repository at this point in the history
  • Loading branch information
awilliambauer authored Jun 6, 2024
1 parent 2408b8a commit b43f98d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@

- Stop generating inlay hints on generated code (#1290)

- Fix parenthesizing of function types in `SignatureHelp` (#1296)

# 1.17.0

## Fixes
Expand Down
12 changes: 9 additions & 3 deletions ocaml-lsp-server/src/signature_help.ml
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,17 @@ let pp_type env ppf ty =
Printtyp.wrap_printing_env env ~verbosity:(Lvl 0) (fun () ->
Printtyp.shared_type_scheme ppf ty)

let rec type_is_arrow ty =
match Types.get_desc ty with
| Tarrow _ -> true
| Tlink ty -> type_is_arrow ty
| Tpoly (ty, _) -> type_is_arrow ty
| _ -> false

(* surround function types in parentheses *)
let pp_parameter_type env ppf ty =
match Types.get_desc ty with
| Tarrow _ -> Format.fprintf ppf "(%a)" (pp_type env) ty
| _ -> pp_type env ppf ty
if type_is_arrow ty then Format.fprintf ppf "(%a)" (pp_type env) ty
else pp_type env ppf ty

(* print parameter labels and types *)
let pp_parameter env label ppf ty =
Expand Down

0 comments on commit b43f98d

Please sign in to comment.