Thanks to visit codestin.com
Credit goes to github.com

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 @@ -5331,11 +5331,11 @@ internal static List<CompletionResult> CompleteVariable(CompletionContext contex
ToStringCodeMethods.Type(value.GetType(),
dropNamespaces: true), name);
}
}

if (!string.IsNullOrEmpty(variable.Description))
{
tooltip += $" - {variable.Description}";
if (!string.IsNullOrEmpty(variable.Description))
{
tooltip += $" - {variable.Description}";
}
}

var completedName = !tokenAtCursorUsedBraces && !ContainsCharactersRequiringQuotes(name)
Expand Down
40 changes: 40 additions & 0 deletions test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,46 @@ Describe "TabCompletion" -Tags CI {
$res.CompletionMatches[0].ToolTip | Should -BeExactly $Expected
}

It 'Should complete environment variable' {
try {
$env:PWSH_TEST_1 = 'value 1'
$env:PWSH_TEST_2 = 'value 2'

$res = TabExpansion2 -inputScript '$env:PWSH_TEST_'
$res.CompletionMatches.Count | Should -Be 2
$res.CompletionMatches[0].CompletionText | Should -BeExactly '$env:PWSH_TEST_1'
$res.CompletionMatches[0].ListItemText | Should -BeExactly 'PWSH_TEST_1'
$res.CompletionMatches[0].ToolTip | Should -BeExactly 'PWSH_TEST_1'
$res.CompletionMatches[1].CompletionText | Should -BeExactly '$env:PWSH_TEST_2'
$res.CompletionMatches[1].ListItemText | Should -BeExactly 'PWSH_TEST_2'
$res.CompletionMatches[1].ToolTip | Should -BeExactly 'PWSH_TEST_2'
}
finally {
$env:PWSH_TEST_1 = $null
$env:PWSH_TEST_2 = $null
}
}

It 'Should complete function variable' {
try {
Function Test-PwshTest1 {}
Function Test-PwshTest2 {}

$res = TabExpansion2 -inputScript '${function:Test-PwshTest'
$res.CompletionMatches.Count | Should -Be 2
$res.CompletionMatches[0].CompletionText | Should -BeExactly '${function:Test-PwshTest1}'
$res.CompletionMatches[0].ListItemText | Should -BeExactly 'Test-PwshTest1'
$res.CompletionMatches[0].ToolTip | Should -BeExactly 'Test-PwshTest1'
$res.CompletionMatches[1].CompletionText | Should -BeExactly '${function:Test-PwshTest2}'
$res.CompletionMatches[1].ListItemText | Should -BeExactly 'Test-PwshTest2'
$res.CompletionMatches[1].ToolTip | Should -BeExactly 'Test-PwshTest2'
}
finally {
Remove-Item function:Test-PwshTest1 -ErrorAction SilentlyContinue
Remove-Item function:Test-PwshTest1 -ErrorAction SilentlyContinue
}
}

It 'Should complete scoped variable with description and value <Value>' -TestCases @(
@{ Value = 1; Expected = '[int]$VariableWithDescription - Variable description' }
@{ Value = 'string'; Expected = '[string]$VariableWithDescription - Variable description' }
Expand Down
Loading