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

Add code fix for adding missing seq before {…} #787

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
**/.DS_Store
NuGet.Config
.gradle/
.gradle/
.idea

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

3 changes: 3 additions & 0 deletions ReSharper.FSharp/ReSharper.FSharp.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=Constants/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb"&gt;&lt;ExtraRule Prefix="" Suffix="" Style="AA_BB" /&gt;&lt;/Policy&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="my" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=4a98fdf6_002D7d98_002D4f5a_002Dafeb_002Dea44ad98c70c/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Instance" AccessRightKinds="Private" Description="Instance fields (private)"&gt;&lt;ElementKinds&gt;&lt;Kind Name="FIELD" /&gt;&lt;Kind Name="READONLY_FIELD" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="my" Suffix="" Style="AaBb" /&gt;&lt;/Policy&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=669e5282_002Dfb4b_002D4e90_002D91e7_002D07d269d04b60/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Any" AccessRightKinds="Protected, ProtectedInternal, Internal, Public, PrivateProtected" Description="Constant fields (not private)"&gt;&lt;ElementKinds&gt;&lt;Kind Name="CONSTANT_FIELD" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="AaBb"&gt;&lt;ExtraRule Prefix="" Suffix="" Style="AA_BB" /&gt;&lt;/Policy&gt;&lt;/Policy&gt;</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EPredefinedNamingRulesToUserRulesUpgrade/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/FSharp/FSharpOptions/EnableOutOfScopeCompletion/@EntryValue">False</s:Boolean>

<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/INDENT_SIZE/@EntryValue">2</s:Int64>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ module FSharpErrors =
let [<Literal>] SingleQuoteInSingleQuote = 3373
let [<Literal>] XmlDocSignatureCheckFailed = 3390
let [<Literal>] InvalidXmlDocPosition = 3520
let [<Literal>] ConstructDeprecatedSequenceExpressionsInvalidForm = 3873
let [<Literal>] InvalidRecordSequenceOrComputationExpression = 740

let isDirectiveSyntaxError number =
number >= 232 && number <= 235
Expand Down Expand Up @@ -526,6 +528,12 @@ type FcsErrorsStageProcessBase(fsFile, daemonProcess) =
| UnionCaseDoesNotTakeArguments ->
createHighlightingFromNode UnionCaseDoesNotTakeArgumentsError range

| InvalidRecordSequenceOrComputationExpression ->
createHighlightingFromNode InvalidRecordSequenceOrComputationExpressionError range

| ConstructDeprecatedSequenceExpressionsInvalidForm ->
createHighlightingFromNode ConstructDeprecatedSequenceExpressionsInvalidFormError range

| UnionCaseExpectsTupledArguments ->
createHighlightingFromNodeWithMessage UnionCaseExpectsTupledArgumentsError range error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
<Compile Include="src\QuickFixes\UpdateRecordFieldsInSignatureFix.fs" />
<Compile Include="src\QuickFixes\UpdateRecordFieldTypeInSignatureFix.fs" />
<Compile Include="src\QuickFixes\RemovePatternArgumentFix.fs" />
<Compile Include="src\QuickFixes\AddMissingSeqFix.fs" />
<Compile Include="src\QuickFixes\AddSetterFix.fs" />
<Compile Include="src\QuickFixes\UpdateMutabilityInSignatureFix.fs" />
<Compile Include="src\QuickFixes\UseNestedRecordFieldSyntaxFix.fs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace JetBrains.ReSharper.Plugins.FSharp.Psi.Features.Daemon.QuickFixes

open JetBrains.ReSharper.Plugins.FSharp.Psi
open JetBrains.ReSharper.Plugins.FSharp.Psi.Features.Daemon.Highlightings
open JetBrains.ReSharper.Plugins.FSharp.Psi.Features.Daemon.QuickFixes
open JetBrains.ReSharper.Plugins.FSharp.Psi.Tree
open JetBrains.ReSharper.Psi.ExtensionsAPI
open JetBrains.ReSharper.Resources.Shell
open JetBrains.ReSharper.Psi.ExtensionsAPI.Tree

type AddMissingSeqFix(expr: IComputationExpr) =
inherit FSharpQuickFixBase()

new(error: ConstructDeprecatedSequenceExpressionsInvalidFormError) =
AddMissingSeqFix(error.ComputationExpr)

new(error: InvalidRecordSequenceOrComputationExpressionError) =
AddMissingSeqFix(error.ComputationExpr)

override x.Text = "Add missing 'seq'"

override x.IsAvailable _ =
isValid expr

override x.ExecutePsiTransaction _ =
use writeCookie = WriteLockCookie.Create(expr.IsPhysical())
use disableFormatter = new DisableCodeFormatter()

let factory = expr.Expression.CreateElementFactory()
let seqExpr = factory.CreateExpr("seq")
let newAppExpr = factory.CreateAppExpr(seqExpr, expr, true)

