Skip to content

Commit bb5c80b

Browse files
committed
Implement other pattern matches.
1 parent 15fe865 commit bb5c80b

14 files changed

+66
-5
lines changed

ReSharper.FSharp/src/FSharp.Psi.Intentions/src/QuickFixes/UpdateCompiledNameInSignatureFix.fs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ type UpdateCompiledNameInSignatureFix(error: ValueNotContainedMutabilityCompiled
1717

1818
let mutable bindingImplementation = null
1919
let mutable bindingSignature = null
20+
let mutable signatureCompiledNameAttribute = None
21+
let mutable implementationCompiledNamedAttribute = None
2022

2123
let tryFindCompiledNameAttribute (binding: IBindingLikeDeclaration) =
2224
binding.Attributes
@@ -30,16 +32,17 @@ type UpdateCompiledNameInSignatureFix(error: ValueNotContainedMutabilityCompiled
3032
| Some (BindingPair(implementation, implMember, signature, sigMember)) ->
3133
bindingImplementation <- implementation
3234
bindingSignature <- signature
35+
signatureCompiledNameAttribute <-tryFindCompiledNameAttribute signature
36+
implementationCompiledNamedAttribute <- tryFindCompiledNameAttribute implementation
3337
implMember.Mfv.CompiledName <> sigMember.Mfv.CompiledName
38+
&& (implementationCompiledNamedAttribute.IsSome || signatureCompiledNameAttribute.IsSome)
3439

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

39-
let signatureCompiledNameAttribute = tryFindCompiledNameAttribute bindingSignature
40-
let implementationCompiledNamedAttribute = tryFindCompiledNameAttribute bindingImplementation
4144
match implementationCompiledNamedAttribute, signatureCompiledNameAttribute with
42-
| None, None -> failwith "both don't have the attribute, add the attribute to the signature" // weird situation though
45+
| None, None -> () // This error will not be raised unless one side has a CompiledNameAttribute.
4346
| Some value, None ->
4447
if bindingSignature.Attributes.IsEmpty then
4548
// 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
5255
] |> ignore
5356
else
5457
FSharpAttributesUtil.addAttributeAfter (Seq.last bindingSignature.Attributes) value
55-
| None, Some value -> failwith "add the attribute to the signature"
56-
| Some value, Some value1 -> failwith "update the value of the signature"
58+
| None, Some sigAttr ->
59+
let parentAttributeList = AttributeListNavigator.GetByAttribute(sigAttr)
60+
if parentAttributeList.Attributes.Count = 1 then
61+
deleteChild parentAttributeList
62+
else
63+
deleteChild sigAttr
64+
| Some implAttr, Some sigAttr ->
65+
sigAttr.SetArgExpression(implAttr.ArgExpression)
66+
|> ignore
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module A
2+
3+
[<CompiledName("X")>]
4+
let x{caret} (a:int) (b:int) = a + 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module A
2+
3+
[<CompiledName("X")>]
4+
let x{caret} (a:int) (b:int) = a + 1
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module A
2+
3+
[<CompiledName("Y")>]
4+
val x: a:int -> b:int -> int
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module A
2+
3+
[<CompiledName("X")>]
4+
val x: a:int -> b:int -> int
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module A
2+
3+
let x{caret} (a:int) (b:int) = a + 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module A
2+
3+
let x{caret} (a:int) (b:int) = a + 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module A
2+
3+
[<CompiledName("Y")>]
4+
val x: a:int -> b:int -> int
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module A
2+
3+
4+
val x: a:int -> b:int -> int
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module A
2+
3+
[<System.Obsolete "meh">]
4+
let x{caret} (a:int) (b:int) = a + 1

0 commit comments

Comments
 (0)