Skip to content

Commit de0b1ec

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

File tree

5 files changed

+34
-37
lines changed

5 files changed

+34
-37
lines changed

src/FsAutoComplete.Core/AbstractClassStubGenerator.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ let tryFindAbstractClassExprInBufferAtPos
5454

5555
let allMembers = reprMembers @ members
5656

57-
let! inheritType, inheritMemberRange = // this must exist for abstract types
57+
let! inheritType, inheritMemberRange =
5858
allMembers
5959
|> List.tryPick (function
6060
| SynMemberDefn.ImplicitInherit(inheritType, _, _, range) -> Some(inheritType, range)

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: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ module SignatureFormatter =
4343
let rec formatFSharpType (context: FSharpDisplayContext) (typ: FSharpType) : string =
4444
let context = context.WithPrefixGenericParameters()
4545

46+
let nullabilityClause =
47+
if typ.HasNullAnnotation || typ.IsNullAmbivalent then
48+
" | null"
49+
else
50+
""
51+
4652
try
4753
if typ.IsTupleType || typ.IsStructTupleType then
4854
let refTupleStr =
@@ -59,7 +65,7 @@ module SignatureFormatter =
5965
else
6066
refTupleStr
6167
elif typ.IsGenericParameter then // no longer need to differentiate between SRTP and normal generic parameter types
62-
"'" + typ.GenericParameter.Name
68+
"'" + typ.GenericParameter.Name + nullabilityClause
6369
elif typ.HasTypeDefinition && typ.GenericArguments.Count > 0 then
6470
let typeDef = typ.TypeDefinition
6571

@@ -68,19 +74,20 @@ module SignatureFormatter =
6874

6975
if entityIsArray typeDef then
7076
if typ.GenericArguments.Count = 1 && typ.GenericArguments.[0].IsTupleType then
71-
sprintf "(%s) array" genericArgs
77+
$"(%s{genericArgs}) array%s{nullabilityClause}"
7278
else
73-
sprintf "%s array" genericArgs
79+
$"%s{genericArgs} array%s{nullabilityClause}"
7480
elif isMeasureType typeDef then
75-
typ.Format context
81+
typ.Format context + nullabilityClause
7682
else
77-
sprintf "%s<%s>" (FSharpKeywords.NormalizeIdentifierBackticks typeDef.DisplayName) genericArgs
83+
$"%s{FSharpKeywords.NormalizeIdentifierBackticks typeDef.DisplayName}<%s{genericArgs}>%s{nullabilityClause}"
7884
else if typ.HasTypeDefinition then
7985
FSharpKeywords.NormalizeIdentifierBackticks typ.TypeDefinition.DisplayName
86+
+ nullabilityClause
8087
else
81-
typ.Format context
88+
typ.Format context + nullabilityClause
8289
with _ ->
83-
typ.Format context
90+
typ.Format context + nullabilityClause
8491

8592
let formatGenericParameter includeMemberConstraintTypes displayContext (param: FSharpGenericParameter) =
8693

@@ -357,7 +364,7 @@ module SignatureFormatter =
357364
if String.IsNullOrWhiteSpace formattedParam then
358365
formattedParam
359366
else
360-
"(requires " + formattedParam + " )"
367+
"(requires " + formattedParam + ")"
361368

362369
if paramConstraint = retTypeConstraint then
363370
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)