From 5f22dc7ad9bbbcb0066167fdf7cf715b066b1594 Mon Sep 17 00:00:00 2001 From: dawe Date: Fri, 17 May 2024 21:45:27 +0200 Subject: [PATCH 1/3] render optional args as ?name: type instead of name: option --- src/FsAutoComplete.Core/SignatureFormatter.fs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/FsAutoComplete.Core/SignatureFormatter.fs b/src/FsAutoComplete.Core/SignatureFormatter.fs index 476321d2e..c9331e1cf 100644 --- a/src/FsAutoComplete.Core/SignatureFormatter.fs +++ b/src/FsAutoComplete.Core/SignatureFormatter.fs @@ -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 = @@ -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.Substring(7).TrimEnd('>') else formatted with :? InvalidOperationException -> From 23dae2b00c9024febd052a0379e1c69e5c25839c Mon Sep 17 00:00:00 2001 From: dawe Date: Fri, 17 May 2024 22:50:26 +0200 Subject: [PATCH 2/3] use span slicing --- src/FsAutoComplete.Core/SignatureFormatter.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FsAutoComplete.Core/SignatureFormatter.fs b/src/FsAutoComplete.Core/SignatureFormatter.fs index c9331e1cf..d78fb002b 100644 --- a/src/FsAutoComplete.Core/SignatureFormatter.fs +++ b/src/FsAutoComplete.Core/SignatureFormatter.fs @@ -294,7 +294,7 @@ 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.Substring(7).TrimEnd('>') + formatted.AsSpan(7, formatted.Length - 8).ToString() else formatted with :? InvalidOperationException -> From 725f4eee74b58653dd60b38c3fda2e5fad6a61b0 Mon Sep 17 00:00:00 2001 From: dawe Date: Fri, 17 May 2024 23:13:05 +0200 Subject: [PATCH 3/3] adjust test --- test/FsAutoComplete.Tests.Lsp/CoreTests.fs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/FsAutoComplete.Tests.Lsp/CoreTests.fs b/test/FsAutoComplete.Tests.Lsp/CoreTests.fs index 19ae26e60..433a24d6d 100644 --- a/test/FsAutoComplete.Tests.Lsp/CoreTests.fs +++ b/test/FsAutoComplete.Tests.Lsp/CoreTests.fs @@ -377,9 +377,9 @@ let tooltipTests state = 28 (concatLines [ "static member Start:" - " body : (MailboxProcessor -> Async) *" - " cancellationToken: option" - " -> MailboxProcessor" ]) + " body : (MailboxProcessor -> Async) *" + " ?cancellationToken: System.Threading.CancellationToken" + " -> MailboxProcessor" ]) verifySignature 54 9 "Case2 of string * newlineBefore: bool * newlineAfter: bool" verifySignature 60