Skip to content

Refactor Tooltip/ListItemText mapping to use CompletionDisplayInfoMapper delegate #25395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

ArmaanMcleod
Copy link
Contributor

@ArmaanMcleod ArmaanMcleod commented Apr 21, 2025

PR Summary

Replaced Func<string, string> toolTipMapping and Func<string, string> listItemTextMapping with CompletionDisplayInfoMapper delegate.

This is to allow any delegate to be passed into GetMatchingResults and reduces mapping parameters. The ToolTip and ListItemText is wrapped in a tuple.

I realised as well there is a lack of tests for ToolTip and ListItemText so added those as well.

PR Context

PR Checklist

@ArmaanMcleod ArmaanMcleod force-pushed the convert-func-to-delegate-mapping branch from 9074808 to 96170ce Compare April 21, 2025 08:31
@iSazonov iSazonov requested a review from Copilot April 21, 2025 09:11
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the mapping of tooltip and list item text for completion results by replacing separate mapping delegates with a single delegate returning a CompletionDisplayInfo instance.

  • Replaced toolTipMapping and listItemTextMapping with a unified CompletionDisplayInfoMapper delegate.
  • Introduced the CompletionDisplayInfo class and its default mapper in CompletionHelpers.cs.
  • Updated separator and registry property type mappings in Join-String.cs and NewPropertyCommand.cs to use the new delegate.

Reviewed Changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated no comments.

File Description
CompletionHelpers.cs Replaced two mapping delegates with CompletionDisplayInfoMapper and added helper types.
Join-String.cs Updated separator mapping to use the new delegate-based approach.
NewPropertyCommand.cs Updated registry property type mappings to use CompletionDisplayInfoMapper.
Files not reviewed (1)
  • test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1: Language not supported
Comments suppressed due to low confidence (2)

src/Microsoft.PowerShell.Commands.Management/commands/management/NewPropertyCommand.cs:233

  • Consider adding tests that cover each registry property type mapping provided by RegistryPropertyTypeDisplayInfoMapper to ensure all mapping cases are correctly handled.
displayInfoMapper: RegistryPropertyTypeDisplayInfoMapper,

src/Microsoft.PowerShell.Commands.Utility/commands/utility/Join-String.cs:175

  • [nitpick] Ensure that the SeparatorDisplayInfoMapper switch expression and the s_separatorValues list remain consistent; adding a brief comment may help future maintainers keep both updated simultaneously when new separators are introduced.
private static readonly CompletionHelpers.CompletionDisplayInfoMapper SeparatorDisplayInfoMapper = separator => separator switch

@iSazonov iSazonov added the CL-CodeCleanup Indicates that a PR should be marked as a Code Cleanup change in the Change Log label Apr 21, 2025
@iSazonov iSazonov self-assigned this Apr 21, 2025
@iSazonov

This comment was marked as outdated.

This comment was marked as outdated.

Copy link
Collaborator

@iSazonov iSazonov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with one style comment.

@ArmaanMcleod
Copy link
Contributor Author

Thanks @iSazonov. I have resolved style comment and also fixed some Codefactor issues.

@iSazonov

This comment was marked as outdated.

This comment was marked as outdated.

@iSazonov iSazonov merged commit 5c8b174 into PowerShell:master Apr 21, 2025
40 of 42 checks passed
Copy link
Contributor

microsoft-github-policy-service bot commented Apr 21, 2025

📣 Hey @@ArmaanMcleod, how did we do? We would love to hear your feedback with the link below! 🗣️

🔗 https://aka.ms/PSRepoFeedback

Sysoiev-Yurii pushed a commit to Sysoiev-Yurii/PowerShell that referenced this pull request May 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CL-CodeCleanup Indicates that a PR should be marked as a Code Cleanup change in the Change Log
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants