Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
DedSec256 committed Oct 9, 2024
1 parent 74cbe52 commit b845647
Show file tree
Hide file tree
Showing 33 changed files with 1,247 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
<TargetFramework>net472</TargetFramework>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Update="Resources\Strings.resx">
<Generator>JetResourceGenerator</Generator>
<LastGenOutput>Strings.Designer.fs</LastGenOutput>
</EmbeddedResource>
<Compile Include="Resources\Strings.Designer.fs">
<AutoGen>True</AutoGen>
<DependentUpon>Strings.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<Compile Include="src\Util\FSharpGlobalUtil.fs" />
<Compile Include="src\Util\Util.fs" />
<Compile Include="src\Util\FSharpPredefinedType.fs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// <auto-generated/>
namespace JetBrains.ReSharper.Plugins.FSharp.Resources

open System
open JetBrains.Application.I18n
open JetBrains.DataFlow
open JetBrains.Diagnostics
open JetBrains.Lifetimes
open JetBrains.Util
open JetBrains.Util.Logging
open JetBrains.Application.I18n.Plurals

[<global.System.Diagnostics.DebuggerNonUserCode>]
[<global.System.Runtime.CompilerServices.CompilerGenerated>]
type public Strings() =
static let logger = Logger.GetLogger("JetBrains.ReSharper.Plugins.FSharp.Resources.Strings")

static let mutable resourceManager = null

static do
CultureContextComponent.Instance.Change.Advise(Lifetime.Eternal, fun (args:PropertyChangedEventArgs<CultureContextComponent>) ->
let instance = if args.HasNew then args.New else null
if instance <> null then
resourceManager <- Lazy<JetResourceManager>(fun _ ->
instance.CreateResourceManager("JetBrains.ReSharper.Plugins.FSharp.Resources.Strings",
typeof<Strings>.Assembly))
else
resourceManager <- null)

[<global.System.ComponentModel.EditorBrowsable(global.System.ComponentModel.EditorBrowsableState.Advanced)>]
static member ResourceManager: JetResourceManager =
match resourceManager with
| null -> ErrorJetResourceManager.Instance
| _ -> resourceManager.Value

static member Choice(format: string, [<ParamArray>] args: Object array): string =
match Strings.ResourceManager.ChoiceFormatter with
| null -> "???"
| formatter -> String.Format(formatter, format, args)

static member FSharpTypeHints_TopLevelMembers_Description = Strings.ResourceManager.GetString("FSharpTypeHints_TopLevelMembers_Description")
static member FSharpTypeHints_LocalBindings_Description = Strings.ResourceManager.GetString("FSharpTypeHints_LocalBindings_Description")
25 changes: 25 additions & 0 deletions ReSharper.FSharp/src/FSharp/FSharp.Common/Resources/Strings.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="FSharpTypeHints_TopLevelMembers_Description" xml:space="preserve">
<value>Type hints for top-level bindings and type members</value>
</data>
<data name="FSharpTypeHints_LocalBindings_Description" xml:space="preserve">
<value>Type hints for local bindings</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ open JetBrains.ProjectModel.DataContext
open JetBrains.ProjectModel.Resources
open JetBrains.ReSharper.Feature.Services.Daemon
open JetBrains.ReSharper.Plugins.FSharp.ProjectModel
open JetBrains.TextControl.DocumentMarkup.Adornments
open JetBrains.UI.RichText
open JetBrains.Application.Environment
open JetBrains.Application.Environment.Helpers
open JetBrains.Util

type Strings = JetBrains.ReSharper.Plugins.FSharp.Resources.Strings


[<SettingsKey(typeof<Missing>, "F# settings")>]
type FSharpSettings() = class end

Expand Down Expand Up @@ -173,13 +177,23 @@ module FSharpTypeHintOptions =
let [<Literal>] hideSameLinePipe = "Hide when |> is on same line as argument"


