Skip to content

Conversation

DoctorKrolic
Copy link
Contributor

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 had GetSnippetDataAsync and GetSnippetAsync methods and for an external person it is somewhat confusing what is the difference between them. Moreover, from the name GetSnippetDataAsync I expect to get eigher Task<SnippetData> or a ValueTask<SnippetData>, but not ValueTask<SnippetData?>. By pooling AdditionalFilterTexts up to the interface I can replace confusing GetSnippetDataAsync with IsValidSnippetLocationAsync and construct SnippetData struct when this method returns true
  • Applied static to a few things
  • Renamed and reordered a few members for clarity

@DoctorKrolic DoctorKrolic requested a review from a team as a code owner August 11, 2024 11:35
@ghost ghost added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Aug 11, 2024
@dotnet-policy-service dotnet-policy-service bot added Community The pull request was submitted by a contributor who is not a Microsoft employee. VSCode labels Aug 11, 2024
/// <summary>
/// The position that the cursor should end up on
/// </summary>
public readonly int FinalCaretPosition;
Copy link
Contributor Author

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)
Copy link
Contributor Author

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;
Copy link
Contributor Author

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;
Copy link
Contributor Author

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

@DoctorKrolic
Copy link
Contributor Author

@akhera99 PTAL

Copy link
Member

@akhera99 akhera99 left a 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee. untriaged Issues and PRs which have not yet been triaged by a lead VSCode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants