Skip to content

Commit d7a465f

Browse files
committed
(GH-811) Add support for unoppinionated variable name in folder
Previously the code folder was not aware of unoppinionated variable name assignments. This commit adds detection and an appropriate test.
1 parent 02273eb commit d7a465f

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/PowerShellEditorServices/Language/TokenOperations.cs

+5
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ internal static FoldingReference[] FoldableRegions(
4747
MatchTokenElement(tokens, TokenKind.HereStringLiteral, RegionKindNone)
4848
);
4949

50+
// Find unoppinionated variable names ${ \n \n }
51+
foldableRegions.AddRange(
52+
MatchTokenElement(tokens, TokenKind.Variable, RegionKindNone)
53+
);
54+
5055
// Find contiguous here strings @" -> "@
5156
foldableRegions.AddRange(
5257
MatchTokenElement(tokens, TokenKind.HereStringExpandable, RegionKindNone)

test/PowerShellEditorServices.Test/Language/TokenOperationsTests.cs

+9-3
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,13 @@ double quoted herestrings should also fold
111111
# Comment Block 2
112112
# Comment Block 2
113113
$something = $true
114-
#endregion Comment Block 3";
114+
#endregion Comment Block 3
115+
116+
# What about anonynous variable assignment
117+
${this
118+
is
119+
valid} = 5
120+
";
115121
private FoldingReference[] expectedAllInOneScriptFolds = {
116122
CreateFoldingReference(0, 0, 3, 10, "region"),
117123
CreateFoldingReference(1, 0, 2, 2, "comment"),
@@ -127,7 +133,8 @@ double quoted herestrings should also fold
127133
CreateFoldingReference(56, 7, 58, 3, null),
128134
CreateFoldingReference(64, 0, 65, 0, "comment"),
129135
CreateFoldingReference(67, 0, 71, 26, "region"),
130-
CreateFoldingReference(68, 0, 69, 0, "comment")
136+
CreateFoldingReference(68, 0, 69, 0, "comment"),
137+
CreateFoldingReference(75, 0, 76, 6, null),
131138
};
132139

133140
/// <summary>
@@ -244,6 +251,5 @@ public void LaguageServiceFindsFoldablRegionsWithSameEndToken() {
244251

245252
AssertFoldingReferenceArrays(expectedFolds, result);
246253
}
247-
248254
}
249255
}

0 commit comments

Comments
 (0)