Skip to content

Commit d937945

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 ffe2485 commit d937945

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
@@ -64,6 +64,12 @@ public override AstVisitAction VisitHashtable(HashtableAst objAst)
6464
return AstVisitAction.Continue;
6565
}
6666

67+
public override AstVisitAction VisitParamBlock(ParamBlockAst objAst)
68+
{
69+
if (IsValidFoldingExtent(objAst.Extent)) { this.FoldableRegions.Add(CreateFoldingReference(objAst.Extent, RegionKindNone)); }
70+
return AstVisitAction.Continue;
71+
}
72+
6773
public override AstVisitAction VisitStatementBlock(StatementBlockAst objAst)
6874
{
6975
// 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
@@ -261,5 +261,58 @@ public void LaguageServiceFindsFoldablRegionsWithSameEndToken() {
261261

262262
AssertFoldingReferenceArrays(expectedFolds, result);
263263
}
264+
265+
// This tests DSC style keywords and param blocks
266+
[Fact]
267+
public void LaguageServiceFindsFoldablRegionsWithDSC() {
268+
string testString =
269+
@"Configuration Example
270+
{
271+
param
272+
(
273+
[Parameter()]
274+
[System.String[]]
275+
$NodeName = 'localhost',
276+
277+
[Parameter(Mandatory = $true)]
278+
[ValidateNotNullorEmpty()]
279+
[System.Management.Automation.PSCredential]
280+
$Credential
281+
)
282+
283+
Import-DscResource -Module ActiveDirectoryCSDsc
284+
285+
Node $AllNodes.NodeName
286+
{
287+
WindowsFeature ADCS-Cert-Authority
288+
{
289+
Ensure = 'Present'
290+
Name = 'ADCS-Cert-Authority'
291+
}
292+
293+
AdcsCertificationAuthority CertificateAuthority
294+
{
295+
IsSingleInstance = 'Yes'
296+
Ensure = 'Present'
297+
Credential = $Credential
298+
CAType = 'EnterpriseRootCA'
299+
DependsOn = '[WindowsFeature]ADCS-Cert-Authority'
300+
}
301+
}
302+
}
303+
";
304+
FoldingReference[] expectedFolds = {
305+
CreateFoldingReference(1, 0, 32, 1, null),
306+
CreateFoldingReference(2, 4, 11, 5, null),
307+
CreateFoldingReference(17, 4, 31, 5, null),
308+
CreateFoldingReference(19, 8, 21, 9, null),
309+
CreateFoldingReference(25, 8, 30, 9, null)
310+
};
311+
312+
FoldingReference[] result = GetRegions(testString);
313+
314+
AssertFoldingReferenceArrays(expectedFolds, result);
315+
}
316+
264317
}
265318
}

0 commit comments

Comments
 (0)