Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
DedSec256 committed Feb 18, 2025
1 parent f0465dc commit e2f62e7
Show file tree
Hide file tree
Showing 60 changed files with 651 additions and 182 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<Compile Include="src\Checker\ScriptFcsProjectProvider.fs" />
<Compile Include="src\Checker\FcsProjectBuilder.fs" />
<Compile Include="src\Checker\FcsProjectProvider.fs" />
<Compile Include="src\Intentions\SpecifyTypeActionsProvider.fs" />
<Compile Include="src\PaketRestoreTargetsAnalyzer.fs" />
<Compile Include="src\ZoneMarker.fs" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace JetBrains.ReSharper.Plugins.FSharp.Intentions

open JetBrains.Application.UI.Controls.BulbMenu.Items
open JetBrains.ReSharper.Psi.Tree

[<Interface>]
type ISpecifyTypeActionProvider =
abstract member TryCreateSpecifyTypeAction: node: ITreeNode -> BulbMenuItem
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ open JetBrains.ProjectModel
open JetBrains.ReSharper.Feature.Services.Daemon.Attributes
open JetBrains.ReSharper.Feature.Services.Daemon
open JetBrains.ReSharper.Feature.Services.InlayHints
open JetBrains.ReSharper.Plugins.FSharp.Intentions
open JetBrains.ReSharper.Plugins.FSharp.Psi.Daemon.Options
open JetBrains.ReSharper.Psi.Tree
open JetBrains.TextControl.DocumentMarkup.Adornments
open JetBrains.UI.RichText

Expand All @@ -19,10 +21,10 @@ open JetBrains.UI.RichText
OverlapResolve = OverlapResolveKind.NONE,
ShowToolTipInStatusBar = false)>]
type TypeHintHighlighting(typeNameString: string, range: DocumentRange, pushToHintMode: PushToHintMode, suffix,
bulbActionsProvider: IInlayHintBulbActionsProvider) =
bulbActionsProvider: IInlayHintBulbActionsProvider, owner: ITreeNode) =
let text = RichText(": " + typeNameString + suffix)
new (typeNameString: string, range: DocumentRange) =
TypeHintHighlighting(typeNameString, range, PushToHintMode.Default, "", null)
TypeHintHighlighting(typeNameString, range, PushToHintMode.Default, "", null, null)

