diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi.Daemon/FSharp.Psi.Daemon.fsproj b/ReSharper.FSharp/src/FSharp/FSharp.Psi.Daemon/FSharp.Psi.Daemon.fsproj index 12d880b767..664fc6f267 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi.Daemon/FSharp.Psi.Daemon.fsproj +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi.Daemon/FSharp.Psi.Daemon.fsproj @@ -24,6 +24,7 @@ Strings.resx True + diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi.Daemon/src/Common/ActionUtils.fs b/ReSharper.FSharp/src/FSharp/FSharp.Psi.Daemon/src/Common/ActionUtils.fs new file mode 100644 index 0000000000..7e00e61737 --- /dev/null +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi.Daemon/src/Common/ActionUtils.fs @@ -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().SetText(text) + shell.GetComponent().Show(Strings.InferredTypeCodeVisionProvider_TypeCopied_TooltipText, PopupWindowContextSource(fun _ -> + if highlighter.IsValid then RiderEditorOffsetPopupWindowContext highlighter + else null + )) diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi.Daemon/src/Highlightings/TypeHintHighlighting.fs b/ReSharper.FSharp/src/FSharp/FSharp.Psi.Daemon/src/Highlightings/TypeHintHighlighting.fs index ef63e526b1..34096c93ac 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi.Daemon/src/Highlightings/TypeHintHighlighting.fs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi.Daemon/src/Highlightings/TypeHintHighlighting.fs @@ -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 @@ -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 [] 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 @@ -60,6 +71,8 @@ and [] override x.ContextMenuTitle = null override x.ContextMenuItems = [| + yield createCopyToClipboardBulbItem thh highlighter + if isNotNull actionsProvider then yield! actionsProvider.CreateChangeVisibilityBulbMenuItems(settingsStore, thh) diff --git a/ReSharper.FSharp/src/FSharp/FSharp.Psi.Daemon/src/Stages/InferredTypeCodeVisionProvider.fs b/ReSharper.FSharp/src/FSharp/FSharp.Psi.Daemon/src/Stages/InferredTypeCodeVisionProvider.fs index 0e000c3f98..81a25aab7d 100644 --- a/ReSharper.FSharp/src/FSharp/FSharp.Psi.Daemon/src/Stages/InferredTypeCodeVisionProvider.fs +++ b/ReSharper.FSharp/src/FSharp/FSharp.Psi.Daemon/src/Stages/InferredTypeCodeVisionProvider.fs @@ -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 @@ -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 @@ -44,8 +40,6 @@ type FSharpInferredTypeHighlighting(range, text, provider: ICodeInsightsProvider [] type InferredTypeCodeVisionProvider() = - let typeCopiedTooltipText = Strings.InferredTypeCodeVisionProvider_TypeCopied_TooltipText - interface ICodeInsightsProvider with member x.ProviderId = FSharpInferredTypeHighlighting.providerId member x.DisplayName = FSharpInferredTypeHighlighting.providerId @@ -59,19 +53,7 @@ type InferredTypeCodeVisionProvider() = let entry = codeInsightsHighlighting.Entry.As() if isNull entry then () else - let shell = Shell.Instance - shell.GetComponent().SetText(entry.Text) - let documentMarkupManager = shell.GetComponent() - shell.GetComponent().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(_, _, _) = ()