-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Improve documentation and error message for InsertTokensBefore/After and ReplaceToken methods #80691
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
Conversation
…nd ReplaceToken methods Co-authored-by: CyrusNajmabadi <[email protected]>
| </data> | ||
| <data name="MissingListItem" xml:space="preserve"> | ||
| <value>The item specified is not the element of a list.</value> | ||
| <value>The specified token must be a direct element of a SyntaxTokenList (such as a modifier in a list of modifiers). The token cannot be an arbitrary token from the syntax tree.</value> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot This is not ok. THis error is also used when a node is not found that needs to be in a list, not just a token. We'll need two errors. Keep the original one, and add a new MissingTokenListItem. Then update SyntaxReplacer.VisitToken to throw the new message. #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. I've kept the original MissingListItem error and added a new MissingTokenListItem error. Updated both C# and VB TokenListEditor.VisitToken methods to use the new error message. Commit: 3b60862 (will be updated in next push)
Co-authored-by: CyrusNajmabadi <[email protected]>
|
@dotnet/roslyn-compiler ptal. |
| Replace | ||
| } | ||
|
|
||
| private static InvalidOperationException GetItemNotListElementException() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like both of these methods are now called only once, would it make sense to inline them now?
| <trans-unit id="MissingListItem"> | ||
| <source>The item specified is not the element of a list.</source> | ||
| <target state="translated">Zadaná položka není elementem seznamu.</target> | ||
| <target state="needs-review-translation">Zadaná položka není elementem seznamu.</target> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe copilot originally changed the existing message, it must not have reverted.
|
Consider adding tests observing that expected message is used. |
AlekseyTs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like xlf files contain unexpected changes. Were they automatically generated?
Plan for Improving InsertTokensBefore/After and ReplaceToken Documentation and Error Messages
Based on the issue analysis:
Update XML documentation for
InsertTokensBefore,InsertTokensAfter, andReplaceToken(tokenInList, IEnumerable<SyntaxToken>)methods to clearly state:tokenInListparameter must be a direct element of aSyntaxTokenListSyntaxTokenListKeep the original
MissingListItemerror message for nodesAdd new
MissingTokenListItemerror message specifically for tokensUpdate
TokenListEditor.VisitTokenin both C# and VB to use the new token-specific error messageUpdate .xlf localization files for the new error message
Verify tests still pass and error messages are improved
All changes complete! The original
MissingListItemerror message has been preserved for nodes, and a newMissingTokenListItemerror message has been added specifically for tokens. The error message for tokens is now: "The specified token must be a direct element of a SyntaxTokenList (such as a modifier in a list of modifiers). The token cannot be an arbitrary token from the syntax tree."Original prompt
Fixes #3082
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.