Skip to content
Open
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 @@ -1198,7 +1198,17 @@ private bool PrepareCommandElements(ExecutionContext context, CommandParameterAs
string commandName = null;
try
{
processor = PrepareFromAst(context, out commandName) ?? context.CreateCommand(commandName, dotSource, forCompletion:true);
processor = PrepareFromAst(context, out commandName);
}
catch (RuntimeException)
{
// There's an issue with the function definition.
// We ignore it because an older working definition can have been loaded into the session state already.
}

try
{
processor ??= context.CreateCommand(commandName, dotSource, forCompletion: true);
}
catch (RuntimeException)
{
Expand Down
56 changes: 56 additions & 0 deletions test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3877,6 +3877,62 @@ function MyFunction ($param1, $param2)
$res = TabExpansion2 -inputScript $Text -cursorColumn ($Text.Length - 1)
$res.CompletionMatches | Should -HaveCount 0
}

Context "Tab completion with broken function definition" {
BeforeAll {
# First define and load a working version of the function
function BrokenFunctionTest
{
[OutputType([string])]
param
(
[Parameter()]
[string]
$Param1
)
}
}

AfterAll {
Remove-Item function:BrokenFunctionTest -ErrorAction SilentlyContinue
}

It 'Should complete parameters of a function with missing types' {
$res = TabExpansion2 -inputScript @'
function BrokenFunctionTest
{
[OutputType([THISTYPEDOESNOTEXIST])]
param
(
[Parameter()]
[THISTYPEDOESNOTEXIST]
$Param1
)
}

BrokenFunctionTest -Param
'@
$res.CompletionMatches[0].CompletionText | Should -BeExactly '-Param1'
}

It 'Should complete output members from a function with missing types' {
$res = TabExpansion2 -inputScript @'
function BrokenFunctionTest
{
[OutputType([THISTYPEDOESNOTEXIST])]
param
(
[Parameter()]
[THISTYPEDOESNOTEXIST]
$Param1
)
}

(BrokenFunctionTest).Lengt
'@
$res.CompletionMatches[0].CompletionText | Should -BeExactly 'Length'
}
}
}

Describe "TabCompletion elevated tests" -Tags CI, RequireAdminOnWindows {
Expand Down