Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
DedSec256 committed Nov 7, 2024
1 parent 4995d27 commit 5ce6bfb
Show file tree
Hide file tree
Showing 16 changed files with 275 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ type public Strings() =
static member FSharpTypeHints_TopLevelMembers_Description = Strings.ResourceManager.GetString("FSharpTypeHints_TopLevelMembers_Description")
static member FSharpTypeHints_LocalBindings_Description = Strings.ResourceManager.GetString("FSharpTypeHints_LocalBindings_Description")
static member FSharpTypeHints_ShowPipeReturnTypes_Description = Strings.ResourceManager.GetString("FSharpTypeHints_ShowPipeReturnTypes_Description")
static member FSharpTypeHints_HideSameLinePipe_Description = Strings.ResourceManager.GetString("FSharpTypeHints_HideSameLinePipe_Description")
static member FSharpTypeHints_HideSameLinePipe_Description = Strings.ResourceManager.GetString("FSharpTypeHints_HideSameLinePipe_Description")
static member FSharpTypeHints_MatchClauses_Description = Strings.ResourceManager.GetString("FSharpTypeHints_MatchClauses_Description")
static member FSharpTypeHints_MatchClausesSettings_Header = Strings.ResourceManager.GetString("FSharpTypeHints_MatchClausesSettings_Header")
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@
<data name="FSharpTypeHints_HideSameLinePipe_Description" xml:space="preserve">
<value>Hide when |&gt; is on same line as argument</value>
</data>
<data name="FSharpTypeHints_MatchClauses_Description" xml:space="preserve">
<value>Type hints for match clauses</value>
</data>
<data name="FSharpTypeHints_MatchClausesSettings_Header" xml:space="preserve">
<value />
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,12 @@ type FSharpTypeHintOptions =
[<SettingsEntry(PushToHintMode.PushToShowHints,
DescriptionResourceType = typeof<Strings>,
DescriptionResourceName = nameof(Strings.FSharpTypeHints_LocalBindings_Description))>]
mutable ShowTypeHintsForLocalBindings: PushToHintMode }
mutable ShowTypeHintsForLocalBindings: PushToHintMode

[<SettingsEntry(PushToHintMode.PushToShowHints,
DescriptionResourceType = typeof<Strings>,
DescriptionResourceName = nameof(Strings.FSharpTypeHints_MatchClauses_Description))>]
mutable ShowTypeHintsForMatchClauses: PushToHintMode }


[<OptionsPage("FSharpOptionsPage", "F#", typeof<ProjectModelThemedIcons.Fsharp>)>]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ type public Strings() =
static member FSharpTypeHints_TopLevelMembersSettings_Comment = Strings.ResourceManager.GetString("FSharpTypeHints_TopLevelMembersSettings_Comment")
static member FSharpTypeHints_ShowPipeReturnTypes_Description = Strings.ResourceManager.GetString("FSharpTypeHints_ShowPipeReturnTypes_Description")
static member FSharpTypeHints_HideSameLinePipe_Description = Strings.ResourceManager.GetString("FSharpTypeHints_HideSameLinePipe_Description")
static member FSharpTypeHints_PipesSettings_Header = Strings.ResourceManager.GetString("FSharpTypeHints_PipesSettings_Header")
static member FSharpTypeHints_PipesSettings_Header = Strings.ResourceManager.GetString("FSharpTypeHints_PipesSettings_Header")
static member FSharpTypeHints_MatchClausesSettings_Header = Strings.ResourceManager.GetString("FSharpTypeHints_MatchClausesSettings_Header")
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,7 @@
<data name="FSharpTypeHints_PipesSettings_Header" xml:space="preserve">
<value>Pipe operators</value>
</data>
<data name="FSharpTypeHints_MatchClausesSettings_Header" xml:space="preserve">
<value>Match clauses</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ type FSharpTopLevelMembersTypeHintBulbActionsProvider private () =
type FSharpLocalBindingTypeHintBulbActionsProvider private () =
inherit FSharpTypeHintBulbActionsProvider((fun x -> x.ShowTypeHintsForLocalBindings), Strings.FSharpTypeHints_LocalBindingsSettings_Header)
static member val Instance = FSharpLocalBindingTypeHintBulbActionsProvider()

