在SSMS中创建代码段的代码段

时间:2019-10-14 09:01:59

标签: sql-server ssms code-snippets vscode-snippets

问题: 通常,如果要将代码另存为摘要,则必须打开一些xml模板,调查标签等。Reference

是否可以尽可能简化此过程:即创建一个SurroundsWith代码段,该代码段将用代码段代码包装所选代码?

1 个答案:

答案 0 :(得分:0)

请尝试以下操作:

  1. 将此代码另存为 create_new_snippet.snippet ,然后通过代码段管理器(Ctrl + K,Ctrk + B)将其添加到您的SSMS中。
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>Create_new_snippet</Title>
            <Shortcut></Shortcut>
            <Description>Snippet to create a snippet</Description>
            <Author>Denis Sipchenko</Author>
            <SnippetTypes>
                <SnippetType>SurroundsWith</SnippetType>
            </SnippetTypes>
        </Header>
        <Snippet>
            <Declarations>
                <Literal> <ID>Title</ID>        <Default>NewSnippetTitle</Default>         <ToolTip>NewSnippetTitle</ToolTip>                   </Literal>
                <Literal> <ID>Description</ID>  <Default>NewSnippetDescription</Default>   <ToolTip>NewSnippetDescription</ToolTip>             </Literal>
                <Literal> <ID>Author</ID>       <Default>Unsung Hero</Default>             <ToolTip>NewSnippetAuthor</ToolTip>                  </Literal>
                <Literal> <ID>SnippetType</ID>  <Default>SurroundsWith</Default>           <ToolTip>SurroundsWith OR Expansion</ToolTip>                  </Literal>
                <Literal> <ID>CodeComment</ID>  <Default>-- Sorry. I was too lazy to write some usefull comment here</Default>         <ToolTip>Comment for you code</ToolTip>                  </Literal>                
            </Declarations>
            <Code Language="sql"
                Delimiter="`">
                <![CDATA[<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>`Title`</Title>    <!--`Title`.snippet -copy/paste for filename-->
            <Shortcut></Shortcut>
            <Description>`Description`</Description>
            <Author>`Author`</Author>
            <SnippetTypes>
                <SnippetType>`SnippetType`</SnippetType>    <!--SurroundsWith/Expansion-->
            </SnippetTypes>
        </Header>
        <Snippet>
            <Declarations>
                <Literal> <ID></ID>     <Default></Default>         <ToolTip></ToolTip>                   </Literal>
            </Declarations>
            <Code Language="SQL">
                <![CDATA[`CodeComment`
$selected$`selected`$end$`end`
]]`fake`>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>
]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>
  1. 选择您要保存为代码段的代码,然后调用Surround With...代码段(Edit\IntelliSense\Surround With... Ctrl+K, Ctrl+S

  2. 根据需要编辑参数(如“标题”,“说明”等),并另存为[YourSnippetName].snippet到您的代码段文件夹中。