Skip to content

Commit

Permalink
render optional args as ?name: type instead of name: option<type> (
Browse files Browse the repository at this point in the history
…#1297)

* render optional args as ?name: type instead of name: option<type>

* use span slicing

* adjust test
  • Loading branch information
dawedawe authored May 21, 2024
1 parent 592ed71 commit b43fe3a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/FsAutoComplete.Core/SignatureFormatter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,9 @@ module SignatureFormatter =
let safeParameterName (p: FSharpParameter) =
match Option.defaultValue p.DisplayNameCore p.Name with
| "" -> ""
| name -> FSharpKeywords.NormalizeIdentifierBackticks name
| name ->
let n = FSharpKeywords.NormalizeIdentifierBackticks name
if p.IsOptionalArg then "?" + n else n // render optional args as "?ident: type"

let padLength =
let allLengths =
Expand Down Expand Up @@ -291,6 +293,8 @@ module SignatureFormatter =

if p.Type.IsFunctionType then
$"({formatted})"
else if p.IsOptionalArg && formatted.StartsWith("option<", StringComparison.Ordinal) then // render optional args as "?ident: type"
formatted.AsSpan(7, formatted.Length - 8).ToString()
else
formatted
with :? InvalidOperationException ->
Expand Down
6 changes: 3 additions & 3 deletions test/FsAutoComplete.Tests.Lsp/CoreTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,9 @@ let tooltipTests state =
28
(concatLines
[ "static member Start:"
" body : (MailboxProcessor<string> -> Async<unit>) *"
" cancellationToken: option<System.Threading.CancellationToken>"
" -> MailboxProcessor<string>" ])
" body : (MailboxProcessor<string> -> Async<unit>) *"
" ?cancellationToken: System.Threading.CancellationToken"
" -> MailboxProcessor<string>" ])
verifySignature 54 9 "Case2 of string * newlineBefore: bool * newlineAfter: bool"
verifySignature
60
Expand Down

0 comments on commit b43fe3a

Please sign in to comment.