Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement other pattern matches.
Browse files Browse the repository at this point in the history
nojaf committed Jul 17, 2023
1 parent 7629779 commit 578f5d7
Showing 14 changed files with 66 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -17,6 +17,8 @@ type UpdateCompiledNameInSignatureFix(error: ValueNotContainedMutabilityCompiled

let mutable bindingImplementation = null
let mutable bindingSignature = null
let mutable signatureCompiledNameAttribute = None
let mutable implementationCompiledNamedAttribute = None

let tryFindCompiledNameAttribute (binding: IBindingLikeDeclaration) =
binding.Attributes
@@ -30,16 +32,17 @@ type UpdateCompiledNameInSignatureFix(error: ValueNotContainedMutabilityCompiled
| Some (BindingPair(implementation, implMember, signature, sigMember)) ->
bindingImplementation <- implementation
bindingSignature <- signature
signatureCompiledNameAttribute <-tryFindCompiledNameAttribute signature
implementationCompiledNamedAttribute <- tryFindCompiledNameAttribute implementation
implMember.Mfv.CompiledName <> sigMember.Mfv.CompiledName
&& (implementationCompiledNamedAttribute.IsSome || signatureCompiledNameAttribute.IsSome)

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

let signatureCompiledNameAttribute = tryFindCompiledNameAttribute bindingSignature
let implementationCompiledNamedAttribute = tryFindCompiledNameAttribute bindingImplementation
match implementationCompiledNamedAttribute, signatureCompiledNameAttribute with
| None, None -> failwith "both don't have the attribute, add the attribute to the signature" // weird situation though
| None, None -> () // This error will not be raised unless one side has a CompiledNameAttribute.
| Some value, None ->
if bindingSignature.Attributes.IsEmpty then
// We create an elementFactory with the implementation file because the CreateEmptyAttributeList is tied to implementation files only.
@@ -52,5 +55,12 @@ type UpdateCompiledNameInSignatureFix(error: ValueNotContainedMutabilityCompiled
] |> ignore
else
FSharpAttributesUtil.addAttributeAfter (Seq.last bindingSignature.Attributes) value
| None, Some value -> failwith "add the attribute to the signature"
| Some value, Some value1 -> failwith "update the value of the signature"
| None, Some sigAttr ->
let parentAttributeList = AttributeListNavigator.GetByAttribute(sigAttr)
if parentAttributeList.Attributes.Count = 1 then
deleteChild parentAttributeList
else
deleteChild sigAttr
| Some implAttr, Some sigAttr ->
sigAttr.SetArgExpression(implAttr.ArgExpression)
|> ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module A

[<CompiledName("X")>]
let x{caret} (a:int) (b:int) = a + 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module A

[<CompiledName("X")>]
let x{caret} (a:int) (b:int) = a + 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module A

[<CompiledName("Y")>]
val x: a:int -> b:int -> int
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module A

[<CompiledName("X")>]
val x: a:int -> b:int -> int
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module A

let x{caret} (a:int) (b:int) = a + 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module A

let x{caret} (a:int) (b:int) = a + 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module A

[<CompiledName("Y")>]
val x: a:int -> b:int -> int
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module A


val x: a:int -> b:int -> int
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module A

[<System.Obsolete "meh">]
let x{caret} (a:int) (b:int) = a + 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module A

[<System.Obsolete "meh">]
let x{caret} (a:int) (b:int) = a + 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module A

[<CompiledName("Y")>]
[<System.Obsolete "meh">]
val x: a:int -> b:int -> int
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module A


[<System.Obsolete "meh">]
val x: a:int -> b:int -> int
Original file line number Diff line number Diff line change
@@ -9,3 +9,6 @@ type UpdateCompiledNameInSignatureFixTest() =
override x.RelativeTestDataPath = "features/quickFixes/updateCompiledNameInSignatureFix"

[<Test>] member x.``Attribute in implementation - 01`` () = x.DoNamedTestWithSignature()
[<Test>] member x.``Attribute in implementation - 02`` () = x.DoNamedTestWithSignature()
[<Test>] member x.``No attribute in implementation - 01`` () = x.DoNamedTestWithSignature()
[<Test>] member x.``No attribute in implementation - 02`` () = x.DoNamedTestWithSignature()

0 comments on commit 578f5d7

Please sign in to comment.