Can Poyrazoğlu
Can Poyrazoğlu

Reputation: 34780

Creating Javascript snippet for Visual Studio that has a replacable literal

I am trying to create a Javascript snippet for Visual Studio 2015 Update 2. It should expand into something like:

myObject.HIGHLIGHT_THIS_METHOD_FOR_REPLACING.something();

I could create expansion snippet. I type the shortcut and double tap tab, and it expands. However, it doesn't highlight "HIGHLIGHT_THIS_METHOD_FOR_REPLACING" part. I'm following the tutorial at https://msdn.microsoft.com/en-us/library/ms165394.aspx and I'm stuck. Here is my snippet:

<?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>MyTitle</Title>
      <Author>Can Poyrazoğlu</Author>
      <Description>My Description
      </Description>
      <HelpUrl>
      </HelpUrl>
      <Shortcut>myShortcut</Shortcut>
    </Header>
    <Snippet>
      <Code Language="javascript"><![CDATA[myObject.$HIGHLIGHT_THIS_METHOD_FOR_REPLACING$.something();]]></Code>
    </Snippet>
    <Declarations>
       <Literal>
        <ID>HIGHLIGHT_THIS_METHOD_FOR_REPLACING</ID>
        <ToolTip>Some tooltip</ToolTip>
        <Default>something</Default>
    </Literal>
    </Declarations>
  </CodeSnippet>
</CodeSnippets>

I am getting myObject..something(); as the expansion, with no default valur for the literal part and with the cursor at the beginning of the whole text (just before myObject), which kills the whole point of the shortcut.

What am I doing wrong?

Upvotes: 0

Views: 85

Answers (1)

Weiwei
Weiwei

Reputation: 3766

According to the document and the XML sample you provided, I tested in both VB and Javascript in VS2015 (with Update 1 and Update 3) and VS2013 with Update 5. I get the same issue with you in VS2015. But in VS2013, the replacements are all display but without highlighted.

I have submit this issue to Visual Studio Connect with detailed steps. Please vote and add your comments for this issue. Before this issue resolved, I suggest you add the replacement content manually.

https://connect.microsoft.com/VisualStudio/feedback/details/3110313/replacements-element-in-code-snippet-doesnt-work

Upvotes: 1

Related Questions