dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.1k stars 4.04k forks source link

Support more code snippets #24224

Open kuhlenh opened 6 years ago

kuhlenh commented 6 years ago

Filing on behalf of a customer who wants to be able to have postfix templates and custom templates (similar to ReSharper live templates).

Examples:

We have some of these with snippets, but I don't think we have all of them and our customization story isn't great. Also need to make sure we document all of these...

kuhlenh commented 6 years ago

I have some more concrete info here:

zarenner commented 6 years ago

I'd like code snippets to be able to guess expected generic types, similar to e.g. this simple ReSharper live template example that automatically figures out T when emitting a Moq It.IsAny<T>() snippet.

kuhlenh commented 6 years ago

Things to also consider:

alrz commented 6 years ago

.var .foreach

.if .typeof .default .null (null check) .switch .using .ret (return) .assert (Debug.Assert) .block (surround) .cast (direct cast) .new .await

MarkusAmshove commented 5 years ago

.null .notnull .nameof

alrz commented 4 years ago

This will have a huge impact on editing experience though it's low pri, it seems. I use .var and .foreach in Rider all the time and it's really helpful.

CyrusNajmabadi commented 4 years ago

Can you describe how the particular snippets work? In particular, it may not be enough to just include them, we may need to update the existing snippet infrastructure to support functionality it doesn't currently have

alrz commented 4 years ago

For instance, (expression).var [enter] is exactly the same as selecting the expression and "introduce local". So yeah I think it's actually more involved than "snippets" feature we have today.

For .var Rider even ask if you want to replace this one occurrence or all of them.

That said, I think "custom suffix snippets" should be separated out from the others.

alrz commented 4 years ago

@CyrusNajmabadi Do we have the infrastructure required for this? I think we need something like CompletionProvider but with the ability to change the whole Document

LunicLynx commented 2 years ago

Any progress on this?