ModificationUtil.ReplaceChild(expr, newAppExpr) |> ignore

Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ type public Strings() =
static member ThisLiteralPatternDoesNotTakeArgumentsMessage = Strings.ResourceManager.GetString("ThisLiteralPatternDoesNotTakeArgumentsMessage")
static member ThisRuleWillNeverBeMatchedMessage = Strings.ResourceManager.GetString("ThisRuleWillNeverBeMatchedMessage")
static member ThisUnionCaseDoesNotTakeArgumentsMessage = Strings.ResourceManager.GetString("ThisUnionCaseDoesNotTakeArgumentsMessage")
static member InvalidRecordSequenceOrComputationExpressionMessage = Strings.ResourceManager.GetString("InvalidRecordSequenceOrComputationExpressionMessage")
static member ConstructDeprecatedSequenceExpressionInvalidFormMessage = Strings.ResourceManager.GetString("ConstructDeprecatedSequenceExpressionInvalidFormMessage")
static member TypeAbbreviationsCannotHaveAugmentationsMessage = Strings.ResourceManager.GetString("TypeAbbreviationsCannotHaveAugmentationsMessage")
static member UnknownParameterNameMessage = Strings.ResourceManager.GetString("UnknownParameterNameMessage")
static member UpcastIsUnnecessaryMessage = Strings.ResourceManager.GetString("UpcastIsUnnecessaryMessage")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,12 @@
<data name="ThisUnionCaseDoesNotTakeArgumentsMessage" xml:space="preserve">
<value>This union case does not take arguments</value>
</data>
<data name="InvalidRecordSequenceOrComputationExpressionMessage" xml:space="preserve">
<value>Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq { ... }'</value>
</data>
<data name="ConstructDeprecatedSequenceExpressionInvalidFormMessage" xml:space="preserve">
<value>This construct is deprecated. Sequence expressions should be of the form 'seq { ... }'</value>
</data>
<data name="TypeAbbreviationsCannotHaveAugmentationsMessage" xml:space="preserve">
<value>Type abbreviations cannot have augmentations</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,22 @@
<QuickFix>RemovePatternArgumentFix</QuickFix>
</Error>

<Error staticGroup="FSharpErrors" name="ConstructDeprecatedSequenceExpressionsInvalidForm" ID="FS3873: This construct is deprecated. Sequence expressions should be of the form 'seq {{ ... }}'">
<Parameter type="IComputationExpr" name="computationExpr"/>
<Message resourceName="ConstructDeprecatedSequenceExpressionInvalidFormMessage" resourceType="Strings"/>
<Range>computationExpr.GetHighlightingRange()</Range>
<Behavour overlapResolvePolicy="NONE"/>
<QuickFix>AddMissingSeqFix</QuickFix>
</Error>

<Error staticGroup="FSharpErrors" name="InvalidRecordSequenceOrComputationExpression" ID="FS740: Invalid record, sequence or computation expression. Sequence expressions should be of the form 'seq { ... }'">
<Parameter type="IComputationExpr" name="computationExpr"/>
<Message resourceName="InvalidRecordSequenceOrComputationExpressionMessage" resourceType="Strings"/>
<Range>computationExpr.GetHighlightingRange()</Range>
<Behavour overlapResolvePolicy="NONE"/>
<QuickFix>AddMissingSeqFix</QuickFix>
</Error>

<Error staticGroup="FSharpErrors" name="AttributeIsNotValidOnThisElement" ID="FS0842: This attribute is not valid for use on this language element">
<Parameter type="IAttribute" name="attribute"/>
<Parameter type="string" name="fcsMessage"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{caret}{ 1;10 }
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
<Compile Include="src\QuickFixes\UpdateRecordFieldsInSignatureFixTest.fs" />
<Compile Include="src\QuickFixes\UpdateRecordFieldTypeInSignatureFixTest.fs" />
<Compile Include="src\QuickFixes\RemovePatternArgumentFixTest.fs" />
<Compile Include="src\QuickFixes\AddMissingSeqFixTest.fs" />
<Compile Include="src\QuickFixes\AddSetterFixTest.fs" />
<Compile Include="src\QuickFixes\UpdateMutabilityInSignatureFixTest.fs" />
<Compile Include="src\QuickFixes\UseNestedRecordFieldSyntaxTest.fs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace JetBrains.ReSharper.Plugins.FSharp.Tests.Intentions.QuickFixes

open JetBrains.ReSharper.Plugins.FSharp.Psi.Features.Daemon.QuickFixes
open JetBrains.ReSharper.Plugins.FSharp.Tests
open NUnit.Framework

[<FSharpTest>]
type AddMissingSeqFixTest() =
inherit FSharpQuickFixTestBase<AddMissingSeqFix>()

override x.RelativeTestDataPath = "features/quickFixes/addMissingSeqFix"

[<Test>] member x.``FS0740 — Adds missing seq before { x; y }`` () = x.DoNamedTest()
15 changes: 0 additions & 15 deletions rider-fsharp/.idea/dictionaries/Mikhail_Filippov.xml

This file was deleted.

7 changes: 0 additions & 7 deletions rider-fsharp/.idea/dictionaries/mfilippov.xml

This file was deleted.

Binary file removed rider-fsharp/.idea/icon.png
Binary file not shown.
Binary file removed rider-fsharp/.idea/icon_dark.png
Binary file not shown.
Loading