Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parens around function types in signature help #1296

Merged
merged 3 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading