Skip to content

Commit cb2f2be

Browse files
committed
update formatting and align test cases
1 parent 88e4b3a commit cb2f2be

File tree

4 files changed

+30
-39
lines changed

4 files changed

+30
-39
lines changed

src/FsAutoComplete.Core/DocumentationFormatter.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ module DocumentationFormatter =
309309
if String.IsNullOrWhiteSpace formattedParam then
310310
formattedParam
311311
else
312-
"(requires " + formattedParam + " )"
312+
"(requires " + formattedParam + ")"
313313
else
314314
""
315315

@@ -379,7 +379,7 @@ module DocumentationFormatter =
379379
if String.IsNullOrWhiteSpace formattedParam then
380380
formattedParam
381381
else
382-
"(requires " + formattedParam + " )"
382+
"(requires " + formattedParam + ")"
383383

384384
if paramConstraint = retTypeConstraint then
385385
paddedParam

src/FsAutoComplete.Core/SignatureFormatter.fs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ module SignatureFormatter =
4242

4343
let rec formatFSharpType (context: FSharpDisplayContext) (typ: FSharpType) : string =
4444
let context = context.WithPrefixGenericParameters()
45-
45+
let nullabilityClause = if typ.HasNullAnnotation || typ.IsNullAmbivalent then " | null" else ""
4646
try
47-
if typ.IsTupleType || typ.IsStructTupleType then
47+
if typ.IsTupleType || typ.IsStructTupleType
48+
then
4849
let refTupleStr =
4950
typ.GenericArguments
5051
|> Seq.map (fun arg ->
@@ -59,7 +60,7 @@ module SignatureFormatter =
5960
else
6061
refTupleStr
6162
elif typ.IsGenericParameter then // no longer need to differentiate between SRTP and normal generic parameter types
62-
"'" + typ.GenericParameter.Name
63+
"'" + typ.GenericParameter.Name + nullabilityClause
6364
elif typ.HasTypeDefinition && typ.GenericArguments.Count > 0 then
6465
let typeDef = typ.TypeDefinition
6566

@@ -68,19 +69,19 @@ module SignatureFormatter =
6869

6970
if entityIsArray typeDef then
7071
if typ.GenericArguments.Count = 1 && typ.GenericArguments.[0].IsTupleType then
71-
sprintf "(%s) array" genericArgs
72+
$"(%s{genericArgs}) array%s{nullabilityClause}"
7273
else
73-
sprintf "%s array" genericArgs
74+
$"%s{genericArgs} array%s{nullabilityClause}"
7475
elif isMeasureType typeDef then
75-
typ.Format context
76+
typ.Format context + nullabilityClause
7677
else
77-
sprintf "%s<%s>" (FSharpKeywords.NormalizeIdentifierBackticks typeDef.DisplayName) genericArgs
78+
$"%s{FSharpKeywords.NormalizeIdentifierBackticks typeDef.DisplayName}<%s{genericArgs}>%s{nullabilityClause}"
7879
else if typ.HasTypeDefinition then
79-
FSharpKeywords.NormalizeIdentifierBackticks typ.TypeDefinition.DisplayName
80+
FSharpKeywords.NormalizeIdentifierBackticks typ.TypeDefinition.DisplayName + nullabilityClause
8081
else
81-
typ.Format context
82+
typ.Format context + nullabilityClause
8283
with _ ->
83-
typ.Format context
84+
typ.Format context + nullabilityClause
8485

8586
let formatGenericParameter includeMemberConstraintTypes displayContext (param: FSharpGenericParameter) =
8687

@@ -357,7 +358,7 @@ module SignatureFormatter =
357358
if String.IsNullOrWhiteSpace formattedParam then
358359
formattedParam
359360
else
360-
"(requires " + formattedParam + " )"
361+
"(requires " + formattedParam + ")"
361362

362363
if paramConstraint = retTypeConstraint then
363364
paramFormat

test/FsAutoComplete.Tests.Lsp/CoreTests.fs

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,8 @@ let tooltipTests state =
523523
13u
524524
(concatLines
525525
[ "val inline add:"
526-
" x: 'a (requires static member ( + ) ) ->"
527-
" y: 'b (requires static member ( + ) )"
526+
" x: 'a (requires static member ( + )) ->"
527+
" y: 'b (requires static member ( + ))"
528528
" -> 'c" ])
529529
//verify rendering of solved generic constraints in tooltips for members where they are solved
530530
verifyDescription "solved generic parameters are called out in tooltip"
@@ -548,15 +548,9 @@ let tooltipTests state =
548548
60u
549549
7u
550550
(concatLines
551-
#if NET8_0
552-
[ "active pattern Value: "
553-
" input: Expr"
554-
" -> option<obj * System.Type>" ])
555-
#else
556551
[ "active pattern Value: "
557552
" input: Expr"
558553
" -> option<objnull * System.Type>" ])
559-
#endif
560554
verifySignature "generic constraint rendering for IWSAM"
561555
77u
562556
5u
@@ -570,7 +564,7 @@ let tooltipTests state =
570564
25u
571565
(concatLines [
572566
"static member GetAwaiter:"
573-
" awaitable: 'Awaitable (requires member GetAwaiter )"
567+
" awaitable: 'Awaitable (requires member GetAwaiter)"
574568
" -> Awaiter<^Awaiter,'TResult> (requires :> ICriticalNotifyCompletion and member IsCompleted and member GetResult)"
575569
])
576570
verifySignature "basic active pattern"
@@ -584,47 +578,41 @@ let tooltipTests state =
584578
70u
585579
7u
586580
(concatLines
587-
#if NET8_0
588-
[ "active pattern ValueWithName: "
589-
" input: Expr"
590-
" -> option<obj * System.Type * string>" ])
591-
#else
592581
[ "active pattern ValueWithName: "
593582
" input: Expr"
594583
" -> option<objnull * System.Type * string>" ])
595-
#endif
596584
verifySignature "interface with members with and without parameter names"
597585
96u
598586
7u
599587
(concatLines
600588
[ "interface IWithAndWithoutParamNames"
601589
" abstract member WithParamNames: arg1: int * arg2: float -> string"
602590
" abstract member WithoutParamNames: int * string -> int" ])
603-
verifySignature "function with unsolved nullable parameter" 100u 7u (concatLines [
591+
verifySignature "function with unsolved nullable parameter" 102u 7u (concatLines [
604592
"val usesNullable:"
605-
" x: 't | null"
606-
" -> 't (requires reference )"
593+
" x: 't | null"
594+
" -> 't (requires reference)"
607595
])
608596

609-
verifySignature "function with concrete nullable parameter" 101u 7u (concatLines [
597+
verifySignature "function with concrete nullable parameter" 103u 7u (concatLines [
610598
"val usesConcreteNullable:"
611599
" x: string | null"
612-
" -> String (requires reference )"
600+
" -> String"
613601
])
614-
verifySignature "function with generic nullable return" 102u 7u (concatLines [
602+
verifySignature "function with generic nullable return" 104u 7u (concatLines [
615603
"val makesNullable:"
616-
" x: 'x (requires reference)"
617-
" -> 'x | null"
604+
" x: 'x"
605+
" -> 'x | null (requires reference)"
618606
])
619-
verifySignature "function with concrete nullable return" 103u 7u (concatLines [
607+
verifySignature "function with concrete nullable return" 105u 7u (concatLines [
620608
"val makesConcreteNullable:"
621609
" x: string"
622610
" -> string | null"
623611
])
624-
verifySignature "function with nullable return from BCL call" 104u 7u (concatLines [
612+
verifySignature "function with nullable return from BCL call" 106u 7u (concatLines [
625613
"val usesBCLNullable:"
626614
" key: string"
627-
" -> string | null"
615+
" -> string | null"
628616
])] ]
629617

630618
let closeTests state =

test/FsAutoComplete.Tests.Lsp/TestCases/Tooltips/Script.fsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ type IWithAndWithoutParamNames =
9898
abstract member WithParamNames : arg1: int * arg2: float -> string
9999
abstract member WithoutParamNames : int * string -> int
100100

101+
#nullable enable
102+
101103
let usesNullable (x: 't | null) = nonNull x
102104
let usesConcreteNullable (x: string | null) = nonNull x
103105
let makesNullable (x: 'x): 'x | null = null

0 commit comments

Comments
 (0)