mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Fix tooltip for variable expansion and include desc (#25112)
This commit is contained in:
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user