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

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

Merged
merged 3 commits into from
May 21, 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
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
Loading