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 @@ -5384,10 +5384,15 @@ internal static List<CompletionResult> CompleteVariable(CompletionContext contex
var toolTip = value is null
? key
: StringUtil.Format("[{0}]${1}", ToStringCodeMethods.Type(value.GetType(), dropNamespaces: true), key);
if (!string.IsNullOrEmpty(variable.Description))
{
toolTip += $" - {variable.Description}";
}

var completionText = !tokenAtCursorUsedBraces && !ContainsCharactersRequiringQuotes(name)
? prefix + name
: prefix + "{" + name + "}";
AddUniqueVariable(hashedResults, tempResults, completionText, key, key);
AddUniqueVariable(hashedResults, tempResults, completionText, key, toolTip);
}
}

Expand Down Expand Up @@ -5436,6 +5441,11 @@ internal static List<CompletionResult> CompleteVariable(CompletionContext contex
}
}

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

var completedName = !tokenAtCursorUsedBraces && !ContainsCharactersRequiringQuotes(name)
? prefix + scopePrefix + name
: prefix + "{" + scopePrefix + name + "}";
Expand Down
28 changes: 28 additions & 0 deletions test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,34 @@ Describe "TabCompletion" -Tags CI {
$res = TabExpansion2 -inputScript 'param($PS = $P'
$res.CompletionMatches.Count | Should -BeGreaterThan 0
}

It 'Should complete variable with description and value <Value>' -TestCases @(
@{ Value = 1; Expected = '[int]$VariableWithDescription - Variable description' }
@{ Value = 'string'; Expected = '[string]$VariableWithDescription - Variable description' }
@{ Value = $null; Expected = 'VariableWithDescription - Variable description' }
) {
param ($Value, $Expected)

New-Variable -Name VariableWithDescription -Value $Value -Description 'Variable description' -Force
$res = TabExpansion2 -inputScript '$VariableWithDescription'
$res.CompletionMatches.Count | Should -Be 1
$res.CompletionMatches[0].CompletionText | Should -BeExactly '$VariableWithDescription'
$res.CompletionMatches[0].ToolTip | Should -BeExactly $Expected
}

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' }
@{ Value = $null; Expected = 'VariableWithDescription - Variable description' }
) {
param ($Value, $Expected)

New-Variable -Name VariableWithDescription -Value $Value -Description 'Variable description' -Force
$res = TabExpansion2 -inputScript '$local:VariableWithDescription'
$res.CompletionMatches.Count | Should -Be 1
$res.CompletionMatches[0].CompletionText | Should -BeExactly '$local:VariableWithDescription'
$res.CompletionMatches[0].ToolTip | Should -BeExactly $Expected
}

It 'Should not complete property name in class definition' {
$res = TabExpansion2 -inputScript 'class X {$P'
Expand Down
Loading