From a405893015a8b490cb7ba2df5f2dce5f31a9bf0b Mon Sep 17 00:00:00 2001 From: ArmaanMcleod Date: Mon, 21 Apr 2025 16:42:26 +1000 Subject: [PATCH 1/9] Use CompletionDisplayInfoMapper delegate for display info mapping --- .../commands/management/NewPropertyCommand.cs | 26 +++++------ .../commands/utility/Join-String.cs | 41 +++++++++-------- .../CommandCompletion/CompletionHelpers.cs | 45 ++++++++++++++++--- 3 files changed, 72 insertions(+), 40 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/NewPropertyCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/NewPropertyCommand.cs index caef4af84dc..45054b7a62d 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/NewPropertyCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/NewPropertyCommand.cs @@ -189,7 +189,18 @@ protected override void ProcessRecord() /// public class PropertyTypeArgumentCompleter : IArgumentCompleter { - private static readonly string[] s_RegistryPropertyTypes = new string[] + private static readonly CompletionHelpers.CompletionDisplayInfoMapper RegistryPropertyTypeDisplayInfoMapper = registryPropertyType => registryPropertyType switch + { + "String" => new(TabCompletionStrings.RegistryStringToolTip, "String"), + "ExpandString" => new(TabCompletionStrings.RegistryExpandStringToolTip, "ExpandString"), + "Binary" => new(TabCompletionStrings.RegistryBinaryToolTip, "Binary"), + "DWord" => new(TabCompletionStrings.RegistryDWordToolTip, "DWord"), + "MultiString" => new(TabCompletionStrings.RegistryMultiStringToolTip, "MultiString"), + "QWord" => new(TabCompletionStrings.RegistryQWordToolTip, "QWord"), + _ => new(TabCompletionStrings.RegistryUnknownToolTip, "Unknown") + }; + + private static readonly IReadOnlyList s_RegistryPropertyTypes = new List(capacity: 6) { "String", "ExpandString", @@ -200,17 +211,6 @@ public class PropertyTypeArgumentCompleter : IArgumentCompleter "Unknown" }; - private static string GetRegistryPropertyTypeToolTip(string propertyTypeName) => propertyTypeName switch - { - "String" => TabCompletionStrings.RegistryStringToolTip, - "ExpandString" => TabCompletionStrings.RegistryExpandStringToolTip, - "Binary" => TabCompletionStrings.RegistryBinaryToolTip, - "DWord" => TabCompletionStrings.RegistryDWordToolTip, - "MultiString" => TabCompletionStrings.RegistryMultiStringToolTip, - "QWord" => TabCompletionStrings.RegistryQWordToolTip, - _ => TabCompletionStrings.RegistryUnknownToolTip - }; - /// /// Returns completion results for PropertyType parameter. /// @@ -230,7 +230,7 @@ public IEnumerable CompleteArgument( ? CompletionHelpers.GetMatchingResults( wordToComplete, possibleCompletionValues: s_RegistryPropertyTypes, - toolTipMapping: GetRegistryPropertyTypeToolTip, + displayInfoMapper: RegistryPropertyTypeDisplayInfoMapper, resultType: CompletionResultType.ParameterValue) : []; diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Join-String.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Join-String.cs index b9fc29d45fe..d30fad40ebd 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Join-String.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Join-String.cs @@ -172,28 +172,28 @@ public sealed class SeparatorArgumentCompleter : IArgumentCompleter "`r`n"; #endif - private static readonly Dictionary s_separatorMappings = new(capacity: 7) + private static readonly CompletionHelpers.CompletionDisplayInfoMapper SeparatorDisplayInfoMapper = separator => separator switch { - { ",", (TabCompletionStrings.SeparatorCommaToolTip, "Comma") }, - { ", ", (TabCompletionStrings.SeparatorCommaSpaceToolTip, "Comma-Space") }, - { ";", (TabCompletionStrings.SeparatorSemiColonToolTip, "Semi-Colon") }, - { "; ", (TabCompletionStrings.SeparatorSemiColonSpaceToolTip, "Semi-Colon-Space") }, - { NewLineText, (StringUtil.Format(TabCompletionStrings.SeparatorNewlineToolTip, NewLineText), "Newline") }, - { "-", (TabCompletionStrings.SeparatorDashToolTip, "Dash") }, - { " ", (TabCompletionStrings.SeparatorSpaceToolTip, "Space") }, + "," => new(TabCompletionStrings.SeparatorCommaToolTip, "Comma"), + ", " => new(TabCompletionStrings.SeparatorCommaSpaceToolTip, "Comma-Space"), + ";" => new(TabCompletionStrings.SeparatorSemiColonToolTip, "Semi-Colon"), + "; " => new(TabCompletionStrings.SeparatorSemiColonSpaceToolTip, "Semi-Colon-Space"), + "-" => new(TabCompletionStrings.SeparatorDashToolTip, "Dash"), + " " => new(TabCompletionStrings.SeparatorSpaceToolTip, "Space"), + _ when separator == NewLineText => new(StringUtil.Format(TabCompletionStrings.SeparatorNewlineToolTip, NewLineText), "Newline"), + _ => new(separator, separator) }; - private static readonly IEnumerable s_separatorValues = s_separatorMappings.Keys; - - private static string GetSeparatorToolTip(string separator) - => s_separatorMappings.TryGetValue(separator, out var mapping) - ? mapping.Tooltip - : separator; - - private static string GetSeparatorListItemText(string separator) - => s_separatorMappings.TryGetValue(separator, out var mapping) - ? mapping.ListItemText - : separator; + private static readonly IReadOnlyList s_separatorValues = new List(capacity: 7) + { + ",", + ", ", + ";", + "; ", + NewLineText, + "-", + " ", + }; /// /// Returns completion results for Separator parameter. @@ -213,8 +213,7 @@ public IEnumerable CompleteArgument( => CompletionHelpers.GetMatchingResults( wordToComplete, possibleCompletionValues: s_separatorValues, - listItemTextMapping: GetSeparatorListItemText, - toolTipMapping: GetSeparatorToolTip, + displayInfoMapper: SeparatorDisplayInfoMapper, resultType: CompletionResultType.ParameterValue); } diff --git a/src/System.Management.Automation/engine/CommandCompletion/CompletionHelpers.cs b/src/System.Management.Automation/engine/CommandCompletion/CompletionHelpers.cs index e7bc41667c2..7df52599e8e 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CompletionHelpers.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CompletionHelpers.cs @@ -23,19 +23,18 @@ internal static class CompletionHelpers /// /// The word to complete. /// The possible completion values to iterate. - /// The optional tool tip mapping delegate. - /// The optional list item text mapping delegate. + /// The optional completion display info mapper delegate for tool tip and list item text. /// The optional completion result type. Default is Text. /// The optional match strategy delegate. /// List of matching completion results. internal static IEnumerable GetMatchingResults( string wordToComplete, IEnumerable possibleCompletionValues, - Func toolTipMapping = null, - Func listItemTextMapping = null, + CompletionDisplayInfoMapper displayInfoMapper = null, CompletionResultType resultType = CompletionResultType.Text, MatchStrategy matchStrategy = null) { + displayInfoMapper ??= DefaultDisplayInfoMapper; matchStrategy ??= DefaultMatch; string quote = HandleDoubleAndSingleQuote(ref wordToComplete); @@ -49,14 +48,48 @@ internal static IEnumerable GetMatchingResults( if (matchStrategy(value, wordToComplete)) { string completionText = QuoteCompletionText(value, quote); - string toolTip = toolTipMapping?.Invoke(value) ?? value; - string listItemText = listItemTextMapping?.Invoke(value) ?? value; + + CompletionDisplayInfo displayInfo = displayInfoMapper(value); + string toolTip = displayInfo.ToolTip; + string listItemText = displayInfo.ListItemText; yield return new CompletionResult(completionText, listItemText, resultType, toolTip); } } } + /// + /// Represents the display information for a completion result. + /// + internal class CompletionDisplayInfo + { + public string ToolTip { get; set; } + + public string ListItemText { get; set; } + + public CompletionDisplayInfo(string toolTip, string listItemText) + { + ToolTip = toolTip; + ListItemText = listItemText; + } + } + + /// + /// Provides the display information for a completion result. + /// This delegate is used to map a string value to its corresponding display information. + /// + /// The input value to be mapped + /// Completion display info containing tool tip and list item text. + internal delegate CompletionDisplayInfo CompletionDisplayInfoMapper(string value); + + /// + /// Provides the default display information for a completion result. + /// Defaults to using the input value for both the tool tip and list item text. + /// + /// Completion display info containing tool tip and list item text. + internal static readonly CompletionDisplayInfoMapper DefaultDisplayInfoMapper = value + => new CompletionDisplayInfo(value, value); + /// /// Normalizes the input string to an expandable string format for PowerShell. /// From b6a0e60eac24b531a23ede837e58cf1ea6354c0d Mon Sep 17 00:00:00 2001 From: Armaan Mcleod Date: Mon, 21 Apr 2025 16:49:43 +1000 Subject: [PATCH 2/9] Update src/Microsoft.PowerShell.Commands.Management/commands/management/NewPropertyCommand.cs --- .../commands/management/NewPropertyCommand.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/NewPropertyCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/NewPropertyCommand.cs index 45054b7a62d..b1958d596b8 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/NewPropertyCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/NewPropertyCommand.cs @@ -200,7 +200,7 @@ public class PropertyTypeArgumentCompleter : IArgumentCompleter _ => new(TabCompletionStrings.RegistryUnknownToolTip, "Unknown") }; - private static readonly IReadOnlyList s_RegistryPropertyTypes = new List(capacity: 6) + private static readonly IReadOnlyList s_RegistryPropertyTypes = new List(capacity: 7) { "String", "ExpandString", From 96170ce3286ddd9b0a3b7a99304345d413c6986b Mon Sep 17 00:00:00 2001 From: ArmaanMcleod Date: Mon, 21 Apr 2025 18:30:56 +1000 Subject: [PATCH 3/9] Add tests for tooltip and listitemtext --- .../TabCompletion/TabCompletion.Tests.ps1 | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 b/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 index 7d20bd8e173..41e611f6ed5 100644 --- a/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 +++ b/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 @@ -1368,6 +1368,12 @@ param([ValidatePattern( $res = TabExpansion2 -inputScript $TextInput -cursorColumn $TextInput.Length $completionText = $res.CompletionMatches.CompletionText $completionText -join ' ' | Should -BeExactly $ExpectedPropertyTypes + + foreach ($match in $res.CompletionMatches) { + $completionText = $match.CompletionText.Replace("""", "").Replace("'", "") + $listItemText = $match.ListItemText + $completionText | Should -BeExactly $listItemText + } } It "Test fallback to provider of current location if no path specified" -Skip:(!$IsWindows) { @@ -1554,6 +1560,14 @@ param([ValidatePattern( $res = TabExpansion2 -inputScript $TextInput -cursorColumn $TextInput.Length $completionText = $res.CompletionMatches.CompletionText $completionText -join ' ' | Should -BeExactly $Expected + + foreach ($match in $res.CompletionMatches) { + $toolTip = $match.ToolTip.Replace("""", "").Replace("'", "") + $completionText = $match.CompletionText.Replace("""", "").Replace("'", "") + $listItemText = $match.ListItemText + $toolTip.StartsWith($completionText) | Should -BeTrue + $toolTip.EndsWith($listItemText) | Should -BeTrue + } } It "Should complete for ''" -Skip:(!$IsWindows) -TestCases @( @@ -1574,6 +1588,14 @@ param([ValidatePattern( $res = TabExpansion2 -inputScript $TextInput -cursorColumn $TextInput.Length $completionText = $res.CompletionMatches.CompletionText $completionText -join ' ' | Should -BeExactly $Expected + + foreach ($match in $res.CompletionMatches) { + $toolTip = $match.ToolTip.Replace("""", "").Replace("'", "") + $completionText = $match.CompletionText.Replace("""", "").Replace("'", "") + $listItemText = $match.ListItemText + $toolTip.StartsWith($completionText) | Should -BeTrue + $toolTip.EndsWith($listItemText) | Should -BeTrue + } } It "Should complete for ''" -Skip:($IsWindows) -TestCases @( @@ -1590,6 +1612,14 @@ param([ValidatePattern( $res = TabExpansion2 -inputScript $TextInput -cursorColumn $TextInput.Length $completionText = $res.CompletionMatches.CompletionText $completionText -join ' ' | Should -BeExactly $Expected + + foreach ($match in $res.CompletionMatches) { + $toolTip = $match.ToolTip.Replace("""", "").Replace("'", "") + $completionText = $match.CompletionText.Replace("""", "").Replace("'", "") + $listItemText = $match.ListItemText + $toolTip.StartsWith($completionText) | Should -BeTrue + $toolTip.EndsWith($listItemText) | Should -BeTrue + } } } From fee92b401ce1449741c3fa31dca6ca507b45fbda Mon Sep 17 00:00:00 2001 From: ArmaanMcleod Date: Mon, 21 Apr 2025 19:19:27 +1000 Subject: [PATCH 4/9] Make NewLineText const --- .../commands/utility/Join-String.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Join-String.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Join-String.cs index d30fad40ebd..2d7accfced8 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Join-String.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Join-String.cs @@ -165,7 +165,7 @@ protected override void EndProcessing() /// public sealed class SeparatorArgumentCompleter : IArgumentCompleter { - private static readonly string NewLineText = + private const string NewLineText = #if UNIX "`n"; #else @@ -180,7 +180,7 @@ public sealed class SeparatorArgumentCompleter : IArgumentCompleter "; " => new(TabCompletionStrings.SeparatorSemiColonSpaceToolTip, "Semi-Colon-Space"), "-" => new(TabCompletionStrings.SeparatorDashToolTip, "Dash"), " " => new(TabCompletionStrings.SeparatorSpaceToolTip, "Space"), - _ when separator == NewLineText => new(StringUtil.Format(TabCompletionStrings.SeparatorNewlineToolTip, NewLineText), "Newline"), + NewLineText => new(StringUtil.Format(TabCompletionStrings.SeparatorNewlineToolTip, NewLineText), "Newline"), _ => new(separator, separator) }; From f0c21a2e05ad37c588ff03543f63a14c5db8e9f0 Mon Sep 17 00:00:00 2001 From: ArmaanMcleod Date: Mon, 21 Apr 2025 19:41:07 +1000 Subject: [PATCH 5/9] Remove class and use tuple --- .../commands/management/NewPropertyCommand.cs | 14 ++++++------ .../commands/utility/Join-String.cs | 16 +++++++------- .../CommandCompletion/CompletionHelpers.cs | 22 +++---------------- 3 files changed, 18 insertions(+), 34 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/NewPropertyCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/NewPropertyCommand.cs index b1958d596b8..66b6b0f6df6 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/NewPropertyCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/NewPropertyCommand.cs @@ -191,13 +191,13 @@ public class PropertyTypeArgumentCompleter : IArgumentCompleter { private static readonly CompletionHelpers.CompletionDisplayInfoMapper RegistryPropertyTypeDisplayInfoMapper = registryPropertyType => registryPropertyType switch { - "String" => new(TabCompletionStrings.RegistryStringToolTip, "String"), - "ExpandString" => new(TabCompletionStrings.RegistryExpandStringToolTip, "ExpandString"), - "Binary" => new(TabCompletionStrings.RegistryBinaryToolTip, "Binary"), - "DWord" => new(TabCompletionStrings.RegistryDWordToolTip, "DWord"), - "MultiString" => new(TabCompletionStrings.RegistryMultiStringToolTip, "MultiString"), - "QWord" => new(TabCompletionStrings.RegistryQWordToolTip, "QWord"), - _ => new(TabCompletionStrings.RegistryUnknownToolTip, "Unknown") + "String" => (TabCompletionStrings.RegistryStringToolTip, "String"), + "ExpandString" => (TabCompletionStrings.RegistryExpandStringToolTip, "ExpandString"), + "Binary" => (TabCompletionStrings.RegistryBinaryToolTip, "Binary"), + "DWord" => (TabCompletionStrings.RegistryDWordToolTip, "DWord"), + "MultiString" => (TabCompletionStrings.RegistryMultiStringToolTip, "MultiString"), + "QWord" => (TabCompletionStrings.RegistryQWordToolTip, "QWord"), + _ => (TabCompletionStrings.RegistryUnknownToolTip, "Unknown") }; private static readonly IReadOnlyList s_RegistryPropertyTypes = new List(capacity: 7) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Join-String.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Join-String.cs index 2d7accfced8..5b0d62a8f01 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Join-String.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Join-String.cs @@ -174,14 +174,14 @@ public sealed class SeparatorArgumentCompleter : IArgumentCompleter private static readonly CompletionHelpers.CompletionDisplayInfoMapper SeparatorDisplayInfoMapper = separator => separator switch { - "," => new(TabCompletionStrings.SeparatorCommaToolTip, "Comma"), - ", " => new(TabCompletionStrings.SeparatorCommaSpaceToolTip, "Comma-Space"), - ";" => new(TabCompletionStrings.SeparatorSemiColonToolTip, "Semi-Colon"), - "; " => new(TabCompletionStrings.SeparatorSemiColonSpaceToolTip, "Semi-Colon-Space"), - "-" => new(TabCompletionStrings.SeparatorDashToolTip, "Dash"), - " " => new(TabCompletionStrings.SeparatorSpaceToolTip, "Space"), - NewLineText => new(StringUtil.Format(TabCompletionStrings.SeparatorNewlineToolTip, NewLineText), "Newline"), - _ => new(separator, separator) + "," => (TabCompletionStrings.SeparatorCommaToolTip, "Comma"), + ", " => (TabCompletionStrings.SeparatorCommaSpaceToolTip, "Comma-Space"), + ";" => (TabCompletionStrings.SeparatorSemiColonToolTip, "Semi-Colon"), + "; " => (TabCompletionStrings.SeparatorSemiColonSpaceToolTip, "Semi-Colon-Space"), + "-" => (TabCompletionStrings.SeparatorDashToolTip, "Dash"), + " " => (TabCompletionStrings.SeparatorSpaceToolTip, "Space"), + NewLineText => (StringUtil.Format(TabCompletionStrings.SeparatorNewlineToolTip, NewLineText), "Newline"), + _ => (separator, separator) }; private static readonly IReadOnlyList s_separatorValues = new List(capacity: 7) diff --git a/src/System.Management.Automation/engine/CommandCompletion/CompletionHelpers.cs b/src/System.Management.Automation/engine/CommandCompletion/CompletionHelpers.cs index 7df52599e8e..9857e50e545 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CompletionHelpers.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CompletionHelpers.cs @@ -49,7 +49,7 @@ internal static IEnumerable GetMatchingResults( { string completionText = QuoteCompletionText(value, quote); - CompletionDisplayInfo displayInfo = displayInfoMapper(value); + (string ToolTip, string ListItemText) displayInfo = displayInfoMapper(value); string toolTip = displayInfo.ToolTip; string listItemText = displayInfo.ListItemText; @@ -58,29 +58,13 @@ internal static IEnumerable GetMatchingResults( } } - /// - /// Represents the display information for a completion result. - /// - internal class CompletionDisplayInfo - { - public string ToolTip { get; set; } - - public string ListItemText { get; set; } - - public CompletionDisplayInfo(string toolTip, string listItemText) - { - ToolTip = toolTip; - ListItemText = listItemText; - } - } - /// /// Provides the display information for a completion result. /// This delegate is used to map a string value to its corresponding display information. /// /// The input value to be mapped /// Completion display info containing tool tip and list item text. - internal delegate CompletionDisplayInfo CompletionDisplayInfoMapper(string value); + internal delegate (string ToolTip, string ListItemText) CompletionDisplayInfoMapper(string value); /// /// Provides the default display information for a completion result. @@ -88,7 +72,7 @@ public CompletionDisplayInfo(string toolTip, string listItemText) /// /// Completion display info containing tool tip and list item text. internal static readonly CompletionDisplayInfoMapper DefaultDisplayInfoMapper = value - => new CompletionDisplayInfo(value, value); + => (value, value); /// /// Normalizes the input string to an expandable string format for PowerShell. From 1da96c02ae27596bcc0e050d266cf0bb88df7277 Mon Sep 17 00:00:00 2001 From: ArmaanMcleod Date: Mon, 21 Apr 2025 19:48:45 +1000 Subject: [PATCH 6/9] Use named tuples and format on multiple lines for easier readability --- .../commands/management/NewPropertyCommand.cs | 35 ++++++++++++---- .../commands/utility/Join-String.cs | 40 +++++++++++++++---- 2 files changed, 60 insertions(+), 15 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/NewPropertyCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/NewPropertyCommand.cs index 66b6b0f6df6..5c8f1e0fc36 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/NewPropertyCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/NewPropertyCommand.cs @@ -191,13 +191,34 @@ public class PropertyTypeArgumentCompleter : IArgumentCompleter { private static readonly CompletionHelpers.CompletionDisplayInfoMapper RegistryPropertyTypeDisplayInfoMapper = registryPropertyType => registryPropertyType switch { - "String" => (TabCompletionStrings.RegistryStringToolTip, "String"), - "ExpandString" => (TabCompletionStrings.RegistryExpandStringToolTip, "ExpandString"), - "Binary" => (TabCompletionStrings.RegistryBinaryToolTip, "Binary"), - "DWord" => (TabCompletionStrings.RegistryDWordToolTip, "DWord"), - "MultiString" => (TabCompletionStrings.RegistryMultiStringToolTip, "MultiString"), - "QWord" => (TabCompletionStrings.RegistryQWordToolTip, "QWord"), - _ => (TabCompletionStrings.RegistryUnknownToolTip, "Unknown") + "String" => ( + ToolTip: TabCompletionStrings.RegistryStringToolTip, + ListItemText: "String" + ), + "ExpandString" => ( + ToolTip: TabCompletionStrings.RegistryExpandStringToolTip, + ListItemText: "ExpandString" + ), + "Binary" => ( + ToolTip: TabCompletionStrings.RegistryBinaryToolTip, + ListItemText: "Binary" + ), + "DWord" => ( + ToolTip: TabCompletionStrings.RegistryDWordToolTip, + ListItemText: "DWord" + ), + "MultiString" => ( + ToolTip: TabCompletionStrings.RegistryMultiStringToolTip, + ListItemText: "MultiString" + ), + "QWord" => ( + ToolTip: TabCompletionStrings.RegistryQWordToolTip, + ListItemText: "QWord" + ), + _ => ( + ToolTip: TabCompletionStrings.RegistryUnknownToolTip, + ListItemText: "Unknown" + ) }; private static readonly IReadOnlyList s_RegistryPropertyTypes = new List(capacity: 7) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Join-String.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Join-String.cs index 5b0d62a8f01..65440e70aaa 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Join-String.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Join-String.cs @@ -174,14 +174,38 @@ public sealed class SeparatorArgumentCompleter : IArgumentCompleter private static readonly CompletionHelpers.CompletionDisplayInfoMapper SeparatorDisplayInfoMapper = separator => separator switch { - "," => (TabCompletionStrings.SeparatorCommaToolTip, "Comma"), - ", " => (TabCompletionStrings.SeparatorCommaSpaceToolTip, "Comma-Space"), - ";" => (TabCompletionStrings.SeparatorSemiColonToolTip, "Semi-Colon"), - "; " => (TabCompletionStrings.SeparatorSemiColonSpaceToolTip, "Semi-Colon-Space"), - "-" => (TabCompletionStrings.SeparatorDashToolTip, "Dash"), - " " => (TabCompletionStrings.SeparatorSpaceToolTip, "Space"), - NewLineText => (StringUtil.Format(TabCompletionStrings.SeparatorNewlineToolTip, NewLineText), "Newline"), - _ => (separator, separator) + "," => ( + ToolTip: TabCompletionStrings.SeparatorCommaToolTip, + ListItemText: "Comma" + ), + ", " => ( + ToolTip: TabCompletionStrings.SeparatorCommaSpaceToolTip, + ListItemText: "Comma-Space" + ), + ";" => ( + ToolTip: TabCompletionStrings.SeparatorSemiColonToolTip, + ListItemText: "Semi-Colon" + ), + "; " => ( + ToolTip: TabCompletionStrings.SeparatorSemiColonSpaceToolTip, + ListItemText: "Semi-Colon-Space" + ), + "-" => ( + ToolTip: TabCompletionStrings.SeparatorDashToolTip, + ListItemText: "Dash" + ), + " " => ( + ToolTip: TabCompletionStrings.SeparatorSpaceToolTip, + ListItemText: "Space" + ), + NewLineText => ( + ToolTip: StringUtil.Format(TabCompletionStrings.SeparatorNewlineToolTip, NewLineText), + ListItemText: "Newline" + ), + _ => ( + ToolTip: separator, + ListItemText: separator + ) }; private static readonly IReadOnlyList s_separatorValues = new List(capacity: 7) From 0f12e06d26218d5093aa5fbb1d9e0eb3fbd91862 Mon Sep 17 00:00:00 2001 From: ArmaanMcleod Date: Mon, 21 Apr 2025 19:58:18 +1000 Subject: [PATCH 7/9] Add check for tooltip not null or empty --- test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 b/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 index 41e611f6ed5..fb3ffc8484e 100644 --- a/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 +++ b/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 @@ -1373,6 +1373,7 @@ param([ValidatePattern( $completionText = $match.CompletionText.Replace("""", "").Replace("'", "") $listItemText = $match.ListItemText $completionText | Should -BeExactly $listItemText + $match.ToolTip | Should -Not -BeNullOrEmpty } } From 89285c52428758ef25e956fcae23a78118c5ba94 Mon Sep 17 00:00:00 2001 From: Armaan Mcleod Date: Mon, 21 Apr 2025 22:08:50 +1000 Subject: [PATCH 8/9] Update src/System.Management.Automation/engine/CommandCompletion/CompletionHelpers.cs Co-authored-by: Ilya --- .../engine/CommandCompletion/CompletionHelpers.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/System.Management.Automation/engine/CommandCompletion/CompletionHelpers.cs b/src/System.Management.Automation/engine/CommandCompletion/CompletionHelpers.cs index 9857e50e545..d54f4d5dc87 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CompletionHelpers.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CompletionHelpers.cs @@ -49,9 +49,7 @@ internal static IEnumerable GetMatchingResults( { string completionText = QuoteCompletionText(value, quote); - (string ToolTip, string ListItemText) displayInfo = displayInfoMapper(value); - string toolTip = displayInfo.ToolTip; - string listItemText = displayInfo.ListItemText; + (string toolTip, string listItemText) = displayInfoMapper(value); yield return new CompletionResult(completionText, listItemText, resultType, toolTip); } From d1e809cee02462d45397d15cd69cbedcf1344a89 Mon Sep 17 00:00:00 2001 From: ArmaanMcleod Date: Mon, 21 Apr 2025 22:12:04 +1000 Subject: [PATCH 9/9] SA1009 Codefactor: Closing parenthesis should not be preceded by a space. --- .../commands/management/NewPropertyCommand.cs | 21 ++++++---------- .../commands/utility/Join-String.cs | 24 +++++++------------ 2 files changed, 15 insertions(+), 30 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/NewPropertyCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/NewPropertyCommand.cs index 5c8f1e0fc36..fb134ce7a11 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/NewPropertyCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/NewPropertyCommand.cs @@ -193,32 +193,25 @@ public class PropertyTypeArgumentCompleter : IArgumentCompleter { "String" => ( ToolTip: TabCompletionStrings.RegistryStringToolTip, - ListItemText: "String" - ), + ListItemText: "String"), "ExpandString" => ( ToolTip: TabCompletionStrings.RegistryExpandStringToolTip, - ListItemText: "ExpandString" - ), + ListItemText: "ExpandString"), "Binary" => ( ToolTip: TabCompletionStrings.RegistryBinaryToolTip, - ListItemText: "Binary" - ), + ListItemText: "Binary"), "DWord" => ( ToolTip: TabCompletionStrings.RegistryDWordToolTip, - ListItemText: "DWord" - ), + ListItemText: "DWord"), "MultiString" => ( ToolTip: TabCompletionStrings.RegistryMultiStringToolTip, - ListItemText: "MultiString" - ), + ListItemText: "MultiString"), "QWord" => ( ToolTip: TabCompletionStrings.RegistryQWordToolTip, - ListItemText: "QWord" - ), + ListItemText: "QWord"), _ => ( ToolTip: TabCompletionStrings.RegistryUnknownToolTip, - ListItemText: "Unknown" - ) + ListItemText: "Unknown"), }; private static readonly IReadOnlyList s_RegistryPropertyTypes = new List(capacity: 7) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Join-String.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Join-String.cs index 65440e70aaa..80a04b07f17 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Join-String.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Join-String.cs @@ -176,36 +176,28 @@ public sealed class SeparatorArgumentCompleter : IArgumentCompleter { "," => ( ToolTip: TabCompletionStrings.SeparatorCommaToolTip, - ListItemText: "Comma" - ), + ListItemText: "Comma"), ", " => ( ToolTip: TabCompletionStrings.SeparatorCommaSpaceToolTip, - ListItemText: "Comma-Space" - ), + ListItemText: "Comma-Space"), ";" => ( ToolTip: TabCompletionStrings.SeparatorSemiColonToolTip, - ListItemText: "Semi-Colon" - ), + ListItemText: "Semi-Colon"), "; " => ( ToolTip: TabCompletionStrings.SeparatorSemiColonSpaceToolTip, - ListItemText: "Semi-Colon-Space" - ), + ListItemText: "Semi-Colon-Space"), "-" => ( ToolTip: TabCompletionStrings.SeparatorDashToolTip, - ListItemText: "Dash" - ), + ListItemText: "Dash"), " " => ( ToolTip: TabCompletionStrings.SeparatorSpaceToolTip, - ListItemText: "Space" - ), + ListItemText: "Space"), NewLineText => ( ToolTip: StringUtil.Format(TabCompletionStrings.SeparatorNewlineToolTip, NewLineText), - ListItemText: "Newline" - ), + ListItemText: "Newline"), _ => ( ToolTip: separator, - ListItemText: separator - ) + ListItemText: separator), }; private static readonly IReadOnlyList s_separatorValues = new List(capacity: 7)