KEMBAR78
Enable completion of scoped variables without specifying scope by MartinGC94 · Pull Request #20340 · PowerShell/PowerShell · GitHub
Skip to content

Conversation

@MartinGC94
Copy link
Contributor

PR Summary

Changes how completion of variables with scopes are handled, so variables like: $Global:TestVar = "Hello" can be completed without specifying the scope like this: TestVar<Tab>.
Also enabled completion of variables with the using scope so this: $TestVar="Hello";$using:Tes<Tab> completes the variable.

PR Context

PR Checklist

@pull-request-quantifier-deprecated

This PR has 53 quantified lines of changes. In general, a change size of upto 200 lines is ideal for the best PR experience!


Quantification details

Label      : Small
Size       : +32 -21
Percentile : 21.2%

Total files changed: 2

Change summary by file extension:
.cs : +26 -21
.ps1 : +6 -0

Change counts above are quantified counts, based on the PullRequestQuantifier customizations.

Why proper sizing of changes matters

Optimal pull request sizes drive a better predictable PR flow as they strike a
balance between between PR complexity and PR review overhead. PRs within the
optimal size (typical small, or medium sized PRs) mean:

  • Fast and predictable releases to production:
    • Optimal size changes are more likely to be reviewed faster with fewer
      iterations.
    • Similarity in low PR complexity drives similar review times.
  • Review quality is likely higher as complexity is lower:
    • Bugs are more likely to be detected.
    • Code inconsistencies are more likely to be detected.
  • Knowledge sharing is improved within the participants:
    • Small portions can be assimilated better.
  • Better engineering practices are exercised:
    • Solving big problems by dividing them in well contained, smaller problems.
    • Exercising separation of concerns within the code changes.

What can I do to optimize my changes

  • Use the PullRequestQuantifier to quantify your PR accurately
    • Create a context profile for your repo using the context generator
    • Exclude files that are not necessary to be reviewed or do not increase the review complexity. Example: Autogenerated code, docs, project IDE setting files, binaries, etc. Check out the Excluded section from your prquantifier.yaml context profile.
    • Understand your typical change complexity, drive towards the desired complexity by adjusting the label mapping in your prquantifier.yaml context profile.
    • Only use the labels that matter to you, see context specification to customize your prquantifier.yaml context profile.
  • Change your engineering behaviors
    • For PRs that fall outside of the desired spectrum, review the details and check if:
      • Your PR could be split in smaller, self-contained PRs instead
      • Your PR only solves one particular issue. (For example, don't refactor and code new features in the same PR).

How to interpret the change counts in git diff output

  • One line was added: +1 -0
  • One line was deleted: +0 -1
  • One line was modified: +1 -1 (git diff doesn't know about modified, it will
    interpret that line like one addition plus one deletion)
  • Change percentiles: Change characteristics (addition, deletion, modification)
    of this PR in relation to all other PRs within the repository.


Was this comment helpful? 👍  :ok_hand:  :thumbsdown: (Email)
Customize PullRequestQuantifier for this repository.

@StevenBucher98 StevenBucher98 added the PowerShell-Docs not needed The PR was reviewed and doesn't appear to require a PowerShell Docs update label Sep 25, 2023
@microsoft-github-policy-service microsoft-github-policy-service bot added the Review - Needed The PR is being reviewed label Oct 2, 2023
@iSazonov
Copy link
Collaborator

Changes how completion of variables with scopes are handled, so variables like: $Global:TestVar = "Hello" can be completed without specifying the scope like this: TestVar<Tab>.

I'm not sure it's unequivocally useful and/or convenient. It's better to discuss it in a new issue and get WG's opinion.

Also enabled completion of variables with the using scope so this: $TestVar="Hello";$using:Tes<Tab> completes the variable.

That seems like an oversight. It would have been handy to have. If you put this in a separate PR then I will review it.

@microsoft-github-policy-service microsoft-github-policy-service bot removed the Review - Needed The PR is being reviewed label Dec 20, 2023
@microsoft-github-policy-service microsoft-github-policy-service bot added the Review - Needed The PR is being reviewed label Dec 27, 2023
@MartinGC94
Copy link
Contributor Author

I'm not sure it's unequivocally useful and/or convenient. It's better to discuss it in a new issue and get WG's opinion.

Variable completion includes variables from the session state so if you declare a global variable: $global:Test = "Hello" and run it then it's already included in the results. My change just makes the user experience consistent, regardless if the line with the variable declaration has been run or not.

@SeeminglyScience SeeminglyScience added WG-Interactive-Console the console experience WG-NeedsReview Needs a review by the labeled Working Group labels Dec 4, 2024
@theJasonHelmick theJasonHelmick added WG-Reviewed A Working Group has reviewed this and made a recommendation and removed WG-NeedsReview Needs a review by the labeled Working Group labels Dec 4, 2024
@kilasuit kilasuit added Review - Needed The PR is being reviewed and removed Review - Needed The PR is being reviewed labels Dec 4, 2024
@MartinGC94
Copy link
Contributor Author

@theJasonHelmick I see you added the WG reviewed tag. What was the conclusion? Are we good to merge this?

@iSazonov
Copy link
Collaborator

@MartinGC94 Please resolve merge conflicts.

@microsoft-github-policy-service microsoft-github-policy-service bot removed the Review - Needed The PR is being reviewed label Feb 19, 2025
@iSazonov

This comment was marked as outdated.

@azure-pipelines

This comment was marked as outdated.

@iSazonov iSazonov added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Feb 25, 2025
if (colon >= 0)
{
scopePrefix = wordToComplete.Remove(colon + 1);
wordToComplete = wordToComplete.Substring(colon + 1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see wordToComplete in line 5282 but now we modify the wordToComplete before use in the line. Is this intentional? Have we tests for the 5282 line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wordToComplete is modified to remove the scope so in scenarios like: $script:MyVar<Tab> it becomes MyVar. So we can find variables that start with MyVar. My test on line 702 covers this scenario because if we didn't remove the global scope from the input text, it wouldn't be able to find any variables at all.

@iSazonov iSazonov self-assigned this Feb 25, 2025
@iSazonov iSazonov merged commit 502653d into PowerShell:master Feb 25, 2025
39 of 41 checks passed
@microsoft-github-policy-service
Copy link
Contributor

microsoft-github-policy-service bot commented Feb 25, 2025

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

🔗 https://aka.ms/PSRepoFeedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log PowerShell-Docs not needed The PR was reviewed and doesn't appear to require a PowerShell Docs update Small WG-Interactive-Console the console experience WG-Reviewed A Working Group has reviewed this and made a recommendation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants