Skip to content

Commit 393d4dd

Browse files
committed
Exclude a function's defintion from its reference count
This change causes a function's definition to be excluded from its reference count when showing reference CodeLenses. This was causing a function definition to show that it had "1 reference" when there were no other references to it in the workspace.
1 parent 2bb2f8c commit 393d4dd

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/PowerShellEditorServices.Host/CodeLens/ReferencesCodeLensProvider.cs

+11
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ await editorSession.LanguageService.FindReferencesOfSymbol(
6969
? new Location[0]
7070
: referencesResult
7171
.FoundReferences
72+
.Where(r => NotReferenceDefinition(foundSymbol, r))
7273
.Select(
7374
r => new Location
7475
{
@@ -94,6 +95,16 @@ await editorSession.LanguageService.FindReferencesOfSymbol(
9495
));
9596
}
9697

98+
private static bool NotReferenceDefinition(
99+
SymbolReference definition,
100+
SymbolReference reference)
101+
{
102+
return
103+
definition.ScriptRegion.StartLineNumber != reference.ScriptRegion.StartLineNumber
104+
|| definition.SymbolType != reference.SymbolType
105+
|| !string.Equals(definition.SymbolName, reference.SymbolName, StringComparison.OrdinalIgnoreCase);
106+
}
107+
97108
private static string GetFileUri(string filePath)
98109
{
99110
// If the file isn't untitled, return a URI-style path

0 commit comments

Comments
 (0)