-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Refactor semantic snippets #74712
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
Refactor semantic snippets #74712
Conversation
/// <summary> | ||
/// The position that the cursor should end up on | ||
/// </summary> | ||
public readonly int FinalCaretPosition; |
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.
This is a rename CursorPosition
-> FinalCaretPosition
. First, I wanted to emphasize that this position is used after text changes and placeholders, so Final
. And second, the standard term for roslyn is 'caret', not 'cursor', so made it more consistent with the rest of the codebase
int cursorPosition, | ||
ImmutableArray<SnippetPlaceholder> placeholders) | ||
ImmutableArray<SnippetPlaceholder> placeholders, | ||
int finalCaretPosition) |
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.
Reordered for clarity. We first insert text changes, then let user loop through placeholders and only then move user's caret to its final position
/// Editable text in the snippet. | ||
/// </summary> | ||
public readonly string Identifier; | ||
public readonly string Text; |
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.
This can be an actual identifier, but it also can be any other text, e.g. in if
snippet the placeholder is a full condition expression. So Identifier
is a confusing name for this thing, renamed it to more generic Text
/// be converted into LSP formatted strings. | ||
/// </summary> | ||
public readonly ImmutableArray<int> PlaceHolderPositions; | ||
public readonly ImmutableArray<int> StartingPositions; |
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.
Wanted to emphasize that these are starting positions for clarity. Also since they are already inside SnippetPlaceholder
type, having PlaceHolder
in the name is an overkill
@akhera99 PTAL |
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 like the refactoring of the SnippetProvider. I agree, if I were someone new coming into this codebase I would be confused by the distinction of GetSnippetData and GetSnippetChange (I should write better comments).
Thanks for the contribution!
I was working on another snippet-related PR and saw a few things that IMO can be improved. So I extracted all these refactorings into this PR. What have I done and why:
ISnippetProvider
hadGetSnippetDataAsync
andGetSnippetAsync
methods and for an external person it is somewhat confusing what is the difference between them. Moreover, from the nameGetSnippetDataAsync
I expect to get eigherTask<SnippetData>
or aValueTask<SnippetData>
, but notValueTask<SnippetData?>
. By poolingAdditionalFilterTexts
up to the interface I can replace confusingGetSnippetDataAsync
withIsValidSnippetLocationAsync
and constructSnippetData
struct when this method returnstrue
static
to a few things