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

Support rendering | null syntax for nullable values in tooltips #1353

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ NUGET
FSharp.Core (9.0.100) - restriction: || (== net8.0) (== net9.0) (&& (== netstandard2.0) (>= net8.0)) (&& (== netstandard2.1) (>= net8.0))
McMaster.NETCore.Plugins (>= 1.4) - restriction: || (== net8.0) (== net9.0) (&& (== netstandard2.0) (>= net8.0)) (&& (== netstandard2.1) (>= net8.0))
Microsoft.Extensions.Logging.Abstractions (>= 6.0) - restriction: || (== net8.0) (== net9.0) (&& (== netstandard2.0) (>= net8.0)) (&& (== netstandard2.1) (>= net8.0))
FSharp.Compiler.Service (43.9.100)
FSharp.Core (9.0.100)
FSharp.Compiler.Service (43.9.101)
FSharp.Core (9.0.101)
System.Buffers (>= 4.5.1)
System.Collections.Immutable (>= 8.0)
System.Diagnostics.DiagnosticSource (>= 8.0)
Expand Down
2 changes: 1 addition & 1 deletion src/FsAutoComplete.Core/AbstractClassStubGenerator.fs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ let tryFindAbstractClassExprInBufferAtPos

let allMembers = reprMembers @ members

let! inheritType, inheritMemberRange = // this must exist for abstract types
let! inheritType, inheritMemberRange =
allMembers
|> List.tryPick (function
| SynMemberDefn.ImplicitInherit(inheritType, _, _, range) -> Some(inheritType, range)
Expand Down
2 changes: 1 addition & 1 deletion src/FsAutoComplete.Core/CompilerServiceInterface.fs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ type FSharpCompilerServiceChecker(hasAnalyzers, typecheckCacheSize, parallelRefe
)

let allFlags =
Array.append [| "--targetprofile:netstandard" |] fsiAdditionalArguments
Array.append [| "--targetprofile:netstandard"; "--checknulls+"; "--define:NULLABLE" |] fsiAdditionalArguments

let! (opts, errors) =
checker.GetProjectOptionsFromScript(
Expand Down
4 changes: 2 additions & 2 deletions src/FsAutoComplete.Core/DocumentationFormatter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ module DocumentationFormatter =
if String.IsNullOrWhiteSpace formattedParam then
formattedParam
else
"(requires " + formattedParam + " )"
"(requires " + formattedParam + ")"
else
""

Expand Down Expand Up @@ -379,7 +379,7 @@ module DocumentationFormatter =
if String.IsNullOrWhiteSpace formattedParam then
formattedParam
else
"(requires " + formattedParam + " )"
"(requires " + formattedParam + ")"

if paramConstraint = retTypeConstraint then
paddedParam
Expand Down
19 changes: 11 additions & 8 deletions src/FsAutoComplete.Core/SignatureFormatter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ module SignatureFormatter =
let rec formatFSharpType (context: FSharpDisplayContext) (typ: FSharpType) : string =
let context = context.WithPrefixGenericParameters()

let nullabilityClause = if typ.HasNullAnnotation then " | null" else ""

try
if typ.IsTupleType || typ.IsStructTupleType then
let refTupleStr =
Expand All @@ -59,7 +61,7 @@ module SignatureFormatter =
else
refTupleStr
elif typ.IsGenericParameter then // no longer need to differentiate between SRTP and normal generic parameter types
"'" + typ.GenericParameter.Name
"'" + typ.GenericParameter.Name + nullabilityClause
elif typ.HasTypeDefinition && typ.GenericArguments.Count > 0 then
let typeDef = typ.TypeDefinition

Expand All @@ -68,19 +70,20 @@ module SignatureFormatter =

if entityIsArray typeDef then
if typ.GenericArguments.Count = 1 && typ.GenericArguments.[0].IsTupleType then
sprintf "(%s) array" genericArgs
$"(%s{genericArgs}) array%s{nullabilityClause}"
else
sprintf "%s array" genericArgs
$"%s{genericArgs} array%s{nullabilityClause}"
elif isMeasureType typeDef then
typ.Format context
typ.Format context + nullabilityClause
else
sprintf "%s<%s>" (FSharpKeywords.NormalizeIdentifierBackticks typeDef.DisplayName) genericArgs
$"%s{FSharpKeywords.NormalizeIdentifierBackticks typeDef.DisplayName}<%s{genericArgs}>%s{nullabilityClause}"
else if typ.HasTypeDefinition then
FSharpKeywords.NormalizeIdentifierBackticks typ.TypeDefinition.DisplayName
+ nullabilityClause
else
typ.Format context
typ.Format context + nullabilityClause
with _ ->
typ.Format context
typ.Format context + nullabilityClause

let formatGenericParameter includeMemberConstraintTypes displayContext (param: FSharpGenericParameter) =

Expand Down Expand Up @@ -357,7 +360,7 @@ module SignatureFormatter =
if String.IsNullOrWhiteSpace formattedParam then
formattedParam
else
"(requires " + formattedParam + " )"
"(requires " + formattedParam + ")"

if paramConstraint = retTypeConstraint then
paramFormat
Expand Down
Loading
Loading