Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2036,7 +2036,10 @@ private static List<CompletionResult> GetResultForIdentifier(CompletionContext c
// 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)
{
Expand Down
5 changes: 5 additions & 0 deletions test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,11 @@ Verb-Noun -Param1 Hello ^
$res.CompletionMatches[0].CompletionText | Should -Be "Break"
}

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 ""
Expand Down