type FSharpMatchClauseTypeHintBulbActionsProvider private () =
inherit FSharpTypeHintBulbActionsProvider((fun x -> x.ShowTypeHintsForMatchClauses), Strings.FSharpTypeHints_MatchClausesSettings_Header)
static member val Instance = FSharpMatchClauseTypeHintBulbActionsProvider()
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ type FSharpTypeHintsOptionsPage(lifetime: Lifetime, optionsPageContext: OptionsP
this.AddHeader(Strings.FSharpTypeHints_LocalBindingsSettings_Header) |> ignore
this.AddVisibilityOption(fun (s: FSharpTypeHintOptions) -> s.ShowTypeHintsForLocalBindings)

this.AddHeader(Strings.FSharpTypeHints_MatchClausesSettings_Header) |> ignore
this.AddVisibilityOption(fun (s: FSharpTypeHintOptions) -> s.ShowTypeHintsForMatchClauses)


this.AddHeader(Strings.FSharpTypeHints_PipesSettings_Header) |> ignore
this.AddBoolOption((fun (s: FSharpTypeHintOptions) -> s.ShowPipeReturnTypes),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,34 @@ open JetBrains.ReSharper.Plugins.FSharp.Psi.Services.Util.TypeAnnotationsUtil
open JetBrains.TextControl.DocumentMarkup.Adornments.IntraTextAdornments

type private NodesRequiringHints =
{ TopLevelNodes: List<ITreeNode>; LocalNodes: List<ITreeNode> }
{ TopLevelNodes: List<ITreeNode>
LocalNodes: List<ITreeNode>
MatchClauses: List<ITreeNode> }

type private FSharpTypeHintSettings =
{ TopLevelMembers: PushToHintMode; LocalBindings: PushToHintMode } with
{ TopLevelMembers: PushToHintMode
LocalBindings: PushToHintMode
MatchClauses: PushToHintMode } with

static member Create(settingsStore: IContextBoundSettingsStore) =
{ TopLevelMembers = settingsStore.GetValue(fun (key: FSharpTypeHintOptions) -> key.ShowTypeHintsForTopLevelMembers)
.EnsureInlayHintsDefault(settingsStore)
LocalBindings = settingsStore.GetValue(fun (key: FSharpTypeHintOptions) -> key.ShowTypeHintsForLocalBindings)
.EnsureInlayHintsDefault(settingsStore) }
.EnsureInlayHintsDefault(settingsStore)
MatchClauses = settingsStore.GetValue(fun (key: FSharpTypeHintOptions) -> key.ShowTypeHintsForMatchClauses)
.EnsureInlayHintsDefault(settingsStore)}

member x.IsDisabled =
x.TopLevelMembers = PushToHintMode.Never &&
x.LocalBindings = PushToHintMode.Never
x.LocalBindings = PushToHintMode.Never &&
x.MatchClauses = PushToHintMode.Never


type private MembersVisitor(settings) =
inherit TreeNodeVisitor<NodesRequiringHints>()
let disabledForTopBindings = settings.TopLevelMembers = PushToHintMode.Never
let disabledForLocalBindings = settings.LocalBindings = PushToHintMode.Never
let disabledForMatchClauses = settings.MatchClauses = PushToHintMode.Never

let isTopLevelMember (node: ITreeNode) =
match node with
Expand All @@ -44,13 +54,20 @@ type private MembersVisitor(settings) =
| :? IConstructorDeclaration -> true
| _ -> false

let isLocalBinding (node: ITreeNode) =
match node with
| :? ILocalBinding
| :? ILambdaExpr
| :? IForEachExpr -> true
| _ -> false

override x.VisitNode(node, context) =
if settings.LocalBindings = PushToHintMode.Never &&
(isTopLevelMember node || node :? IMatchClauseListOwnerExpr) then () else
if disabledForMatchClauses &&
(disabledForLocalBindings && isTopLevelMember node || node :? IMatchClauseListOwnerExpr) then () else

for child in node.Children() do
if settings.TopLevelMembers = PushToHintMode.Never &&
isTopLevelMember child then x.VisitNode(child, context) else
if disabledForTopBindings && isTopLevelMember child || disabledForLocalBindings && isLocalBinding child
then x.VisitNode(child, context) else

match child with
| :? IFSharpTreeNode as treeNode -> treeNode.Accept(x, context)
Expand Down Expand Up @@ -100,7 +117,7 @@ type private MembersVisitor(settings) =

override x.VisitMatchClause(matchClause, context) =
let result = collectTypeHintAnchorsForMatchClause matchClause
context.LocalNodes.AddRange(result)
context.MatchClauses.AddRange(result)

x.VisitNode(matchClause, context)

Expand Down Expand Up @@ -192,7 +209,10 @@ type private PatternsHighlightingProcess(fsFile, settingsStore: IContextBoundSet

| _ -> ValueNone

let adornNodes (topLevelNodes : ITreeNode array) (localNodes : ITreeNode array) =
let adornNodes
(topLevelNodes: ITreeNode array)
(localNodes: ITreeNode array)
(matchClauses: ITreeNode array) =
let highlightingConsumer = FilteringHighlightingConsumer(daemonProcess.SourceFile, fsFile, settingsStore)

let inline adornNodes nodes pushToHintMode actionsProvider =
Expand All @@ -205,15 +225,17 @@ type private PatternsHighlightingProcess(fsFile, settingsStore: IContextBoundSet

adornNodes topLevelNodes settings.TopLevelMembers FSharpTopLevelMembersTypeHintBulbActionsProvider.Instance
adornNodes localNodes settings.LocalBindings FSharpLocalBindingTypeHintBulbActionsProvider.Instance
adornNodes matchClauses settings.MatchClauses FSharpMatchClauseTypeHintBulbActionsProvider.Instance

highlightingConsumer.CollectHighlightings()

override x.Execute(committer) =
let consumer = { TopLevelNodes = List(); LocalNodes = List() }
let consumer = { TopLevelNodes = List(); LocalNodes = List(); MatchClauses = List() }
fsFile.Accept(MembersVisitor(settings), consumer)

let topLevelNodes = consumer.TopLevelNodes |> Array.ofSeq
let localNodes = consumer.LocalNodes |> Array.ofSeq
let matchClauses = consumer.MatchClauses |> Array.ofSeq

// Visible range may be larger than document range by 1 char
// Intersect them to ensure commit doesn't throw
Expand All @@ -229,15 +251,16 @@ type private PatternsHighlightingProcess(fsFile, settingsStore: IContextBoundSet
// Partition the expressions to adorn by whether they're visible in the viewport or not
let topLevelVisible, topLevelNotVisible = partition topLevelNodes visibleRange
let localNodesVisible, localNodesNotVisible = partition localNodes visibleRange
let matchClausesVisible, matchClausesNotVisible = partition matchClauses visibleRange

// Adorn visible expressions first
let visibleHighlightings = adornNodes topLevelVisible localNodesVisible
let visibleHighlightings = adornNodes topLevelVisible localNodesVisible matchClausesVisible
committer.Invoke(DaemonStageResult(visibleHighlightings, visibleRange))

// Finally adorn expressions that aren't visible in the viewport
adornNodes topLevelNotVisible localNodesNotVisible
adornNodes topLevelNotVisible localNodesNotVisible matchClausesNotVisible
else
adornNodes topLevelNodes localNodes
adornNodes topLevelNodes localNodes matchClauses

committer.Invoke(DaemonStageResult remainingHighlightings)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ let (|String|) (x: MyStruct) : string = String(x.myString)
let f1 (x & Int(i) & String(s)) = ()


function x -> ()
let _ = function x -> ()

match [Some 5] with
| [] -> ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ let (|String|) (x: MyStruct) : string = String(x.myString)
let f1 (x & Int(i) & String(s)) = ()


function x -> ()
let _ = function x -> ()

match [Some 5] with
| [] -> ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,19 @@ let (|String|) (x: MyStruct) : string = String(x.myString)
let f1 (x & Int(i) & String(s)) = ()


function x||(12) -> ()
let _ = function x -> ()

match [Some 5] with
| [] -> ()
| [x] -> ()
| x :: y :: [] -> ()
| Some(x||(13)) :: tail||(14) -> ()
| [Some(x||(15))]
| [_; Some(x)] when let x||(16) = 5 in true ->
let y||(17) = 5 in ()
| Some(x) :: tail -> ()
| [Some(x)]
| [_; Some(x)] when let x = 5 in true ->
let y = 5 in ()

exception MyException of string
try () with | MyException(x||(18)) -> ()
try () with | MyException(x) -> ()

---------------------------------------------------------
(0): ReSharper Parameter Name Hint: : int
Expand All @@ -158,10 +158,3 @@ try () with | MyException(x||(18)) -> ()
(9): ReSharper Parameter Name Hint: : int
(10): ReSharper Parameter Name Hint: : string
(11): ReSharper Parameter Name Hint: : int
(12): ReSharper Parameter Name Hint: : 'a
(13): ReSharper Parameter Name Hint: : int
(14): ReSharper Parameter Name Hint: : int option list
(15): ReSharper Parameter Name Hint: : int
(16): ReSharper Parameter Name Hint: : int
(17): ReSharper Parameter Name Hint: : int
(18): ReSharper Parameter Name Hint: : string
Loading

0 comments on commit 5ce6bfb

Please sign in to comment.