Skip to content

Commit f26755f

Browse files
committed
Revert "Fix PowerShell#827 Pester TestName w/expandable str returns nothing (PowerShell#851)"
This reverts commit 161a3ed.
1 parent 9358709 commit f26755f

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

src/PowerShellEditorServices/Symbols/PesterDocumentSymbolProvider.cs

+6-19
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ IEnumerable<SymbolReference> IDocumentSymbolProvider.ProvideDocumentSymbols(
3232

3333
return commandAsts.OfType<CommandAst>()
3434
.Where(IsPesterCommand)
35-
.Select(ast => ConvertPesterAstToSymbolReference(scriptFile, ast));
35+
.Select(ast => ConvertPesterAstToSymbolReference(scriptFile, ast))
36+
.Where(pesterSymbol => pesterSymbol?.TestName != null);
3637
}
3738

3839
/// <summary>
@@ -104,21 +105,20 @@ private static PesterSymbolReference ConvertPesterAstToSymbolReference(ScriptFil
104105
// Check for an explicit "-Name" parameter
105106
if (currentCommandElement is CommandParameterAst parameterAst)
106107
{
107-
// Found -Name parameter, move to next element which is the argument for -TestName
108108
i++;
109-
110-
if (!alreadySawName && TryGetTestNameArgument(pesterCommandAst.CommandElements[i], out testName))
109+
if (parameterAst.ParameterName == "Name" && i < pesterCommandAst.CommandElements.Count)
111110
{
111+
testName = alreadySawName ? null : (pesterCommandAst.CommandElements[i] as StringConstantExpressionAst)?.Value;
112112
alreadySawName = true;
113113
}
114-
115114
continue;
116115
}
117116

118117
// Otherwise, if an argument is given with no parameter, we assume it's the name
119118
// If we've already seen a name, we set the name to null
120-
if (!alreadySawName && TryGetTestNameArgument(pesterCommandAst.CommandElements[i], out testName))
119+
if (pesterCommandAst.CommandElements[i] is StringConstantExpressionAst testNameStrAst)
121120
{
121+
testName = alreadySawName ? null : testNameStrAst.Value;
122122
alreadySawName = true;
123123
}
124124
}
@@ -131,19 +131,6 @@ private static PesterSymbolReference ConvertPesterAstToSymbolReference(ScriptFil
131131
pesterCommandAst.Extent
132132
);
133133
}
134-
135-
private static bool TryGetTestNameArgument(CommandElementAst commandElementAst, out string testName)
136-
{
137-
testName = null;
138-
139-
if (commandElementAst is StringConstantExpressionAst testNameStrAst)
140-
{
141-
testName = testNameStrAst.Value;
142-
return true;
143-
}
144-
145-
return (commandElementAst is ExpandableStringExpressionAst);
146-
}
147134
}
148135

149136
/// <summary>

0 commit comments

Comments
 (0)