Skip to content

Reference counter skips scriptblock and when used as parameter #1481

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

Closed
C0smin opened this issue Aug 15, 2018 · 2 comments · Fixed by PowerShell/PowerShellEditorServices#1993
Assignees
Labels
Area-Symbols & References Issue-Enhancement A feature request (enhancement).

Comments

@C0smin
Copy link

C0smin commented Aug 15, 2018

Issue Description

I have observed that the reference counter does not count when the function is being used as a scriptblock or as parameter in Get-Command, see example1.

Also if you reimpliment the function, the counter will be 1 for both, see example2.

Attached Example

1

0 references
function foo {
    Write-Output 0
}

Invoke-Command -ComputerName . -ScriptBlock $Function:foo
Get-Command foo

2

1 reference
function foo {
    Write-Output 0
}
1 reference
function foo {
    Write-Output 0
}

Environment Information

Visual Studio Code

Name Version
Operating System Windows_NT x64 10.0.16299
VSCode 1.26.0
PowerShell Extension Version 1.8.2

PowerShell Information

Name Value
PSVersion 5.1.16299.551
PSEdition Desktop
PSCompatibleVersions 1.0 2.0 3.0 4.0 5.0 5.1.16299.551
BuildVersion 10.0.16299.551
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Visual Studio Code Extensions

Visual Studio Code Extensions(Click to Expand)
Extension Author Version
beautify HookyQR 1.3.2
better-comments aaron-bond 1.2.6
code-runner formulahendry 0.9.4
code-settings-sync Shan 3.0.0
code-spell-checker streetsidesoftware 1.6.10
csharp ms-vscode 1.15.2
debugger-for-chrome msjsdiag 4.8.2
gitlens eamodio 8.5.4
material-icon-theme PKief 3.5.2
mssql ms-mssql 1.4.0
npm-intellisense christian-kohler 1.3.0
perforce slevesque 3.1.0
PowerShell ms-vscode 1.8.2
project-manager alefragnani 8.0.0
rest-client humao 0.19.1
tslint eg2 1.0.34
vscode-markdownlint DavidAnson 0.19.0
vscode-npm-script eg2 0.3.5
xml DotJoshJohnson 2.3.1
@rjmholt rjmholt added Issue-Enhancement A feature request (enhancement). Up for Grabs Will shepherd PRs. Area-Pester labels Aug 15, 2018
@rjmholt
Copy link
Contributor

rjmholt commented Aug 15, 2018

Hi @C0smin, thanks for opening an issue.

Yes, ideally we can improve the situation here. Since PowerShell has all the caveats of dynamic scope, the function provider, Set-Variable/Get-Variable, etc. things like the reference CodeLens are very much "best effort" features.

In terms of solvability (and bang for buck), I imagine the work priority would be:

  • Fix function redefinition reference count
  • Implement function variable and function provider references
  • The Get-Command scenario

That last scenario is one that would require more complex logic (since the foo there is just a bare word, the Get-Command is the only thing that means it's a function).

@andyleejordan
Copy link
Member

Hey @C0smin, I just opened a PR to support:

Invoke-Command -ComputerName . -ScriptBlock $Function:foo

Or really any use of $Function:<some function name>. Great idea, totally doable.

However, it's not really feasible to support:

Get-Command foo

For reasons previously notated. There's a whole lot of edge cases to process around that, none of which we have any logic to process already. Sorry about that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Symbols & References Issue-Enhancement A feature request (enhancement).
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants