Skip to content

Commit c68f71e

Browse files
committed
Line continuation fix for ChangeParameterByRefByValQuickFix
1 parent 448d891 commit c68f71e

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

RetailCoder.VBE/Inspections/ChangeParameterByRefByValQuickFix.cs

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
using System;
12
using Antlr4.Runtime;
3+
using Rubberduck.Parsing.Grammar;
24
using Rubberduck.VBEditor;
35

46
namespace Rubberduck.Inspections
@@ -15,16 +17,38 @@ public ChangeParameterByRefByValQuickFix(ParserRuleContext context, QualifiedSel
1517

1618
public override void Fix()
1719
{
18-
var parameter = Context.GetText();
19-
var newContent = string.Concat(_newToken, " ", parameter);
20-
var selection = Selection.Selection;
21-
22-
var module = Selection.QualifiedName.Component.CodeModule;
20+
try
2321
{
24-
var lines = module.GetLines(selection.StartLine, selection.LineCount);
25-
var result = lines.Replace(parameter, newContent);
26-
module.ReplaceLine(selection.StartLine, result);
22+
dynamic context = Context;
23+
var parameter = Context.GetText();
24+
dynamic args = Context.parent;
25+
var argList = args.GetText();
26+
var module = Selection.QualifiedName.Component.CodeModule;
27+
{
28+
string result;
29+
if (context.OPTIONAL() != null)
30+
{
31+
result = parameter.Replace(Tokens.Optional, Tokens.Optional + ' ' + _newToken);
32+
}
33+
else
34+
{
35+
result = _newToken + ' ' + parameter;
36+
}
37+
38+
dynamic proc = args.parent;
39+
var startLine = proc.GetType().GetProperty("Start").GetValue(proc).Line;
40+
var stopLine = proc.GetType().GetProperty("Stop").GetValue(proc).Line;
41+
var code = module.GetLines(startLine, stopLine - startLine + 1);
42+
result = code.Replace(argList, argList.Replace(parameter, result));
43+
44+
foreach (var line in result.Split(new[] {"\r\n"}, StringSplitOptions.None))
45+
{
46+
module.ReplaceLine(startLine++, line);
47+
}
48+
}
2749
}
50+
// ReSharper disable once EmptyGeneralCatchClause
51+
catch { }
2852
}
2953
}
3054
}

RubberduckTests/Inspections/ImplicitByRefParameterInspectionTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,8 @@ bar _
342342
End Sub";
343343

344344
const string expectedCode =
345-
@"Sub Foo(Optional _
346-
ByRef bar _
345+
@"Sub Foo(Optional ByRef _
346+
bar _
347347
As Byte)
348348
bar = 1
349349
End Sub";
@@ -421,7 +421,7 @@ bar _
421421

422422
const string expectedCode =
423423
@"Sub Foo( _
424-
bar _
424+
ByRef bar _
425425
As Byte)
426426
bar = 1
427427
End Sub";

0 commit comments

Comments
 (0)