Skip to content

Commit 83b4634

Browse files
authored
Merge pull request #2093 from Hosch250/Issue2063
Fix search/replace bug in VariableTypeNotDeclared quick fix
2 parents d8aefb5 + 71ef474 commit 83b4634

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

RetailCoder.VBE/Inspections/VariableTypeNotDeclaredInspectionResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public override void Fix()
6666
return;
6767
}
6868

69-
var fixedCodeLine = codeLine.Replace(originalInstruction, fix);
69+
var fixedCodeLine = codeLine.Remove(Context.Start.Column, originalInstruction.Length).Insert(Context.Start.Column, fix);
7070
codeModule.ReplaceLine(Selection.Selection.StartLine, fixedCodeLine);
7171
}
7272

RubberduckTests/Inspections/VariableTypeNotDeclaredInspectionTests.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,38 @@ public void VariableTypeNotDeclared_QuickFixWorks_Parameter()
279279
Assert.AreEqual(expectedCode, actual);
280280
}
281281

282+
[TestMethod]
283+
[TestCategory("Inspections")]
284+
public void VariableTypeNotDeclared_QuickFixWorks_SubNameContainsParameterName()
285+
{
286+
const string inputCode =
287+
@"Sub Foo(Foo)
288+
End Sub";
289+
290+
const string expectedCode =
291+
@"Sub Foo(Foo As Variant)
292+
End Sub";
293+
294+
//Arrange
295+
var builder = new MockVbeBuilder();
296+
VBComponent component;
297+
var vbe = builder.BuildFromSingleStandardModule(inputCode, out component);
298+
var project = vbe.Object.VBProjects.Item(0);
299+
var module = project.VBComponents.Item(0).CodeModule;
300+
var mockHost = new Mock<IHostApplication>();
301+
mockHost.SetupAllProperties();
302+
var parser = MockParser.Create(vbe.Object, new RubberduckParserState(vbe.Object, new Mock<ISinks>().Object));
303+
304+
parser.Parse(new CancellationTokenSource());
305+
if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); }
306+
307+
var inspection = new VariableTypeNotDeclaredInspection(parser.State);
308+
inspection.GetInspectionResults().First().QuickFixes.First().Fix();
309+
310+
var actual = module.Lines();
311+
Assert.AreEqual(expectedCode, actual);
312+
}
313+
282314
[TestMethod]
283315
[TestCategory("Inspections")]
284316
public void VariableTypeNotDeclared_QuickFixWorks_Variable()

0 commit comments

Comments
 (0)