Skip to content

Commit 6652213

Browse files
committed
Remove FindCommandVisitor, FindSymbolVisitor and FindDotSourcedVisitor
`SymbolsService` is now nullable too.
1 parent cd8dd7f commit 6652213

File tree

12 files changed

+166
-832
lines changed

12 files changed

+166
-832
lines changed

src/PowerShellEditorServices/Services/CodeLens/ReferencesCodeLensProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public async Task<CodeLens> ResolveCodeLens(
103103
codeLens.Range.Start.Character + 1);
104104

105105
IEnumerable<SymbolReference> referencesResult =
106-
await _symbolsService.ScanForReferencesOfSymbol(
106+
await _symbolsService.ScanForReferencesOfSymbolAsync(
107107
foundSymbol, cancellationToken).ConfigureAwait(false);
108108

109109
Location[] referenceLocations;

src/PowerShellEditorServices/Services/Symbols/ReferenceTable.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
1010
using Microsoft.PowerShell.EditorServices.Services.Symbols;
1111
using System.Collections.Generic;
12+
using System.Linq;
1213

1314
namespace Microsoft.PowerShell.EditorServices.Services;
1415

@@ -47,16 +48,19 @@ internal bool TryGetReferences(string command, out ConcurrentBag<SymbolReference
4748
return _symbolReferences.TryGetValue(command, out references);
4849
}
4950

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()
5255
{
5356
EnsureInitialized();
54-
List<SymbolReference> allReferences = new();
5557
foreach (ConcurrentBag<SymbolReference> bag in _symbolReferences.Values)
5658
{
57-
allReferences.AddRange(bag);
59+
foreach (SymbolReference symbol in bag)
60+
{
61+
yield return symbol;
62+
}
5863
}
59-
return allReferences;
6064
}
6165

6266
internal void EnsureInitialized()
@@ -69,15 +73,10 @@ internal void EnsureInitialized()
6973
_parent.ScriptAst.Visit(new SymbolVisitor(_parent, AddReference));
7074
}
7175

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-
7776
private AstVisitAction AddReference(SymbolReference symbol)
7877
{
7978
// We have to exclude implicit things like `$this` that don't actually exist.
80-
if (ExtentIsEmpty(symbol.ScriptRegion))
79+
if (symbol.ScriptRegion.IsEmpty())
8180
{
8281
return AstVisitAction.Continue;
8382
}

0 commit comments

Comments
 (0)