dotnet / dotnet/roslyn

Code snippets do not always appear for insertion, depending on the cursor placement?

Open
#73,644 2 comments 0 reactions 1 assignee Claimed by @akhera99 View on GitHub
Area-IDE
Dominant language
C#
Stars
20.7k
Forks
4.3k
PR merge metrics
PR metrics pending

Description

_This issue has been moved from [a ticket on Developer Community](https://developercommunity.visualstudio.com/t/Code-snippets-do-not-always-appear-for-i/10650252)._

---
\[severity:It’s more difficult to complete my work\]
There seems to be some logic that prevents certain code snippets from being suggested at various places in a document. I’d like to know if this is a bug or intentional and if intentional I’d like more information about this behavior or a way of controlling it because right now for me it limits how useful code snippets can be

I have created a snippet `twc` that inserts an extension method call `.TagWithCallPath(cc,c)`

It is intended to be used on a DbSet:

![image.png](https://aka.ms/dc/image?name=B0d568982d55345c2ac11cfd048d66c5f638501423775069390_20240501-073933-image.png&tid=0d568982d55345c2ac11cfd048d66c5f638501423775069390)

My snip has a pink arrow. The suggested snips are in yellow - **as, is, switch, with**

My snip is not suggested.

If I move the caret to placed after a `{` then the snip does appear and will insert:

![image.png](https://aka.ms/dc/image?name=B9704e50b199a42f99aedf5a81001c2ce638501425306113772_20240501-074206-image.png&tid=9704e50b199a42f99aedf5a81001c2ce638501425306113772)

Why does the snip show here, but not before?

If I press tab when the snip is not suggested, i get "as"

---

I understand the notion that some snips should be prevented in some places = it would be silly to write `var ctor =` and suddenly have a constructor appear in the middle of a method but if there is a logic that does something like that it is currently making some of my snippets unusable - how do I turn that off?

If there is no way of turning that off, I wish to raise a feature suggestion of "allow snips to be configured so that they can always be inserted"

---
### Original Comments

#### Feedback Bot on 5/1/2024, 08:47 PM:

(private comment, text removed)
#### Wenwen Fan [MSFT] on 5/6/2024, 09:16 PM:

(private comment, text removed)
#### MaWh on 5/9/2024, 06:37 AM:

(private comment, text removed)
#### MaWh on 5/9/2024, 06:47 AM:

(private comment, text removed)
#### Wenwen Fan [MSFT] on 5/20/2024, 09:14 PM:

(private comment, text removed)

---
### Original Solutions
(no solutions)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.