PowerShellEditorServices icon indicating copy to clipboard operation
PowerShellEditorServices copied to clipboard

Function reference not counted in codelens when on same line as definition

Open fflaten opened this issue 3 years ago • 1 comments

Prerequisites

  • [X] Write a descriptive title.
  • [X] Make sure you are able to repro it on the latest version
  • [X] Search the existing issues.

Steps to reproduce

Create a function and invoke it on the same line. See image.

Expected behavior

Invocation is counted in codelens

Actual behavior

Invocation isn't counted in codelense.
Go to reference detects the invocation as expected.

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.2.6
PSEdition                      Core
GitCommitId                    7.2.6
OS                             Microsoft Windows 10.0.22000
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Version

2022.8.2 preview

Visuals

image

This issue also means this will show 2 references in code lense because it counts the function-name in definition itself:

function
funcNewline {
    'hello'
}

funcNewline

fflaten avatar Aug 14 '22 17:08 fflaten

Problem is here where it only compares file and startline. https://github.com/PowerShell/PowerShellEditorServices/blob/948dffe080cb93b6c2d6b8fb5544788d2bcb5a83/src/PowerShellEditorServices/Services/CodeLens/ReferencesCodeLensProvider.cs#L170-L183

Suggestions

  1. ~~Compare reference startcolumn not equal~~

  2. Add SymbolType.Command for CommandAst or more generic, extend SymbolReference with something like IsDefinition. The new prop or type would be applied here to identify that the commandsAst are references only. FindReferencesVisitor.VisitCommand(CommandAst)?

fflaten avatar Aug 15 '22 18:08 fflaten

I think fixed by https://github.com/PowerShell/PowerShellEditorServices/pull/1984

andyleejordan avatar Feb 02 '23 20:02 andyleejordan