[<SettingsKey(typeof<FSharpOptions>, "FSharpTypeHintOptions")>]
[<SettingsKey(typeof<FSharpOptions>, nameof(FSharpTypeHintOptions))>]
type FSharpTypeHintOptions =
{ [<SettingsEntry(true, FSharpTypeHintOptions.pipeReturnTypes); DefaultValue>]
mutable ShowPipeReturnTypes: bool

[<SettingsEntry(true, FSharpTypeHintOptions.hideSameLinePipe); DefaultValue>]
mutable HideSameLine: bool }
mutable HideSameLine: bool

[<SettingsEntry(PushToHintMode.Default,
DescriptionResourceType = typeof<Strings>,
DescriptionResourceName = nameof(Strings.FSharpTypeHints_TopLevelMembers_Description))>]
mutable ShowTypeHintsForTopLevelMembers: PushToHintMode

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


[<OptionsPage("FSharpOptionsPage", "F#", typeof<ProjectModelThemedIcons.Fsharp>)>]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
<TargetFramework>net472</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="PsiFeaturesNamespaceZoneMarker.fs" />
<Compile Include="PsiNamespaceZoneMarker.fs" />
<EmbeddedResource Update="Resources\Strings.resx">
<Generator>JetResourceGenerator</Generator>
<LastGenOutput>Strings.Designer.fs</LastGenOutput>
Expand All @@ -24,6 +22,10 @@
<DependentUpon>Strings.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<Compile Include="PsiFeaturesNamespaceZoneMarker.fs" />
<Compile Include="PsiNamespaceZoneMarker.fs" />
<Compile Include="src\Options\FSharpTypeHintOptionsPage.fs" />
<Compile Include="src\Options\FSharpTypeHintsOptionsRegistrator.fs" />
<Compile Include="src\ReadLockCookieUtil.fs" />
<Compile Include="src\Highlightings\TypeHintHighlighting.fs" />
<Compile Include="src\ContextHighlighters\FSharpMatchingBraceContextHighlighter.fs" />
Expand All @@ -41,6 +43,7 @@
<Compile Include="src\Stages\FSharpVcsCodeVisionRangesProviderStage.fs" />
<Compile Include="src\Stages\FSharpErrorsStage.fs" />
<Compile Include="src\Stages\PipeChainTypeHintStage.fs" />
<Compile Include="src\Stages\PatternTypeHintsStage.fs" />
<Compile Include="src\Stages\InferredTypeCodeVisionProvider.fs" />
<Compile Include="src\Stages\FSharpSyntaxHighlightingStage.fs" />
<Compile Include="src\Stages\ZoneMarker.fs" />
Expand Down Expand Up @@ -95,4 +98,4 @@
<Import Project="ManagedProject.Generated.Targets" Condition="$(InternalBuild)" />
<Import Project="Sdk.targets" Sdk="JetBrains.NET.Sdk" Version="0.0.4" Condition="$(InternalBuild)" />
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" Condition="!$(InternalBuild)" />
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@ type public Strings() =
static member FSharpInferredTypeHighlighting_ProviderId = Strings.ResourceManager.GetString("FSharpInferredTypeHighlighting_ProviderId")
static member FSharpInferredTypeHighlighting_TooltipText = Strings.ResourceManager.GetString("FSharpInferredTypeHighlighting_TooltipText")
static member InferredTypeCodeVisionProvider_TypeCopied_TooltipText = Strings.ResourceManager.GetString("InferredTypeCodeVisionProvider_TypeCopied_TooltipText")
static member FSharpSignatureHints_SettingsDescription = Strings.ResourceManager.GetString("FSharpSignatureHints_SettingsDescription")
static member FSharpSignatureHints_TopLevelMembersSettings_Header = Strings.ResourceManager.GetString("FSharpSignatureHints_TopLevelMembersSettings_Header")
static member FSharpOptionPageTitle = Strings.ResourceManager.GetString("FSharpOptionPageTitle")
static member FSharpTypeHints_OptionsPage_Title = Strings.ResourceManager.GetString("FSharpTypeHints_OptionsPage_Title")
static member FSharpSignatureHints_LocalBindingsSettings_Header = Strings.ResourceManager.GetString("FSharpSignatureHints_LocalBindingsSettings_Header")
static member FSharpSignatureHints_TopLevelMembersSettings_Comment = Strings.ResourceManager.GetString("FSharpSignatureHints_TopLevelMembersSettings_Comment")
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,22 @@
<data name="InferredTypeCodeVisionProvider_TypeCopied_TooltipText" xml:space="preserve">
<value>Inferred type copied to clipboard</value>
</data>
<data name="FSharpSignatureHints_SettingsDescription" xml:space="preserve">
<value>F# Signature hints settings</value>
</data>
<data name="FSharpSignatureHints_TopLevelMembersSettings_Header" xml:space="preserve">
<value>Top-level bindings and type members </value>
</data>
<data name="FSharpOptionPageTitle" xml:space="preserve">
<value>F#</value>
</data>
<data name="FSharpTypeHints_OptionsPage_Title" xml:space="preserve">
<value>Signatures</value>
</data>
<data name="FSharpSignatureHints_LocalBindingsSettings_Header" xml:space="preserve">
<value>Local bindings</value>
</data>
<data name="FSharpSignatureHints_TopLevelMembersSettings_Comment" xml:space="preserve">
<value>if the 'Never Show' option is selected, Code Vision inferred types will be shown</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ 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.Feature.Services.TypeNameHints
open JetBrains.TextControl.DocumentMarkup.Adornments
open JetBrains.UI.RichText

