Skip to content
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

Semantic snippets: Implement do snippet #72842

Merged
merged 5 commits into from
Apr 5, 2024

Conversation

DoctorKrolic
Copy link
Contributor

Part of #64144 (don't forget to check the item when merging)

@DoctorKrolic DoctorKrolic requested a review from a team as a code owner April 2, 2024 17:13
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 2, 2024
@dotnet-policy-service dotnet-policy-service bot added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Apr 2, 2024
@DoctorKrolic
Copy link
Contributor Author

@CyrusNajmabadi Regardless your request on extracting constants: I tried to preserve layering and separated identifiers into 2 categories: those which can theoretically be reused in VB (e.g. cw) and those which are C# only (keywords and so on). As part of that work I moved some properties up to C# layer (e.g. for else identifier since it is clearly a C# keyword and in VB it would be Else, same with description). Also since I touched most files in snippets folder anyway, I refactored classes in it a bit by making importing constructors primary and sealing what was still unsealed

@DoctorKrolic
Copy link
Contributor Author

@CyrusNajmabadi PTAL


protected override SyntaxNode GetCondition(SyntaxNode node)
{
var doStatement = (DoStatementSyntax)node;
Copy link
Member

Choose a reason for hiding this comment

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

nit: int eh future, it would nice to use generics (with teh base type) to make it so that all this is strongly typed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this particular example this would just move the hard cast one layer above:

protected override ImmutableArray<SnippetPlaceholder> GetPlaceHolderLocationsList(SyntaxNode node, ISyntaxFacts syntaxFacts, CancellationToken cancellationToken)
{
if (ConstructedFromInlineExpression)
return [];
var condition = GetCondition(node);

GetPlaceHolderLocationsList is from the AbstractSnippetProvider class, which is a base class for all snippets. And even if we try to make AbstractSnippetProvider generic as well, we will still need to hard cast here (see how mainChangeNode is just found via annotation, the cast would be here):
var mainChangeNode = reformattedRoot.GetAnnotatedNodes(FindSnippetAnnotation).FirstOrDefault();
Contract.ThrowIfNull(caretTarget);
Contract.ThrowIfNull(mainChangeNode);
var annotatedReformattedDocument = documentWithIndentation.WithSyntaxRoot(reformattedRoot);
// All the TextChanges from the original document. Will include any imports (if necessary) and all snippet associated
// changes after having been formatted.
var changes = await annotatedReformattedDocument.GetTextChangesAsync(document, cancellationToken).ConfigureAwait(false);
// Gets a listing of the identifiers that need to be found in the snippet TextChange
// and their associated TextSpan so they can later be converted into an LSP snippet format.
var placeholders = GetPlaceHolderLocationsList(mainChangeNode, syntaxFacts, cancellationToken);

Copy link
Member

Choose a reason for hiding this comment

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

Yup. mkaing these changes in #72892

@CyrusNajmabadi
Copy link
Member

Thanks!

@CyrusNajmabadi CyrusNajmabadi merged commit e6c6877 into dotnet:main Apr 5, 2024
27 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Apr 5, 2024
@DoctorKrolic DoctorKrolic deleted the do-while-snippet branch April 5, 2024 18:53
@dibarbet dibarbet modified the milestones: Next, 17.11 P1 Apr 29, 2024
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants