Fix tooltip for variable expansion and include desc (#25112)

This commit is contained in:
Jordan Borean
2025-03-03 09:23:24 +05:00
committed by GitHub
parent 33ed509ca4
commit 05214da717
2 changed files with 39 additions and 1 deletions
@@ -5384,10 +5384,15 @@ namespace System.Management.Automation
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);
}
}
@@ -5436,6 +5441,11 @@ namespace System.Management.Automation
}
}
if (!string.IsNullOrEmpty(variable.Description))
{
tooltip += $" - {variable.Description}";
}
var completedName = !tokenAtCursorUsedBraces && !ContainsCharactersRequiringQuotes(name)
? prefix + scopePrefix + name
: prefix + "{" + scopePrefix + name + "}";
@@ -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'