Fix &! operator: parser terminator, scriptblock body extraction, and ThreadJob cmdlet resolution#164
Draft
Copilot wants to merge 21 commits intothreadJobOperatorfrom
Draft
Fix &! operator: parser terminator, scriptblock body extraction, and ThreadJob cmdlet resolution#164Copilot wants to merge 21 commits intothreadJobOperatorfrom
Copilot wants to merge 21 commits intothreadJobOperatorfrom
Conversation
- Added new TokenKind.AmpersandExclaim for &! operator - Updated tokenizer to recognize &! operator - Added BackgroundThreadJob property to PipelineAst - Updated parser to handle &! operator for ThreadJobs - Modified MiscOps to use Start-ThreadJob when BackgroundThreadJob is true - Updated all token enum values to accommodate new token Co-authored-by: kilasuit <6355225+kilasuit@users.noreply.github.com>
Co-authored-by: kilasuit <6355225+kilasuit@users.noreply.github.com>
Co-authored-by: kilasuit <6355225+kilasuit@users.noreply.github.com>
Co-authored-by: kilasuit <6355225+kilasuit@users.noreply.github.com>
…use compound assignment - Moved BackgroundThreadJob property from PipelineAst to ChainableAst base class to make it accessible to both PipelineAst and PipelineChainAst - Updated PipelineChainAst.Copy() to preserve BackgroundThreadJob property - Fixed IDE0074 warning by using ??= compound assignment operator - Fixes CS1061 error where PipelineBaseAst didn't have BackgroundThreadJob property Co-authored-by: kilasuit <6355225+kilasuit@users.noreply.github.com>
- Moved BackgroundThreadJob from ChainableAst to PipelineBaseAst - This ensures the property is accessible when the parameter type is PipelineBaseAst - Fixes CS1061 compilation error where PipelineBaseAst didn't have BackgroundThreadJob Co-authored-by: kilasuit <6355225+kilasuit@users.noreply.github.com>
…ling - Reorganized tests into Context blocks (Runtime, Syntax, Parser, Tokenizer) - Added tests to validate ThreadJob vs fallback behavior with -Skip conditions - Fixed variable capture test to assert actual captured values - Enabled and improved the && operator combination test - Simplified exception handling in MiscOps.cs (removed unnecessary try-catch) - GetCmdlet returns null when not found, doesn't throw in common case Co-authored-by: kilasuit <6355225+kilasuit@users.noreply.github.com>
- Moved TokenKind.AmpersandExclaim from position 29 to position 171 (end of enum) - Restored all token enum values (Pipe through Clean) to their original positions - Updated token flags and text arrays to place AmpersandExclaim at the end - Updated PSToken.cs mapping array accordingly - Added missing Clean entry to PSToken.cs - This avoids breaking compiled consumers that rely on stable enum values Co-authored-by: kilasuit <6355225+kilasuit@users.noreply.github.com>
Co-authored-by: kilasuit <6355225+kilasuit@users.noreply.github.com>
- Added backgroundThreadJob boolean variable to track ThreadJob intent - Changed AmpersandExclaim case to set backgroundThreadJob variable instead of property - Set BackgroundThreadJob property in default case alongside Background property - Fixes issue where "1+1 &!" caused parser error because property was set on wrong pipeline Co-authored-by: kilasuit <6355225+kilasuit@users.noreply.github.com>
- Added case for TokenKind.AmpersandExclaim in PipelineRule switch
- Sets both background and backgroundThreadJob flags when &! is encountered
- Fixes "Unexpected token '&!'" error when using {1+1} &! syntax
- Follows same pattern as TokenKind.Ampersand case with allowBackground check
Co-authored-by: kilasuit <6355225+kilasuit@users.noreply.github.com>
- Added backgroundThreadJob variable declaration in PipelineRule method - Set BackgroundThreadJob property on PipelineAst when backgroundThreadJob flag is true - Fixes CS0103 compilation error: "The name 'backgroundThreadJob' does not exist" Co-authored-by: kilasuit <6355225+kilasuit@users.noreply.github.com>
- Changed from GetCmdlet to GetCommand with CommandTypes.Cmdlet | CommandTypes.Function
- GetCommand will auto-import the ThreadJob module if it's available
- Properly handles CmdletInfo vs FunctionInfo by checking type and creating appropriate command info
- Fixes issue where {1+1} &! was creating BackgroundJob instead of ThreadJob
- Now correctly creates ThreadJob when ThreadJob module is available
Co-authored-by: kilasuit <6355225+kilasuit@users.noreply.github.com>
- Use pattern matching to check if threadJobCommand is CmdletInfo - Handle FunctionInfo case by falling back to Start-Job (functions can't be invoked in this context) - Fixes CS1061 error: CommandInfo doesn't have ImplementingType property - Only CmdletInfo has ImplementingType, not base CommandInfo class Co-authored-by: kilasuit <6355225+kilasuit@users.noreply.github.com>
- Added usingThreadJob boolean flag to track if Start-ThreadJob is actually being used - Only add WorkingDirectory parameter for Start-Job, not Start-ThreadJob - Start-ThreadJob doesn't support the WorkingDirectory parameter - Fixes error: "A parameter cannot be found that matches parameter name 'WorkingDirectory'" Co-authored-by: kilasuit <6355225+kilasuit@users.noreply.github.com>
- Detect when pipeline is already a ScriptBlockExpressionAst (e.g., {1+1} &!)
- Extract the inner script block content directly instead of wrapping it again
- Previously {1+1} &! created ScriptBlock.Create("{1+1}") which returned literal string
- Now correctly extracts "1+1" and creates ScriptBlock.Create("1+1") which evaluates the expression
- Fixes issue where {1+1} &! returned "1+1" instead of 2
Co-authored-by: kilasuit <6355225+kilasuit@users.noreply.github.com>
…essing PipelineElements - PipelineElements property is on PipelineAst, not PipelineBaseAst - Added type check and cast: pipelineAst is PipelineAst pipeline - Fixes CS1061 error: 'PipelineBaseAst' does not contain a definition for 'PipelineElements' Co-authored-by: kilasuit <6355225+kilasuit@users.noreply.github.com>
- Set BackgroundThreadJob property on PipelineChainAst after creation - Previously only passing background flag to constructor, not setting BackgroundThreadJob - Fixes issue where "1+1 && 2+2 &!" showed as BackgroundJob instead of ThreadJob - Now properly creates ThreadJob for pipeline chains ending with &! Co-authored-by: kilasuit <6355225+kilasuit@users.noreply.github.com>
… add Wait-Job timeouts, fix DEBUG assertions Co-authored-by: kilasuit <6355225+kilasuit@users.noreply.github.com>
…dlet resolution per PR review Co-authored-by: kilasuit <6355225+kilasuit@users.noreply.github.com>
Author
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Copilot
AI
changed the title
[WIP] Add ThreadJobOperator to run pipelines as ThreadJobs
Fix &! operator: parser terminator, scriptblock body extraction, and ThreadJob cmdlet resolution
Mar 11, 2026
7414207 to
69cefb0
Compare
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.
Three correctness bugs in the
&!(ThreadJob background operator) implementation identified in code review.Parser:
&!not treated as statement terminatorAmpersandExclaimwas missing from token-dispatch lists thatAmpersandalready appears in, causingWrite-Output 1 &!to parse&!as an argument rather than backgrounding the pipeline.Added
TokenKind.AmpersandExclaimto:CommandRule()argument scanning switch — stops scanning command elements at&!GetCommandArgument()"never allowed as command arguments" listMiscOps: scriptblock body includes outer braces
ScriptBlockExpressionAst.Extent.Textfor{ content }includes the outer{}. Passing that directly toScriptBlock.Create()creates a script that returns a ScriptBlock object rather than executing the body:Fixed by stripping the first/last character before
ScriptBlock.Create(), adjusting the offset used for variable-position tracking accordingly. Added a debug assertion validating the brace invariant.MiscOps: ThreadJob resolved via function lookup
GetCommand("Start-ThreadJob", CommandTypes.Cmdlet | CommandTypes.Function)can resolve a user-definedStart-ThreadJobfunction, causing&!to silently fall back toStart-Jobeven when the ThreadJob module is installed. Changed toCommandTypes.Cmdletonly, simplifying the resolution path.Tests
Fixed two
Itblock names containing$using:in double-quoted strings (PowerShell parse errors) by switching them to single-quoted strings.💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.