KEMBAR78
Refactor and add comments to `CompletionRequiresQuotes` to clarify implementation by ArmaanMcleod · Pull Request #25223 · PowerShell/PowerShell · GitHub
Skip to content

Conversation

@ArmaanMcleod
Copy link
Contributor

@ArmaanMcleod ArmaanMcleod commented Mar 24, 2025

PR Summary

This PR simplifies CompletionRequiresQuotes method and adds XML comments clarifying implementation with the tokenising and error handling. It can be difficult to understand what this method is trying to do, so hoping comments explain intent clearer. I have also broken-down conditions into variables so it's easier to follow flow and perhaps add to this method in future.

PR Context

PR Checklist

Comment on lines 139 to 148
// Check the type of the first token:
// - String token (e.g. a string literal or text)
// - PowerShell keyword (e.g. "while", "if")
bool isStringToken = firstToken is StringToken;
bool isKeywordToken = (firstToken.TokenFlags & TokenFlags.Keyword) != 0;

// Perform additional checks before checking characters:
// - If no quotes required and the first token is a string token
// - If the input is exactly 2 tokens long and the first token is a keyword
if ((!requireQuote && isStringToken) || (tokens.Length == 2 && isKeywordToken))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Really these both comments are obvious and it is better to remove its.
Examples of non-obvious scenarios could be useful here, but it is better to show them in the general description of this method. If you don't know an exhaustive list, then it's best not to add anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@iSazonov Yep good point, I agree. I have summarized this in the XML summary. I think code changes alone make intent clearer anyways.

@iSazonov
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@iSazonov iSazonov self-assigned this Mar 25, 2025
@iSazonov iSazonov added the CL-CodeCleanup Indicates that a PR should be marked as a Code Cleanup change in the Change Log label Mar 25, 2025
@iSazonov iSazonov enabled auto-merge (squash) March 25, 2025 10:51
auto-merge was automatically disabled March 25, 2025 10:51

Head branch was pushed to by a user without write access

@iSazonov iSazonov enabled auto-merge (squash) March 25, 2025 10:53
@iSazonov
Copy link
Collaborator

@ArmaanMcleod What are your plans? It may be worth continuing PR with improving the interface.

@ArmaanMcleod
Copy link
Contributor Author

ArmaanMcleod commented Mar 25, 2025

@ArmaanMcleod What are your plans? It may be worth continuing PR with improving the interface.

@iSazonov I think after this one I am happy with the refactoring and will come back to the interface. Code is cleaned up quite a bit and we have streamlined methods with CompletionHelpers class. I was trying to simplify this code as much as possible before going back to interface.

@ArmaanMcleod
Copy link
Contributor Author

@iSazonov I think auto merge didn't work for this one. Some checks still waiting.

@iSazonov

This comment was marked as outdated.

@azure-pipelines

This comment was marked as outdated.

@iSazonov iSazonov merged commit 84369c7 into PowerShell:master Mar 26, 2025
38 of 40 checks passed
@microsoft-github-policy-service
Copy link
Contributor

microsoft-github-policy-service bot commented Mar 26, 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