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

问题描述 投票:0回答:1

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

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

sql-server ssms code-snippets vscode-snippets
1个回答
0
投票

请尝试以下:

  1. 将此代码另存为create_new_snippet.snippet,然后通过代码段管理器(Ctrl + K,Ctrk + B)将其添加到您的SSMS中>]
  2. <?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到您的代码片段文件夹中。

© www.soinside.com 2019 - 2024. All rights reserved.