Skip to content

Commit b53f353

Browse files
authored
Merge pull request #6014 from awb95/dev-4795-Indenter_Declare_PtrSafe
Fix Indenter "Declare PtrSafe"
2 parents 5ff67f4 + fccbe4e commit b53f353

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

Rubberduck.SmartIndenter/AbsoluteCodeLine.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class AbsoluteCodeLine
1616

1717
private static readonly Regex PropertyStartRegex = new Regex(@"^(Public\s|Private\s|Friend\s)?(Static\s)?(Property\s(Let|Get|Set))\s", RegexOptions.IgnoreCase);
1818

19-
private static readonly Regex ProcedureStartIgnoreRegex = new Regex(@"^[LR]?Set\s|^Let\s|^(Public|Private)\sDeclare\s(Function|Sub)", RegexOptions.IgnoreCase);
19+
private static readonly Regex ProcedureStartIgnoreRegex = new Regex(@"^[LR]?Set\s|^Let\s|^(Public\s|Private\s)?Declare\s(PtrSafe\s)?(Function|Sub)", RegexOptions.IgnoreCase);
2020
private static readonly Regex ProcedureEndRegex = new Regex(@"^End\s(Sub|Function|Property)", RegexOptions.IgnoreCase);
2121
private static readonly Regex TypeEnumStartRegex = new Regex(@"^(Public\s|Private\s)?(Enum\s|Type\s)", RegexOptions.IgnoreCase);
2222
private static readonly Regex TypeEnumEndRegex = new Regex(@"^End\s(Enum|Type)", RegexOptions.IgnoreCase);

Rubberduck.SmartIndenter/LogicalCodeLine.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public override string ToString()
202202
return _lines.Aggregate(string.Empty, (x, y) => x + y.ToString());
203203
}
204204

205-
private static readonly Regex StartIgnoreRegex = new Regex(@"^(\d*\s)?\s*[LR]?Set\s|^(\d*\s)?\s*Let\s|^(\d*\s)?\s*(Public|Private)\sDeclare\s(Function|Sub)|^(\d*\s+)", RegexOptions.IgnoreCase);
205+
private static readonly Regex StartIgnoreRegex = new Regex(@"^(\d*\s)?\s*[LR]?Set\s|^(\d*\s)?\s*Let\s|^(\d*\s)?\s*(Public\s|Private\s)?Declare\s(PtrSafe\s)?(Function|Sub)|^(\d*\s+)", RegexOptions.IgnoreCase);
206206
private readonly Stack<AlignmentToken> _alignment = new Stack<AlignmentToken>();
207207
private int _nestingDepth;
208208

RubberduckTests/SmartIndenter/LineContinuationTests.cs

+22
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,28 @@ public void DeclarationLineAlignsCorrectly()
2929
Assert.IsTrue(expected.SequenceEqual(actual));
3030
}
3131

32+
// https://github.com/rubberduck-vba/Rubberduck/issues/4795
33+
[Test]
34+
[Category("Indenter")]
35+
public void DeclarationPtrSafeLineAlignsCorrectly()
36+
{
37+
var code = new[]
38+
{
39+
@"Private Declare PtrSafe Function Foo Lib ""bar.dll"" _",
40+
"(x As Long y As Long) As LongPtr"
41+
};
42+
43+
var expected = new[]
44+
{
45+
@"Private Declare PtrSafe Function Foo Lib ""bar.dll"" _",
46+
" (x As Long y As Long) As LongPtr"
47+
};
48+
49+
var indenter = new Indenter(null, () => IndenterSettingsTests.GetMockIndenterSettings());
50+
var actual = indenter.Indent(code);
51+
Assert.IsTrue(expected.SequenceEqual(actual));
52+
}
53+
3254
[Test]
3355
[Category("Indenter")]
3456
public void FunctionParametersAlignCorrectly()

0 commit comments

Comments
 (0)