Skip to content

Commit ebe7164

Browse files
committed
(PowerShellGH-812) Update folder for DSC style scripts
Previously the code folding was not tested against DSC configuration scripts. This commit; * Adds tests for a sample DSC script to ensure the folding occurs at the correct places * Adds an AST visitor for the ParamBlockAST object. This typically spans multiple lines. This commit also adds tests for this scenario
1 parent e33ba46 commit ebe7164

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

src/PowerShellEditorServices/Language/FindFoldsVisitor.cs

+6
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ public override AstVisitAction VisitHashtable(HashtableAst objAst)
6969
return AstVisitAction.Continue;
7070
}
7171

72+
public override AstVisitAction VisitParamBlock(ParamBlockAst objAst)
73+
{
74+
if (IsValidFoldingExtent(objAst.Extent)) { this.FoldableRegions.Add(CreateFoldingReference(objAst.Extent, RegionKindNone)); }
75+
return AstVisitAction.Continue;
76+
}
77+
7278
public override AstVisitAction VisitStatementBlock(StatementBlockAst objAst)
7379
{
7480
// These parent visitors will get this AST Object. No need to process it

test/PowerShellEditorServices.Test/Language/TokenOperationsTests.cs

+53
Original file line numberDiff line numberDiff line change
@@ -246,5 +246,58 @@ public void LaguageServiceFindsFoldablRegionsWithSameEndToken() {
246246

247247
AssertFoldingReferenceArrays(expectedFolds, result);
248248
}
249+
250+
// This tests DSC style keywords and param blocks
251+
[Fact]
252+
public void LaguageServiceFindsFoldablRegionsWithDSC() {
253+
string testString =
254+
@"Configuration Example
255+
{
256+
param
257+
(
258+
[Parameter()]
259+
[System.String[]]
260+
$NodeName = 'localhost',
261+
262+
[Parameter(Mandatory = $true)]
263+
[ValidateNotNullorEmpty()]
264+
[System.Management.Automation.PSCredential]
265+
$Credential
266+
)
267+
268+
Import-DscResource -Module ActiveDirectoryCSDsc
269+
270+
Node $AllNodes.NodeName
271+
{
272+
WindowsFeature ADCS-Cert-Authority
273+
{
274+
Ensure = 'Present'
275+
Name = 'ADCS-Cert-Authority'
276+
}
277+
278+
AdcsCertificationAuthority CertificateAuthority
279+
{
280+
IsSingleInstance = 'Yes'
281+
Ensure = 'Present'
282+
Credential = $Credential
283+
CAType = 'EnterpriseRootCA'
284+
DependsOn = '[WindowsFeature]ADCS-Cert-Authority'
285+
}
286+
}
287+
}
288+
";
289+
FoldingReference[] expectedFolds = {
290+
CreateFoldingReference(1, 0, 32, 1, null),
291+
CreateFoldingReference(2, 4, 11, 5, null),
292+
CreateFoldingReference(17, 4, 31, 5, null),
293+
CreateFoldingReference(19, 8, 21, 9, null),
294+
CreateFoldingReference(25, 8, 30, 9, null)
295+
};
296+
297+
FoldingReference[] result = GetRegions(testString);
298+
299+
AssertFoldingReferenceArrays(expectedFolds, result);
300+
}
301+
249302
}
250303
}

0 commit comments

Comments
 (0)