6
6
using System . Linq ;
7
7
using System . Management . Automation . Language ;
8
8
using Microsoft . PowerShell . EditorServices . Services . TextDocument ;
9
+ using Microsoft . PowerShell . EditorServices . Services . PowerShell . Utility ;
9
10
10
11
namespace Microsoft . PowerShell . EditorServices . Services . Symbols
11
12
{
@@ -42,8 +43,7 @@ IEnumerable<SymbolReference> IDocumentSymbolProvider.ProvideDocumentSymbols(
42
43
private static bool IsNamedCommandWithArguments ( Ast ast )
43
44
{
44
45
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 ) &&
47
47
commandAst . CommandElements . Count >= 2 ;
48
48
}
49
49
@@ -59,8 +59,10 @@ private static bool IsPesterCommand(CommandAst commandAst)
59
59
return false ;
60
60
}
61
61
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 ) ) )
64
66
{
65
67
return false ;
66
68
}
@@ -90,14 +92,16 @@ private static PesterSymbolReference ConvertPesterAstToSymbolReference(ScriptFil
90
92
. TrimStart ( )
91
93
. TrimEnd ( DefinitionTrimChars ) ;
92
94
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 )
95
98
{
96
99
return null ;
97
100
}
98
101
99
102
string testName = null ;
100
- if ( PesterSymbolReference . IsPesterTestCommand ( commandName . Value ) ) {
103
+ if ( PesterSymbolReference . IsPesterTestCommand ( commandType . Value ) )
104
+ {
101
105
// Search for a name for the test
102
106
// If the test has more than one argument for names, we set it to null
103
107
bool alreadySawName = false ;
@@ -130,7 +134,7 @@ private static PesterSymbolReference ConvertPesterAstToSymbolReference(ScriptFil
130
134
131
135
return new PesterSymbolReference (
132
136
scriptFile ,
133
- commandName . Value ,
137
+ commandType . Value ,
134
138
symbolName ,
135
139
testName ,
136
140
pesterCommandAst . Extent
0 commit comments