66using System . Linq ;
77using System . Management . Automation . Language ;
88using Microsoft . PowerShell . EditorServices . Services . TextDocument ;
9+ using Microsoft . PowerShell . EditorServices . Services . PowerShell . Utility ;
910
1011namespace Microsoft . PowerShell . EditorServices . Services . Symbols
1112{
@@ -42,8 +43,7 @@ IEnumerable<SymbolReference> IDocumentSymbolProvider.ProvideDocumentSymbols(
4243 private static bool IsNamedCommandWithArguments ( Ast ast )
4344 {
4445 return ast is CommandAst commandAst &&
45- commandAst . InvocationOperator != TokenKind . Dot &&
46- PesterSymbolReference . GetCommandType ( commandAst . GetCommandName ( ) ) . HasValue &&
46+ commandAst . InvocationOperator is not ( TokenKind . Dot or TokenKind . Ampersand ) &&
4747 commandAst . CommandElements . Count >= 2 ;
4848 }
4949
@@ -59,8 +59,10 @@ private static bool IsPesterCommand(CommandAst commandAst)
5959 return false ;
6060 }
6161
62- // Ensure the first word is a Pester keyword
63- if ( ! PesterSymbolReference . PesterKeywords . ContainsKey ( commandAst . GetCommandName ( ) ) )
62+ // Ensure the first word is a Pester keyword and in Pester-module if using module-qualified call
63+ string commandName = CommandHelpers . StripModuleQualification ( commandAst . GetCommandName ( ) , out ReadOnlyMemory < char > module ) ;
64+ if ( ! PesterSymbolReference . PesterKeywords . ContainsKey ( commandName ) ||
65+ ( ! module . IsEmpty && ! module . Span . Equals ( "pester" . AsSpan ( ) , StringComparison . OrdinalIgnoreCase ) ) )
6466 {
6567 return false ;
6668 }
@@ -90,14 +92,16 @@ private static PesterSymbolReference ConvertPesterAstToSymbolReference(ScriptFil
9092 . TrimStart ( )
9193 . TrimEnd ( DefinitionTrimChars ) ;
9294
93- PesterCommandType ? commandName = PesterSymbolReference . GetCommandType ( pesterCommandAst . GetCommandName ( ) ) ;
94- if ( commandName == null )
95+ string commandName = CommandHelpers . StripModuleQualification ( pesterCommandAst . GetCommandName ( ) , out _ ) ;
96+ PesterCommandType ? commandType = PesterSymbolReference . GetCommandType ( commandName ) ;
97+ if ( commandType == null )
9598 {
9699 return null ;
97100 }
98101
99102 string testName = null ;
100- if ( PesterSymbolReference . IsPesterTestCommand ( commandName . Value ) ) {
103+ if ( PesterSymbolReference . IsPesterTestCommand ( commandType . Value ) )
104+ {
101105 // Search for a name for the test
102106 // If the test has more than one argument for names, we set it to null
103107 bool alreadySawName = false ;
@@ -130,7 +134,7 @@ private static PesterSymbolReference ConvertPesterAstToSymbolReference(ScriptFil
130134
131135 return new PesterSymbolReference (
132136 scriptFile ,
133- commandName . Value ,
137+ commandType . Value ,
134138 symbolName ,
135139 testName ,
136140 pesterCommandAst . Extent
0 commit comments