Skip to content
Closed
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 @@ -4580,13 +4580,20 @@ internal static IEnumerable<CompletionResult> CompleteFilename(CompletionContext
return CommandCompletion.EmptyCompletionResult;
}

var lastAst = context.RelatedAsts[^1];
if (lastAst.Parent is UsingStatementAst usingStatement
&& usingStatement.UsingStatementKind is UsingStatementKind.Module or UsingStatementKind.Assembly
&& lastAst.Extent.File is not null)
if (context.RelatedAsts != null && context.RelatedAsts.Count > 0)
{
relativeBasePath = Directory.GetParent(lastAst.Extent.File).FullName;
_ = currentPS.AddParameter("RelativeBasePath", relativeBasePath);
var lastAst = context.RelatedAsts[^1];
if (lastAst.Parent is UsingStatementAst usingStatement
&& usingStatement.UsingStatementKind is UsingStatementKind.Module or UsingStatementKind.Assembly
&& lastAst.Extent.File is not null)
{
relativeBasePath = Directory.GetParent(lastAst.Extent.File).FullName;
_ = currentPS.AddParameter("RelativeBasePath", relativeBasePath);
}
else
{
relativeBasePath = context.ExecutionContext.SessionState.Internal.CurrentLocation.ProviderPath;
}
}
else
{
Expand Down
6 changes: 6 additions & 0 deletions test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4012,4 +4012,10 @@ Describe "WSMan Config Provider tab complete tests" -Tags Feature,RequireAdminOn
# https://github.com/PowerShell/PowerShell/issues/4744
# TODO: move to test cases above once working
}

It "[CompletionCompleters]::CompleteFilename should not throw NullReferenceException with empty string" {
{ [System.Management.Automation.CompletionCompleters]::CompleteFilename("") } | Should -Not -Throw
$result = [System.Management.Automation.CompletionCompleters]::CompleteFilename("")
$result | Should -Not -BeNullOrEmpty
}
}
Loading