9
9
using Microsoft . PowerShell . EditorServices . Services . TextDocument ;
10
10
using Microsoft . PowerShell . EditorServices . Services . Symbols ;
11
11
using System . Collections . Generic ;
12
+ using System . Linq ;
12
13
13
14
namespace Microsoft . PowerShell . EditorServices . Services ;
14
15
@@ -47,16 +48,19 @@ internal bool TryGetReferences(string command, out ConcurrentBag<SymbolReference
47
48
return _symbolReferences . TryGetValue ( command , out references ) ;
48
49
}
49
50
50
- // TODO: Should this be improved, or pre-sorted?
51
- internal IReadOnlyList < SymbolReference > GetAllReferences ( )
51
+ internal SymbolReference ? TryGetSymbolAtPosition ( int line , int column ) => GetAllReferences ( )
52
+ . FirstOrDefault ( ( i ) => i . NameRegion . ContainsPosition ( line , column ) ) ;
53
+
54
+ internal IEnumerable < SymbolReference > GetAllReferences ( )
52
55
{
53
56
EnsureInitialized ( ) ;
54
- List < SymbolReference > allReferences = new ( ) ;
55
57
foreach ( ConcurrentBag < SymbolReference > bag in _symbolReferences . Values )
56
58
{
57
- allReferences . AddRange ( bag ) ;
59
+ foreach ( SymbolReference symbol in bag )
60
+ {
61
+ yield return symbol ;
62
+ }
58
63
}
59
- return allReferences ;
60
64
}
61
65
62
66
internal void EnsureInitialized ( )
@@ -69,15 +73,10 @@ internal void EnsureInitialized()
69
73
_parent . ScriptAst . Visit ( new SymbolVisitor ( _parent , AddReference ) ) ;
70
74
}
71
75
72
- private static bool ExtentIsEmpty ( IScriptExtent e ) => string . IsNullOrEmpty ( e . File ) &&
73
- e . StartLineNumber == 0 && e . StartColumnNumber == 0 &&
74
- e . EndLineNumber == 0 && e . EndColumnNumber == 0 &&
75
- string . IsNullOrEmpty ( e . Text ) ;
76
-
77
76
private AstVisitAction AddReference ( SymbolReference symbol )
78
77
{
79
78
// We have to exclude implicit things like `$this` that don't actually exist.
80
- if ( ExtentIsEmpty ( symbol . ScriptRegion ) )
79
+ if ( symbol . ScriptRegion . IsEmpty ( ) )
81
80
{
82
81
return AstVisitAction . Continue ;
83
82
}
0 commit comments