@@ -209,12 +209,7 @@ static public IEnumerable<SymbolReference> FindSymbolsInDocument(Ast scriptAst,
209
209
// }
210
210
// else
211
211
{
212
- // sometimes we don't have reliable access to the filename
213
- // so we employ heuristics to check if the contents are
214
- // part of a psd1 file.
215
- if ( ( scriptAst . Extent . File != null
216
- && scriptAst . Extent . File . EndsWith ( ".psd1" , StringComparison . OrdinalIgnoreCase ) )
217
- || IsPowerShellDataFile ( scriptAst ) )
212
+ if ( IsPowerShellDataFileAst ( scriptAst ) )
218
213
{
219
214
var findHashtableSymbolsVisitor = new FindHashtabeSymbolsVisitor ( ) ;
220
215
scriptAst . Visit ( findHashtableSymbolsVisitor ) ;
@@ -231,26 +226,25 @@ static public IEnumerable<SymbolReference> FindSymbolsInDocument(Ast scriptAst,
231
226
return symbolReferences ;
232
227
}
233
228
234
- static private bool IsPowerShellDataFile ( Ast ast )
229
+ static private bool IsPowerShellDataFileAst ( Ast ast )
235
230
{
236
- //var node = new { Item = ast, Children = new List<dynamic>() };
237
- //GenerateTree(node);
238
- //return node.Children.Count == 1 && node.Children[0].Item is NamedBlockAst
239
- // && node.Children[0].Children.Count == 1 && node.Children[0].Children[0].Item is PipelineAst
240
- // && node.Children[0].Children[0].Children.Count == 1 && ;
241
-
242
- return IsPowerShellDataFile (
243
- new { Item = ast , Children = new List < dynamic > ( ) } ,
244
- new Type [ ] {
245
- typeof ( ScriptBlockAst ) ,
246
- typeof ( NamedBlockAst ) ,
247
- typeof ( PipelineAst ) ,
248
- typeof ( CommandExpressionAst ) ,
249
- typeof ( HashtableAst ) } ,
250
- 0 ) ;
231
+ // sometimes we don't have reliable access to the filename
232
+ // so we employ heuristics to check if the contents are
233
+ // part of a psd1 file.
234
+ return ( ast . Extent . File != null
235
+ && ast . Extent . File . EndsWith ( ".psd1" , StringComparison . OrdinalIgnoreCase ) )
236
+ || IsPowerShellDataFileAstNode (
237
+ new { Item = ast , Children = new List < dynamic > ( ) } ,
238
+ new Type [ ] {
239
+ typeof ( ScriptBlockAst ) ,
240
+ typeof ( NamedBlockAst ) ,
241
+ typeof ( PipelineAst ) ,
242
+ typeof ( CommandExpressionAst ) ,
243
+ typeof ( HashtableAst ) } ,
244
+ 0 ) ;
251
245
}
252
246
253
- static private bool IsPowerShellDataFile ( dynamic node , Type [ ] levelAstMap , int level )
247
+ static private bool IsPowerShellDataFileAstNode ( dynamic node , Type [ ] levelAstMap , int level )
254
248
{
255
249
var levelAstTypeMatch = node . Item . GetType ( ) . Equals ( levelAstMap [ level ] ) ;
256
250
if ( ! levelAstTypeMatch )
@@ -268,39 +262,21 @@ static private bool IsPowerShellDataFile(dynamic node, Type[] levelAstMap, int l
268
262
{
269
263
foreach ( var astFound in astsFound )
270
264
{
271
- if ( ! astFound . Equals ( node . Item ) && node . Item . Equals ( astFound . Parent ) )
265
+ if ( ! astFound . Equals ( node . Item )
266
+ && node . Item . Equals ( astFound . Parent )
267
+ && IsPowerShellDataFileAstNode (
268
+ new { Item = astFound , Children = new List < dynamic > ( ) } ,
269
+ levelAstMap ,
270
+ level + 1 ) )
272
271
{
273
- if ( IsPowerShellDataFile ( new { Item = astFound , Children = new List < dynamic > ( ) } , levelAstMap , level + 1 ) )
274
- {
275
- return true ;
276
- }
272
+ return true ;
277
273
}
278
274
}
279
275
}
280
276
281
277
return false ;
282
278
}
283
279
284
- static private void GenerateTree ( dynamic node )
285
- {
286
- var astsFound = ( node . Item as Ast ) . FindAll ( a => a is Ast , false ) ;
287
- if ( astsFound != null )
288
- {
289
- foreach ( var astFound in astsFound )
290
- {
291
- if ( ! astFound . Equals ( node . Item ) && node . Item . Equals ( astFound . Parent ) )
292
- {
293
- node . Children . Add ( new { Item = astFound , Children = new List < dynamic > ( ) } ) ;
294
- }
295
- }
296
- }
297
-
298
- foreach ( var child in node . Children )
299
- {
300
- GenerateTree ( child ) ;
301
- }
302
- }
303
-
304
280
/// <summary>
305
281
/// Finds all files dot sourced in a script
306
282
/// </summary>
0 commit comments