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

Inlay hints/Patterns: support optional parameters #764

Open
wants to merge 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ open JetBrains.ReSharper.Plugins.FSharp.Psi.Features.Daemon.Stages
open JetBrains.ReSharper.Plugins.FSharp.Psi.Impl
open JetBrains.ReSharper.Plugins.FSharp.Psi.Tree
open JetBrains.ReSharper.Plugins.FSharp.Settings
open JetBrains.ReSharper.Plugins.FSharp.Util
open JetBrains.ReSharper.Psi.Tree
open JetBrains.TextControl.DocumentMarkup.Adornments
open JetBrains.ReSharper.Plugins.FSharp.Psi.Services.Util.TypeAnnotationsUtil
Expand Down Expand Up @@ -169,6 +170,9 @@ type private PatternsHighlightingProcess(fsFile, settingsStore: IContextBoundSet
let fcsType = symbol.FullType
let range = pattern.GetNavigationRange().EndOffsetRange()

let isOptional = isNotNull (OptionalValPatNavigator.GetByPattern(refPat))
let fcsType = if isOptional && isOption fcsType then fcsType.GenericArguments[0] else fcsType

createTypeHintHighlighting fcsType defaultDisplayContext range pushToHintMode actionsProvider false
|> ValueSome

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ open JetBrains.ReSharper.Psi.Tree
let rec private visitPattern (acc: ITreeNode list) (pattern: IFSharpPattern) =
match pattern with
| null
| :? IUnitPat
| :? IConstPat
| :? IWildPat
| :? ITypedPat -> acc

Expand All @@ -31,6 +31,8 @@ let rec private visitPattern (acc: ITreeNode list) (pattern: IFSharpPattern) =
parametersOwnerPat.ParametersEnumerable
|> Seq.fold visitPattern acc

| :? IOptionalValPat as optionalPat -> visitPattern acc optionalPat.Pattern

| :? INamedUnionCaseFieldsPat as unionCaseFieldsPat ->
unionCaseFieldsPat.FieldPatternsEnumerable
|> Seq.fold visitPattern acc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

open System
open System.Collections.Generic
open System.Runtime.InteropServices

type SingleCaseDU<'a, 'b> = SingleCaseDU of x: 'a
type Record = { Foo: int; Bar: string }
Expand Down Expand Up @@ -67,6 +68,8 @@ type A(x) =
let res = x + y + z
res

member _.M1([<Optional>] ?x, ?y) = x.Value + y.Value + 1

interface IDisposable with
member _.Dispose() = ()

Expand Down Expand Up @@ -99,6 +102,8 @@ type Typed(x: int) =
let res: int = x + y + z
res

member _.M1([<Optional>] ?x: int, ?y: int) : int = x.Value + y.Value + 1

interface IDisposable with
member _.Dispose(): unit = ()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

open System
open System.Collections.Generic
open System.Runtime.InteropServices

type SingleCaseDU<'a, 'b> = SingleCaseDU of x: 'a
type Record = { Foo: int; Bar: string }
Expand Down Expand Up @@ -67,6 +68,8 @@ type A(x) =
let res = x + y + z
res

member _.M1([<Optional>] ?x, ?y) = x.Value + y.Value + 1

interface IDisposable with
member _.Dispose() = ()

Expand Down Expand Up @@ -99,6 +102,8 @@ type Typed(x: int) =
let res: int = x + y + z
res

member _.M1([<Optional>] ?x: int, ?y: int) : int = x.Value + y.Value + 1

interface IDisposable with
member _.Dispose(): unit = ()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

open System
open System.Collections.Generic
open System.Runtime.InteropServices

type SingleCaseDU<'a, 'b> = SingleCaseDU of x: 'a
type Record = { Foo: int; Bar: string }
Expand Down Expand Up @@ -67,6 +68,8 @@ type A(x) =
let res||(11) = x + y + z
res

member _.M1([<Optional>] ?x, ?y) = x.Value + y.Value + 1

interface IDisposable with
member _.Dispose() = ()

Expand Down Expand Up @@ -99,6 +102,8 @@ type Typed(x: int) =
let res: int = x + y + z
res

member _.M1([<Optional>] ?x: int, ?y: int) : int = x.Value + y.Value + 1

interface IDisposable with
member _.Dispose(): unit = ()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

open System
open System.Collections.Generic
open System.Runtime.InteropServices

type SingleCaseDU<'a, 'b> = SingleCaseDU of x: 'a
type Record = { Foo: int; Bar: string }
Expand Down Expand Up @@ -67,8 +68,10 @@ type A(x||(24)) =
let res||(41) = x + y + z
res

member _.M1([<Optional>] ?x||(42), ?y||(43)) ||(44)= x.Value + y.Value + 1

interface IDisposable with
member _.Dispose() ||(42)= ()
member _.Dispose() ||(45)= ()


type Typed(x: int) =
Expand All @@ -88,7 +91,7 @@ type Typed(x: int) =

member val P3: int = 3 with get, set

member x.P4||(43)
member x.P4||(46)
with get (index: int) =
let x: string = array[index]
x
Expand All @@ -99,12 +102,14 @@ type Typed(x: int) =
let res: int = x + y + z
res

member _.M1([<Optional>] ?x: int, ?y: int) : int = x.Value + y.Value + 1

interface IDisposable with
member _.Dispose(): unit = ()

let delimiter (delim1||(44), delim2||(45), value||(46)) ||(47)=
let delimiter (delim1||(47), delim2||(48), value||(49)) ||(50)=
{ new IFormattable with
member x.ToString(format||(48), provider||(49)) ||(50)=
member x.ToString(format||(51), provider||(52)) ||(53)=
if format = "D" then
delim1 + value + delim2
else
Expand All @@ -116,19 +121,19 @@ type MyStruct =
val mutable myString : string


let (|Active|) arg||(51) valueToMatch||(52) ||(53)=
let (|Active|) arg||(54) valueToMatch||(55) ||(56)=
Active(if arg && valueToMatch = 2 then "" else "")

let (|Active1|Active2|) valueToMatch||(54) ||(55)=
let (|Active1|Active2|) valueToMatch||(57) ||(58)=
if valueToMatch then Choice1Of2(1) else Choice2Of2("")

let (|ActiveOption|_|) _ ||(56)= None
let (|ActiveOption|_|) _ ||(59)= None


let (|Int|) (x: MyStruct) : int = Int(x.myInt)
let (|String|) (x: MyStruct) : string = String(x.myString)

let f1 (x||(57) & Int(i||(58)) & String(s||(59))) ||(60)= ()
let f1 (x||(60) & Int(i||(61)) & String(s||(62))) ||(63)= ()

---------------------------------------------------------
(0): ReSharper Parameter Name Hint: : 'b
Expand Down Expand Up @@ -173,22 +178,25 @@ let f1 (x||(57) & Int(i||(58)) & String(s||(59))) ||(60)= ()
(39): ReSharper Parameter Name Hint: : int
(40): ReSharper Parameter Name Hint: : int
(41): ReSharper Parameter Name Hint: : int
(42): ReSharper Parameter Name Hint: : unit
(43): ReSharper Parameter Name Hint: : string
(44): ReSharper Parameter Name Hint: : string
(45): ReSharper Parameter Name Hint: : string
(46): ReSharper Parameter Name Hint: : string
(47): ReSharper Parameter Name Hint: : IFormattable
(42): ReSharper Parameter Name Hint: : int
(43): ReSharper Parameter Name Hint: : int
(44): ReSharper Parameter Name Hint: : int
(45): ReSharper Parameter Name Hint: : unit
(46): ReSharper Parameter Name Hint: : string
(47): ReSharper Parameter Name Hint: : string
(48): ReSharper Parameter Name Hint: : string
(49): ReSharper Parameter Name Hint: : IFormatProvider
(50): ReSharper Parameter Name Hint: : string
(51): ReSharper Parameter Name Hint: : bool
(52): ReSharper Parameter Name Hint: : int
(49): ReSharper Parameter Name Hint: : string
(50): ReSharper Parameter Name Hint: : IFormattable
(51): ReSharper Parameter Name Hint: : string
(52): ReSharper Parameter Name Hint: : IFormatProvider
(53): ReSharper Parameter Name Hint: : string
(54): ReSharper Parameter Name Hint: : bool
(55): ReSharper Parameter Name Hint: : Choice<int,string>
(56): ReSharper Parameter Name Hint: : 'b option
(57): ReSharper Parameter Name Hint: : MyStruct
(58): ReSharper Parameter Name Hint: : int
(59): ReSharper Parameter Name Hint: : string
(60): ReSharper Parameter Name Hint: : unit
(55): ReSharper Parameter Name Hint: : int
(56): ReSharper Parameter Name Hint: : string
(57): ReSharper Parameter Name Hint: : bool
(58): ReSharper Parameter Name Hint: : Choice<int,string>
(59): ReSharper Parameter Name Hint: : 'b option
(60): ReSharper Parameter Name Hint: : MyStruct
(61): ReSharper Parameter Name Hint: : int
(62): ReSharper Parameter Name Hint: : string
(63): ReSharper Parameter Name Hint: : unit
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

open System
open System.Collections.Generic
open System.Runtime.InteropServices

type SingleCaseDU<'a, 'b> = SingleCaseDU of x: 'a
type Record = { Foo: int; Bar: string }
Expand Down Expand Up @@ -67,8 +68,10 @@ type A(x||(16)) =
let res = x + y + z
res

member _.M1([<Optional>] ?x||(31), ?y||(32)) ||(33)= x.Value + y.Value + 1

interface IDisposable with
member _.Dispose() ||(31)= ()
member _.Dispose() ||(34)= ()


type Typed(x: int) =
Expand All @@ -88,7 +91,7 @@ type Typed(x: int) =

member val P3: int = 3 with get, set

member x.P4||(32)
member x.P4||(35)
with get (index: int) =
let x: string = array[index]
x
Expand All @@ -99,10 +102,12 @@ type Typed(x: int) =
let res: int = x + y + z
res

member _.M1([<Optional>] ?x: int, ?y: int) : int = x.Value + y.Value + 1

interface IDisposable with
member _.Dispose(): unit = ()

let delimiter (delim1||(33), delim2||(34), value||(35)) ||(36)=
let delimiter (delim1||(36), delim2||(37), value||(38)) ||(39)=
{ new IFormattable with
member x.ToString(format, provider) =
if format = "D" then
Expand All @@ -116,19 +121,19 @@ type MyStruct =
val mutable myString : string


let (|Active|) arg||(37) valueToMatch||(38) ||(39)=
let (|Active|) arg||(40) valueToMatch||(41) ||(42)=
Active(if arg && valueToMatch = 2 then "" else "")

let (|Active1|Active2|) valueToMatch||(40) ||(41)=
let (|Active1|Active2|) valueToMatch||(43) ||(44)=
if valueToMatch then Choice1Of2(1) else Choice2Of2("")

let (|ActiveOption|_|) _ ||(42)= None
let (|ActiveOption|_|) _ ||(45)= None


let (|Int|) (x: MyStruct) : int = Int(x.myInt)
let (|String|) (x: MyStruct) : string = String(x.myString)

let f1 (x||(43) & Int(i||(44)) & String(s||(45))) ||(46)= ()
let f1 (x||(46) & Int(i||(47)) & String(s||(48))) ||(49)= ()

---------------------------------------------------------
(0): ReSharper Parameter Name Hint: : 'b
Expand Down Expand Up @@ -162,19 +167,22 @@ let f1 (x||(43) & Int(i||(44)) & String(s||(45))) ||(46)= ()
(28): ReSharper Parameter Name Hint: : int
(29): ReSharper Parameter Name Hint: : int
(30): ReSharper Parameter Name Hint: : int
(31): ReSharper Parameter Name Hint: : unit
(32): ReSharper Parameter Name Hint: : string
(33): ReSharper Parameter Name Hint: : string
(34): ReSharper Parameter Name Hint: : string
(35): ReSharper Parameter Name Hint: : string
(36): ReSharper Parameter Name Hint: : IFormattable
(37): ReSharper Parameter Name Hint: : bool
(38): ReSharper Parameter Name Hint: : int
(39): ReSharper Parameter Name Hint: : string
(31): ReSharper Parameter Name Hint: : int
(32): ReSharper Parameter Name Hint: : int
(33): ReSharper Parameter Name Hint: : int
(34): ReSharper Parameter Name Hint: : unit
(35): ReSharper Parameter Name Hint: : string
(36): ReSharper Parameter Name Hint: : string
(37): ReSharper Parameter Name Hint: : string
(38): ReSharper Parameter Name Hint: : string
(39): ReSharper Parameter Name Hint: : IFormattable
(40): ReSharper Parameter Name Hint: : bool
(41): ReSharper Parameter Name Hint: : Choice<int,string>
(42): ReSharper Parameter Name Hint: : 'b option
(43): ReSharper Parameter Name Hint: : MyStruct
(44): ReSharper Parameter Name Hint: : int
(45): ReSharper Parameter Name Hint: : string
(46): ReSharper Parameter Name Hint: : unit
(41): ReSharper Parameter Name Hint: : int
(42): ReSharper Parameter Name Hint: : string
(43): ReSharper Parameter Name Hint: : bool
(44): ReSharper Parameter Name Hint: : Choice<int,string>
(45): ReSharper Parameter Name Hint: : 'b option
(46): ReSharper Parameter Name Hint: : MyStruct
(47): ReSharper Parameter Name Hint: : int
(48): ReSharper Parameter Name Hint: : string
(49): ReSharper Parameter Name Hint: : unit
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Test

open System
open System.Collections.Generic
open System.Runtime.InteropServices

type SingleCaseDU<'a, 'b> = SingleCaseDU of x: 'a
type Record = { Foo: int; Bar: string }
Expand Down Expand Up @@ -67,6 +68,8 @@ type A(x) =
let res = x + y + z
res

member _.M1([<Optional>] ?x, ?y) = x.Value + y.Value + 1

interface IDisposable with
member _.Dispose() = ()

Expand Down Expand Up @@ -99,6 +102,8 @@ type Typed(x: int) =
let res: int = x + y + z
res

member _.M1([<Optional>] ?x: int, ?y: int) : int = x.Value + y.Value + 1

interface IDisposable with
member _.Dispose(): unit = ()

Expand Down
Loading