Expand All @@ -15,19 +17,24 @@ open JetBrains.UI.RichText
AttributeId = AnalysisHighlightingAttributeIds.PARAMETER_NAME_HINT,
OverlapResolve = OverlapResolveKind.NONE,
ShowToolTipInStatusBar = false)>]
type TypeHintHighlighting(typeNameString: string, range: DocumentRange) =
type TypeHintHighlighting(typeNameString: string, range: DocumentRange, pushToHintMode: PushToHintMode) =
let text = RichText(": " + typeNameString)
new (typeNameString: string, range: DocumentRange) =
TypeHintHighlighting(typeNameString, range, PushToHintMode.Default)

interface IHighlighting with
member x.ToolTip = null
member x.ErrorStripeToolTip = null
member x.IsValid() = x.IsValid()
member x.CalculateRange() = range

interface IInlayHintHighlighting

interface IHighlightingWithTestOutput with
member x.TestOutput = text.Text

member x.Text = text
member x.PushToHintMode = pushToHintMode
member x.IsValid() = not text.IsEmpty && range.IsEmpty

and [<SolutionComponent(Instantiation.DemandAnyThreadSafe)>] TypeHintAdornmentProvider() =
Expand All @@ -42,8 +49,8 @@ and [<SolutionComponent(Instantiation.DemandAnyThreadSafe)>] TypeHintAdornmentPr
| :? TypeHintHighlighting as thh ->
let data =
AdornmentData(thh.Text, null, AdornmentFlags.None, AdornmentPlacement.DefaultAfterPrevChar,
PushToHintMode.Default)
thh.PushToHintMode)

