Add fallback to session state if function definition in Ast is broken in PseudoBinding#27616
Open
MartinGC94 wants to merge 2 commits into
Open
Add fallback to session state if function definition in Ast is broken in PseudoBinding#27616MartinGC94 wants to merge 2 commits into
MartinGC94 wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Updates tab-completion’s pseudo-parameter binding to fall back to the current session state when a function definition found in script text can’t be compiled (e.g., due to unresolved types), improving parameter and member completion in those “broken AST” scenarios.
Changes:
- Update
PseudoParameterBinderto ignoreRuntimeExceptionfrom AST-based function compilation and then attempt command creation from session state for completion. - Add Pester coverage to validate parameter completion and output-member completion when the script text’s function definition references missing types.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/System.Management.Automation/engine/CommandCompletion/PseudoParameterBinder.cs |
Adds a guarded fallback path so tab completion can use an already-loaded session-state definition when AST compilation fails. |
test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 |
Adds tests exercising the new fallback behavior for both parameter completion and member completion. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Summary
This PR updates the PseudoBinding logic so there is a fallback to the session state if a function definition in the script text is broken for whatever reason.
This is intended as a workaround for the issue where you can't tab complete function parameters inside a script if the function uses a PowerShell class. Like in this scenario:
After this change you can load the class and function definitions into the session state (select them and press F8 in ISE/VS code) and now the tab completion will use the definitions found in the session state.
Ideally the PseudoBinding would be able to handle PowerShell classes in a scenario like this, but it relies on compiling the function definition, and when it does that it can't find the class.
I believe a proper fix would be to revamp the PseudoBinding so it doesn't have to compile the function definitions it finds, and can instead use static analysis of the function definition ast to determine the available parameters and output type. However, in the interest of reducing the workload for both me and the reviewer(s) <Looks at the 276 pending PRs> I have opted for this simple approach that can hopefully get through the process a little quicker.
PR Context
This fixes one of my main issues when working with PowerShell classes.
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright header