Customizing the snippet's body and properties

For editing of already supported or your own custom snippets, you only need to open a file in any editor, specify the necessary changes, and save it. All the snippets are placed in TWS installation directory (it could be at the disk C: for example); to find them navigate to the Extensions\Application\Editor\CodeSnippets\Snippets folder,

NB: During the updates of The Welkin Suite, the IDE reverts all default snippets to their original state. So all your changes in default snippets will be lost. At the same time, snippets that were added by you are not changed by the update process. Probably, you may need to re-add a folder to the Code Snippet Manager after the update.

The body of a snippet has the following structure:

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets
    xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title></Title>
            <Shortcut></Shortcut>
            <Description></Description>
            <Author></Author>
            <SnippetTypes>
                <SnippetType></SnippetType>
            </SnippetTypes>
        </Header>
        <Snippet>
            <Declarations>
                <Literal>
                    <ID></ID>
                    <Default></Default>
                    <ToolTip></ToolTip>
                </Literal></Declarations>
            <Code Language="Apex"><![CDATA[ ]]></Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>

Here are the details about the structure.

Header

  • Title — how your snippet would be called from the code,
  • Shortcut — it describes if the snippet is for a class or a method,
  • Author and Description — it can be useful to get more information about a snippet in the Code Snippets Manager and when sharing it with other developers,
  • Snippets Type — it describes, which type of a snippet you are going to create. Possible values are Expansion (a snippet just expands into a block of code) or SurroundWith (a snippet wraps around some code, like the try..catch block).

Snippet

  • Declarations — in this section you describe the parameters that are going to be replaced in a snippet body, e.g. 'variables' as a number of Literal entries with following parameters:
    • ID — a name of the parameter, which is used in the code,
    • Default — the default value of the parameter,
    • ToolTip — a tooltip text that will be displayed to a user,
  • Snippet's body itself entered as <![CDATA[ ]]> block inside of the Code element.

Snippet's body

In the snippet's body, you can enter any code that you'd like to be generated. In order to use any of the 'variables' that you've declared you should enter it in the snippet's body as $id$. Other variables that are available for insertion are the next:

  • $end$ — the end of a line,
  • $selected — selected text in case if your snippet is of SurroundWith type.

Taking this into account snippet's body for a simple snippet that adds System.assertEquals call would look like this (assuming that you have declared two literals named expected and actual):

<![CDATA[System.assertEquals($expected$, $actual$); $end$]]>

In this section:

This also may be useful:

Last modified: 2017/05/24 11:29

footer image