Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
3 tasks done
fflaten opened this issue Aug 14, 2022 · 2 comments
Closed
3 tasks done
Assignees
Labels
Area-CodeLens Issue-Bug A bug to squash. Up for Grabs Will shepherd PRs.

Comments

@fflaten
Copy link
Contributor

fflaten commented Aug 14, 2022

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest version
  • 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
@ghost ghost added the Needs: Triage Maintainer attention needed! label Aug 14, 2022
@fflaten
Copy link
Contributor Author

fflaten commented Aug 15, 2022

Problem is here where it only compares file and startline.

private static bool IsReferenceDefinition(
SymbolReference definition,
SymbolReference reference)
{
// First check if we are in the same file as the definition. if we are...
// check if it's on the same line number.
// TODO: Do we care about two symbol definitions of the same name?
// if we do, how could we possibly know that a reference in one file is a reference
// of a particular symbol definition?
return
definition.FilePath == reference.FilePath &&
definition.ScriptRegion.StartLineNumber == reference.ScriptRegion.StartLineNumber;
}

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)?

@andyleejordan
Copy link
Member

andyleejordan commented Feb 2, 2023

I think fixed by #1984

@andyleejordan andyleejordan self-assigned this Feb 2, 2023
@PowerShell PowerShell deleted a comment Feb 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-CodeLens Issue-Bug A bug to squash. Up for Grabs Will shepherd PRs.
Projects
None yet
Development

No branches or pull requests

3 participants