{ new IAdornmentDataModel with
override x.ContextMenuTitle = null
override x.ContextMenuItems = null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace JetBrains.ReSharper.Plugins.FSharp.Psi.Daemon.Options

open System.Runtime.InteropServices
open JetBrains.Application.UI.Options
open JetBrains.Application.UI.Options.OptionsDialog
open JetBrains.IDE.UI.Options
open JetBrains.Lifetimes
open JetBrains.ReSharper.Feature.Services.InlayHints
open JetBrains.ReSharper.Plugins.FSharp.Psi.Daemon.Resources
open JetBrains.ReSharper.Plugins.FSharp.Settings

[<OptionsPage(nameof(FSharpInlayHintsPage),
"F#",
null,
Sequence = 3.,
ParentId = InlayHintsOptionsPage.PID,
NameResourceType = typeof<Strings>,
NameResourceName = nameof(Strings.FSharpOptionPageTitle))>]
type FSharpInlayHintsPage(lifetime: Lifetime, optionsPageContext: OptionsPageContext, optionsSettingsSmartContext: OptionsSettingsSmartContext, [<Optional; DefaultParameterValue(false)>] wrapInScrollablePanel) =
inherit BeSimpleOptionsPage(lifetime, optionsPageContext, optionsSettingsSmartContext, wrapInScrollablePanel)


[<OptionsPage(nameof(FSharpTypeHintsOptionsPage),
"Type Hints",
null,
ParentId = nameof(FSharpInlayHintsPage),
NestingType = OptionPageNestingType.Child,
Sequence = 1.,
NameResourceType = typeof<Strings>,
NameResourceName = nameof(Strings.FSharpTypeHints_OptionsPage_Title))>]
type FSharpTypeHintsOptionsPage(lifetime: Lifetime, optionsPageContext: OptionsPageContext,
optionsSettingsSmartContext: OptionsSettingsSmartContext) as this =
inherit InlayHintsOptionPageBase(lifetime, optionsPageContext, optionsSettingsSmartContext, optionsPageContext.IsReSharper)

do
this.AddVisibilityHelpText()

this.AddHeader(Strings.FSharpSignatureHints_TopLevelMembersSettings_Header) |> ignore
this.AddVisibilityOption(fun (s: FSharpTypeHintOptions) -> s.ShowTypeHintsForTopLevelMembers)
this.AddCommentText(Strings.FSharpSignatureHints_TopLevelMembersSettings_Comment)

this.AddHeader(Strings.FSharpSignatureHints_LocalBindingsSettings_Header) |> ignore
this.AddVisibilityOption(fun (s: FSharpTypeHintOptions) -> s.ShowTypeHintsForLocalBindings)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace JetBrains.ReSharper.Plugins.FSharp.Psi.Daemon.Options

open JetBrains.Application.Parts
open JetBrains.Application.Settings
open JetBrains.ProjectModel
open JetBrains.ReSharper.Feature.Services.InlayHints
open JetBrains.ReSharper.Plugins.FSharp.Settings

[<SolutionComponent(InstantiationEx.LegacyDefault)>]
type FSharpTypeHintsOptionsRegistrator(inlayHintsOptionsStore: InlayHintsOptionsStore, settingsStore: ISettingsStore) =
do
let settingsKey = settingsStore.Schema.GetKey<FSharpTypeHintOptions>()
inlayHintsOptionsStore.RegisterSettingsKeyToRehighlightVisibleDocumentOnItsChange(settingsKey)
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@ open JetBrains.ReSharper.Daemon.CodeInsights
open JetBrains.ReSharper.Feature.Services.Daemon
open JetBrains.RdBackend.Common.Features.Services
open JetBrains.ReSharper.Plugins.FSharp
open JetBrains.ReSharper.Plugins.FSharp.Psi.Daemon.Options
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
open JetBrains.ReSharper.Plugins.FSharp.Psi.Tree
open JetBrains.ReSharper.Plugins.FSharp.Psi.Impl
open JetBrains.ReSharper.Plugins.FSharp.Settings
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.Util

module FSharpInferredTypeHighlighting =
Expand Down Expand Up @@ -137,13 +140,14 @@ and InferredTypeCodeVisionProviderProcess(fsFile, settings, daemonProcess, provi

override x.Execute(committer) =
let consumer = FilteringHighlightingConsumer(daemonProcess.SourceFile, fsFile, settings)
let settingsStore = x.DaemonProcess.ContextBoundSettingsStore

let isDisabled =
// todo: fix zoning?
not Shell.Instance.IsTestShell &&

x.DaemonProcess.ContextBoundSettingsStore.GetIndexedValue(
(fun (key: CodeInsightsSettings) -> key.DisabledProviders), FSharpInferredTypeHighlighting.providerId)
settingsStore.GetIndexedValue((fun (key: CodeInsightsSettings) -> key.DisabledProviders), FSharpInferredTypeHighlighting.providerId) ||
settingsStore.GetValue(fun (key: FSharpTypeHintOptions) -> key.ShowTypeHintsForTopLevelMembers) <> PushToHintMode.Never

if not isDisabled then
fsFile.ProcessThisAndDescendants(Processor(x, consumer))
Expand Down
Loading

0 comments on commit b845647

Please sign in to comment.