Skip to content

Commit 6f5fdc3

Browse files
committed
Clean up command AST parsing
1 parent 872a5c6 commit 6f5fdc3

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/PowerShellEditorServices/Symbols/PesterDocumentSymbolProvider.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private static bool IsPesterCommand(CommandAst commandAst)
9090
private static PesterSymbolReference ConvertPesterAstToSymbolReference(ScriptFile scriptFile, CommandAst pesterCommandAst)
9191
{
9292
string testLine = scriptFile.GetLine(pesterCommandAst.Extent.StartLineNumber);
93-
string commandName = (pesterCommandAst.CommandElements[0] as StringConstantExpressionAst)?.Value;
93+
string commandName = pesterCommandAst.GetCommandName();
9494

9595
// Search for a name for the test
9696
string testName = null;
@@ -159,12 +159,9 @@ public class PesterSymbolReference : SymbolReference
159159
/// Lookup for Pester keywords we support. Ideally we could extract these from Pester itself
160160
/// </summary>
161161
internal static readonly IReadOnlyDictionary<string, PesterCommandType> PesterKeywords =
162-
new Dictionary<string, PesterCommandType>(StringComparer.OrdinalIgnoreCase)
163-
{
164-
{ "Describe", PesterCommandType.Describe },
165-
{ "Context", PesterCommandType.Context },
166-
{ "It", PesterCommandType.It }
167-
};
162+
Enum.GetValues(typeof(PesterCommandType))
163+
.Cast<PesterCommandType>()
164+
.ToDictionary(pct => pct.ToString(), pct => pct);
168165

169166
private static char[] DefinitionTrimChars = new char[] { ' ', '{' };
170167

0 commit comments

Comments
 (0)