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: add 'copy inferred type' action #761

Open
wants to merge 3 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 @@ -24,6 +24,7 @@
<DependentUpon>Strings.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<Compile Include="src\Common\ActionUtils.fs" />
<Compile Include="src\Options\FSharpTypeHintOptionsPage.fs" />
<Compile Include="src\Options\FSharpTypeHintsOptionsRegistrator.fs" />
<Compile Include="src\ReadLockCookieUtil.fs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module JetBrains.ReSharper.Plugins.FSharp.Psi.Daemon.Common.ActionUtils

open JetBrains.Application.UI.Components
open JetBrains.Application.UI.PopupLayout
open JetBrains.Application.UI.Tooltips
open JetBrains.RdBackend.Common.Features.Services
open JetBrains.ReSharper.Plugins.FSharp.Psi.Daemon.Resources
open JetBrains.ReSharper.Resources.Shell
open JetBrains.TextControl.DocumentMarkup

let copyToClipboard text (highlighter: IHighlighter) =
let shell = Shell.Instance
shell.GetComponent<Clipboard>().SetText(text)
shell.GetComponent<ITooltipManager>().Show(Strings.InferredTypeCodeVisionProvider_TypeCopied_TooltipText, PopupWindowContextSource(fun _ ->
if highlighter.IsValid then RiderEditorOffsetPopupWindowContext highlighter
else null
))
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
open System
open JetBrains.Application.Parts
open JetBrains.Application.Settings
open JetBrains.Application.UI.Controls.BulbMenu.Anchors
open JetBrains.Application.UI.Controls.BulbMenu.Items
open JetBrains.DocumentModel
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.Psi.Daemon.Common.ActionUtils
open JetBrains.ReSharper.Plugins.FSharp.Psi.Daemon.Options
open JetBrains.ReSharper.Plugins.FSharp.Psi.Daemon.Resources
open JetBrains.TextControl.DocumentMarkup.Adornments
open JetBrains.UI.RichText

Expand Down Expand Up @@ -36,12 +40,19 @@ type TypeHintHighlighting(typeNameString: string, range: DocumentRange, pushToHi
member x.TestOutput = text.Text

member x.Text = text
member x.TypeText = typeNameString
member x.PushToHintMode = pushToHintMode
member x.BulbActionsProvider = bulbActionsProvider
member x.IsValid() = not text.IsEmpty && range.IsEmpty

and [<SolutionComponent(Instantiation.DemandAnyThreadSafe)>]
TypeHintAdornmentProvider(settingsStore: ISettingsStore) =

let createCopyToClipboardBulbItem (highlighting: TypeHintHighlighting) highlighter =
let text = highlighting.TypeText
BulbMenuItem(ExecutableItem(fun () -> copyToClipboard text highlighter),
Strings.FSharpInferredTypeHighlighting_TooltipText, null, BulbMenuAnchors.FirstClassContextItems)

interface IHighlighterAdornmentProvider with
member x.IsValid(highlighter) =
match highlighter.GetHighlighting() with
Expand All @@ -60,6 +71,8 @@ and [<SolutionComponent(Instantiation.DemandAnyThreadSafe)>]
override x.ContextMenuTitle = null
override x.ContextMenuItems =
[|
yield createCopyToClipboardBulbItem thh highlighter

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ open FSharp.Compiler.CodeAnalysis
open FSharp.Compiler.Symbols
open JetBrains.Application
open JetBrains.Application.Settings
open JetBrains.Application.UI.Components
open JetBrains.Application.UI.PopupLayout
open JetBrains.Application.UI.Tooltips
open JetBrains.RdBackend.Common.Platform.CodeInsights
open JetBrains.ReSharper.Daemon.CodeInsights
open JetBrains.ReSharper.Feature.Services.Daemon
open JetBrains.RdBackend.Common.Features.Services
open JetBrains.ReSharper.Plugins.FSharp.Psi.Daemon.Common.ActionUtils
open JetBrains.ReSharper.Plugins.FSharp.Psi.Daemon.Resources
open JetBrains.ReSharper.Plugins.FSharp.Psi.Features.Daemon.Stages
open JetBrains.ReSharper.Plugins.FSharp.Psi.Features.Util
Expand All @@ -22,7 +19,6 @@ open JetBrains.ReSharper.Psi
open JetBrains.ReSharper.Psi.Tree
open JetBrains.ReSharper.Resources.Shell
open JetBrains.Rider.Model
open JetBrains.TextControl.DocumentMarkup
open JetBrains.TextControl.DocumentMarkup.Adornments
open JetBrains.TextControl.DocumentMarkup.Adornments.IntraTextAdornments
open JetBrains.Util
Expand All @@ -44,8 +40,6 @@ type FSharpInferredTypeHighlighting(range, text, provider: ICodeInsightsProvider

[<ShellComponent>]
type InferredTypeCodeVisionProvider() =
let typeCopiedTooltipText = Strings.InferredTypeCodeVisionProvider_TypeCopied_TooltipText

interface ICodeInsightsProvider with
member x.ProviderId = FSharpInferredTypeHighlighting.providerId
member x.DisplayName = FSharpInferredTypeHighlighting.providerId
Expand All @@ -59,19 +53,7 @@ type InferredTypeCodeVisionProvider() =
let entry = codeInsightsHighlighting.Entry.As<TextCodeVisionEntry>()
if isNull entry then () else

let shell = Shell.Instance
shell.GetComponent<Clipboard>().SetText(entry.Text)
let documentMarkupManager = shell.GetComponent<IDocumentMarkupManager>()
shell.GetComponent<ITooltipManager>().Show(typeCopiedTooltipText, PopupWindowContextSource(fun _ ->
let documentMarkup = documentMarkupManager.TryGetMarkupModel(codeInsightsHighlighting.Range.Document)
if isNull documentMarkup then null else

documentMarkup.GetFilteredHighlighters(FSharpInferredTypeHighlighting.providerId,
fun h -> highlighting.Equals(h.GetHighlighting()))
|> Seq.tryHead
|> Option.map RiderEditorOffsetPopupWindowContext
|> Option.defaultValue null :> _
))
copyToClipboard entry.Text highlighting.Highlighter

member x.OnExtraActionClick(_, _, _) = ()

Expand Down
Loading