Skip to content

Commit 56f1940

Browse files
committed
format the signature help to improve the readability
1 parent e46d676 commit 56f1940

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

ocaml-lsp-server/src/signature_help.ml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,19 @@ let run (state : State.t) { SignatureHelpParams.textDocument = { uri }; position
6363
sprintf "%s : " fun_name
6464
in
6565
let offset = String.length prefix in
66-
let+ doc =
66+
let* doc =
6767
Document.Merlin.doc_comment
6868
~name:"signature help-position"
6969
merlin
7070
application_signature.function_position
7171
in
72+
let+ formatted_signature =
73+
let typ = application_signature.signature in
74+
let* result = Ocamlformat_rpc.format_type state.ocamlformat_rpc ~typ in
75+
match result with
76+
| Ok v -> Fiber.return (String.trim v)
77+
| Error _ -> Fiber.return typ
78+
in
7279
let info =
7380
let parameters =
7481
List.map
@@ -90,7 +97,7 @@ let run (state : State.t) { SignatureHelpParams.textDocument = { uri }; position
9097
in
9198
format_doc ~markdown ~doc
9299
in
93-
let label = prefix ^ application_signature.signature in
100+
let label = prefix ^ formatted_signature in
94101
SignatureInformation.create ~label ?documentation ~parameters ()
95102
in
96103
SignatureHelp.create

ocaml-lsp-server/test/e2e-new/signature_help.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ let _ : int = f
3737
"activeSignature": 0,
3838
"signatures": [
3939
{
40-
"label": "f : int -> int -> int -> int -> int -> int -> int -> int -> int -> int",
40+
"label": "f : int ->\nint ->\nint ->\nint ->\nint ->\nint ->\nint ->\nint ->\nint ->\nint",
4141
"parameters": [
4242
{ "label": [ 4, 7 ] },
4343
{ "label": [ 11, 14 ] },

0 commit comments

Comments
 (0)