mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Fix issue when completing the first command in a script with an empty array expression (#18355) (#18630)
Co-authored-by: MartinGC94 <42123497+MartinGC94@users.noreply.github.com>
This commit is contained in:
co-authored by
MartinGC94
parent
645249b845
commit
fb46702bbc
@@ -1986,7 +1986,10 @@ namespace System.Management.Automation
|
||||
// Handle completion for a path with variable, such as: $PSHOME\ty<tab>
|
||||
if (completionContext.RelatedAsts.Count > 0 && completionContext.RelatedAsts[0] is ScriptBlockAst)
|
||||
{
|
||||
Ast cursorAst = completionContext.RelatedAsts[0].FindAll(ast => ast.Extent.EndOffset <= tokenAtCursor.Extent.StartOffset, true).LastOrDefault();
|
||||
Ast cursorAst = completionContext.RelatedAsts[0].FindAll(
|
||||
ast => ast.Extent.EndOffset <= tokenAtCursor.Extent.StartOffset
|
||||
&& ast.Extent is not EmptyScriptExtent,
|
||||
searchNestedScriptBlocks: true).LastOrDefault();
|
||||
|
||||
if (cursorAst is not null)
|
||||
{
|
||||
|
||||
@@ -759,6 +759,11 @@ ConstructorTestClass(int i, bool b)
|
||||
$res.CompletionMatches.CompletionText | Should -Contain "-Path"
|
||||
}
|
||||
|
||||
it 'Should complete command with an empty arrayexpression element' {
|
||||
$res = TabExpansion2 -inputScript 'Get-ChildItem @()' -cursorColumn 1
|
||||
$res.CompletionMatches[0].CompletionText | Should -Be "Get-ChildItem"
|
||||
}
|
||||
|
||||
Context "Script name completion" {
|
||||
BeforeAll {
|
||||
Setup -f 'install-powershell.ps1' -Content ""
|
||||
|
||||
Reference in New Issue
Block a user