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

No completion for Properties of $Error[n] #16941

Closed
3 tasks done
nbros opened this issue Mar 1, 2022 · 8 comments
Closed
3 tasks done

No completion for Properties of $Error[n] #16941

nbros opened this issue Mar 1, 2022 · 8 comments
Labels
Issue-Bug Issue has been identified as a bug in the product Resolution-No Activity Issue has had no activity for 6 months or more WG-Interactive-IntelliSense tab completion

Comments

@nbros
Copy link

nbros commented Mar 1, 2022

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • Search the existing issues, especially the pinned issues.

Exception report

N/A

Screenshot

image

Environment data

PS Version: 7.2.1
PS HostName: ConsoleHost (Windows Terminal)
PSReadLine Version: 2.2.2
PSReadLine EditMode: Windows
OS: 10.0.19041.1 (WinBuild.160101.0800)
BufferWidth: 245
BufferHeight: 67

Steps to reproduce

> Write-Error "an error"
> $Error[0]. <-- type <tab> or Ctrl+Space to try to complete Properties of System.Management.Automation.ErrorRecord

Expected behavior

Powershell should return completions of System.Management.Automation.ErrorRecord

Actual behavior

Powershell apparently returns completions of Array instead of ErrorRecord.

@ghost ghost added the Needs-Triage 🔍 label Mar 1, 2022
@daxian-dbw daxian-dbw transferred this issue from PowerShell/PSReadLine Mar 1, 2022
@MartinGC94
Copy link
Contributor

If you unload PSReadline and try tab completing or invoke TabExpansion2 manually you get the expected results. I think the issue is that PowerShell looks at the current scope, and I guess $error exists but is empty in the PSReadline module scope.

@iSazonov
Copy link
Collaborator

iSazonov commented Mar 2, 2022

See #3568 for no success history.

@MartinGC94
Copy link
Contributor

He said:

The original fix I made had a bad assumption as there is a valid $script:error variable.

If that's true then I don't see how this can be fixed without some sort of hack, PowerShell is correctly finding the $Error variable in the PSReadline scope.
So the question becomes, how should the hack be implemented? Should the completion code have a special case for $Error if no results are found? Should the Safe Expression Value code have a special case for $Error within the PSReadline scope? Should PSReadline provide its own completions for $Error?

@iSazonov
Copy link
Collaborator

iSazonov commented Mar 3, 2022

If I understand correctly current status is that the issue presents only if PSReadline is loaded. If so maybe @daxian-dbw advice.

@StevenBucher98 StevenBucher98 added Needs-Triage The issue is new and needs to be triaged by a work group. Issue-Bug Issue has been identified as a bug in the product and removed Needs-Triage 🔍 labels May 23, 2022
@sdwheeler
Copy link
Collaborator

sdwheeler commented Aug 16, 2023

Interactive completion of $global:Error[0].Fu<tab> works with PSReadLine loaded.

@sdwheeler sdwheeler removed the Needs-Triage The issue is new and needs to be triaged by a work group. label Aug 23, 2023
@SeeminglyScience
Copy link
Collaborator

SeeminglyScience commented Aug 24, 2023

As @MartinGC94 pointed out this is due to PSReadLine's entry point having affinity to its module's session state. The easiest fixes would be in PSReadLine itself to do one of these:

  1. Strip session state affinity before exporting (though it may come right back during the export, I can't remember).
    # in the psm1 after the function definition
    $function:PSConsoleHostReadLine = $function:PSConsoleHostReadLine.Ast.GetScriptBlock()
  2. Reimplement PSConsoleHostReadLine as a binary command

As a workaround, you can put this in your profile:

. (Get-Module PSReadLine) {
    $function:PSConsoleHostReadLine = $function:PSConsoleHostReadLine.Ast.Body.GetScriptBlock()
}

$function:PSConsoleHostReadLine = $function:PSConsoleHostReadLine.Ast.Body.GetScriptBlock()

(Both seem to be needed when export has already occurred. Not really sure why. Also note that the addition of Body here is needed only after export has occurred)

@daxian-dbw
Copy link
Member

The above fix could work, but there is also possibility that the PSConsoleHostReadLine function from PSReadLine will depend on state in the module in future, and in that case the function won't work properly if it's disconnected with the PSReadLine session state.

So, maybe the fix needs to happen in the tab completion code, for example, CommandCompletion.CompleteInput offers an additional parameter to allow the caller to choose running it with the top-level session state.

@microsoft-github-policy-service microsoft-github-policy-service bot added the Resolution-No Activity Issue has had no activity for 6 months or more label Mar 12, 2024
Copy link
Contributor

This issue has not had any activity in 6 months, if there is no further activity in 7 days, the issue will be closed automatically.

Activity in this case refers only to comments on the issue. If the issue is closed and you are the author, you can re-open the issue using the button below. Please add more information to be considered during retriage. If you are not the author but the issue is impacting you after it has been closed, please submit a new issue with updated details and a link to this issue and the original.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug Issue has been identified as a bug in the product Resolution-No Activity Issue has had no activity for 6 months or more WG-Interactive-IntelliSense tab completion
Projects
None yet
Development

No branches or pull requests

7 participants