Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code snippet shortcut doesn't work everywhere

I have a code snippet string.Format(@"") with a shortcut sf that inserts the snippet and places the cursor in between the two double quotes. Really convenient. I can normally use it, of course, by just typing sf and hitting tab twice:

enter image description here

However, I've just discovered that the shortcut doesn't work in all locations. For example, if I'm building this statement:

if(true) throw new FormatException() // <-- cursor is inside these parens

and I hit sf, the shortcut does not appear in the intellisense menu, and if I hit Tab twice, it doesn't generate the snippet. Why?

I have tried searching for "C# code snippet shortcut sometimes doesn't work", "C# code snippet shortcut doesn't work", "visual studio code snippet sometimes doesn't work" among others, and I can't find anything useful about it.

EDIT: Here is the snippet definition:

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
      </SnippetTypes>
      <Title>String.Format with @</Title>
      <Author>Rory</Author>
      <Description>
      </Description>
      <HelpUrl>
      </HelpUrl>
      <Shortcut>sf</Shortcut>
    </Header>
    <Snippet>
      <Declarations>
        <Literal Editable="true">
          <ID>anchor</ID>
          <ToolTip>
          </ToolTip>
          <Default>
          </Default>
          <Function>
          </Function>
        </Literal>
      </Declarations>
      <Code Language="csharp" Delimiter="$" Kind="method body"><![CDATA[string.Format(@"$selected$$end$")]]></Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>
like image 878
rory.ap Avatar asked Oct 01 '15 16:10

rory.ap


1 Answers

According to the docs the Kind attribute determines where you can use the snippet - you have specified "method body" and you should probably specify "any"

like image 65
gordy Avatar answered Sep 29 '22 02:09

gordy