interface IHighlighting with
member x.ToolTip = null
Expand All @@ -38,10 +40,11 @@ type TypeHintHighlighting(typeNameString: string, range: DocumentRange, pushToHi
member x.Text = text
member x.PushToHintMode = pushToHintMode
member x.BulbActionsProvider = bulbActionsProvider
member x.Owner = owner
member x.IsValid() = not text.IsEmpty && range.IsEmpty

and [<SolutionComponent(Instantiation.DemandAnyThreadSafe)>]
TypeHintAdornmentProvider(settingsStore: ISettingsStore) =
TypeHintAdornmentProvider(settingsStore: ISettingsStore, specifyTypeActionProvider: ISpecifyTypeActionProvider) =
interface IHighlighterAdornmentProvider with
member x.IsValid(highlighter) =
match highlighter.GetHighlighting() with
Expand All @@ -54,15 +57,21 @@ and [<SolutionComponent(Instantiation.DemandAnyThreadSafe)>]
let data =
AdornmentData(thh.Text, null, AdornmentFlags.None, AdornmentPlacement.DefaultAfterPrevChar,
thh.PushToHintMode)
let actionsProvider = thh.BulbActionsProvider
let visibilityActionsProvider = thh.BulbActionsProvider

{ new IAdornmentDataModel with
override x.ContextMenuTitle = null
override x.ContextMenuItems =
[|
if isNotNull actionsProvider then
yield! actionsProvider.CreateChangeVisibilityBulbMenuItems(settingsStore, thh)
// First-class context items
let specifyTypeAction = specifyTypeActionProvider.TryCreateSpecifyTypeAction(thh.Owner)
if isNotNull specifyTypeAction then
yield specifyTypeAction

if isNotNull visibilityActionsProvider then
yield! visibilityActionsProvider.CreateChangeVisibilityBulbMenuItems(settingsStore, thh)

// Second-class context items
yield IntraTextAdornmentDataModelHelper.CreateTurnOffAllInlayHintsBulbMenuItem(settingsStore)
yield IntraTextAdornmentDataModelHelper.CreateConfigureBulbMenuItem(nameof(FSharpTypeHintsOptionsPage))
|]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ open JetBrains.ReSharper.Plugins.FSharp.Psi.Daemon.Highlightings.FSharpTypeHints
open JetBrains.ReSharper.Plugins.FSharp.Psi.Daemon.Utils.VisibleRangeContainer
open JetBrains.ReSharper.Plugins.FSharp.Psi.Features.Daemon.Highlightings
open JetBrains.ReSharper.Plugins.FSharp.Psi.Features.Daemon.Stages
open JetBrains.ReSharper.Plugins.FSharp.Psi.Features.Util.FcsTypeUtil
open JetBrains.ReSharper.Plugins.FSharp.Psi.Impl
open JetBrains.ReSharper.Plugins.FSharp.Psi.Tree
open JetBrains.ReSharper.Plugins.FSharp.Psi.Util
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 @@ -141,9 +141,10 @@ type private PatternsHighlightingProcess(fsFile, settingsStore: IContextBoundSet
range
pushToHintMode
actionsProvider
owner
isFromReturnType =
let suffix = if isFromReturnType then " " else ""
TypeHintHighlighting(fcsType.Format(displayContext), range, pushToHintMode, suffix, actionsProvider)
TypeHintHighlighting(fcsType.Format(displayContext), range, pushToHintMode, suffix, actionsProvider, owner)

let getReturnTypeHint (decl: IParameterOwnerMemberDeclaration) pushToHintMode actionsProvider =
match decl with
Expand Down Expand Up @@ -176,7 +177,7 @@ type private PatternsHighlightingProcess(fsFile, settingsStore: IContextBoundSet
let symbol = symbolUse.Symbol.As<FSharpMemberOrFunctionOrValue>()
if isNull symbol then ValueNone else

createTypeHintHighlighting symbol.ReturnParameter.Type defaultDisplayContext range pushToHintMode actionsProvider true
createTypeHintHighlighting symbol.ReturnParameter.Type defaultDisplayContext range pushToHintMode actionsProvider decl true
|> ValueSome

let rec getHintForPattern (pattern: IFSharpPattern) pushToHintMode actionsProvider =
Expand All @@ -201,20 +202,18 @@ type private PatternsHighlightingProcess(fsFile, settingsStore: IContextBoundSet
if isNull symbol then ValueNone else

let fcsType = symbol.FullType
let pattern, fcsType = tryGetOuterOptionalParameterAndItsType refPat fcsType
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
createTypeHintHighlighting fcsType defaultDisplayContext range pushToHintMode actionsProvider pattern false
|> ValueSome

| pattern ->
let fcsType = pattern.TryGetFcsType()
if isNull fcsType then ValueNone else

let range = pattern.GetDocumentRange().EndOffsetRange()
createTypeHintHighlighting fcsType defaultDisplayContext range pushToHintMode actionsProvider false
createTypeHintHighlighting fcsType defaultDisplayContext range pushToHintMode actionsProvider pattern false
|> ValueSome

let rec getHighlighting (node: ITreeNode) pushToHintMode actionsProvider =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<Compile Include="src\Intentions\IfToElifAction.fs" />
<Compile Include="src\Intentions\NegateConditionActions.fs" />
<Compile Include="src\Intentions\ToMutableAction.fs" />
<Compile Include="src\Intentions\FunctionAnnotationAction.fs" />
<Compile Include="src\Intentions\AnnotationActions.fs" />
<Compile Include="src\Intentions\ToLiteralAction.fs" />
<Compile Include="src\Intentions\SetNameAction.fs" />
<Compile Include="src\Intentions\LetToUseAction.fs" />
Expand Down
Loading

0 comments on commit e2f62e7

Please sign in to comment.