garbas / vim-snipmate

snipMate.vim aims to be a concise vim script that implements some of TextMate's snippets features in Vim.
www.vim.org/scripts/script.php?script_id=2540
2.01k stars 181 forks source link

adds support for snippet comments in completion text #277

Closed ditodidio closed 3 years ago

ditodidio commented 3 years ago

This little change adds comments support. The basic idea is, to have a really small snippet abbreviation as snippet trigger and a comment that describes the snippet further.

An example:

# xml schema element with complexType and simple content                                                              
snippet xsect                                              
    <xs:element name="${1}">                                                         
        <xs:complexType>                                                             
            <xs:simpleContent>                                                       
                <xs:extension base="${2}">                                           
                    ${0}                                                          
                </xs:extension>                                                      
            </xs:simpleContent>                                                      
        </xs:complexType>                                                            
    </xs:element> 

autocomplete menu shows:

xsect xml schema element with complexType and simple content

ajzafar commented 3 years ago

How is this an improvement over the already supported g:snipMate.description_in_completion option (see :h SnipMate-options for details) where the snippet is defined as follows?

snippet xsect xml schema element with complexType and simple content
    <xs:element name="${1}">
        <xs:complexType>
            <xs:simpleContent>
                <xs:extension base="${2}">
                    ${0}
                </xs:extension>
            </xs:simpleContent>
        </xs:complexType>
    </xs:element>
ditodidio commented 3 years ago

Yeah you are right. It is not. I did not notice the possibility to write it after the snippet name. Although I think, it makes more sense to seperate it from the snippet itsself. The folded snippet file is more readable this way and you can easily grab a list of all available snippet Comments without string manipulation of the snippet line. Maybe later it is possible to have space separated snippet names (if its not already possible). The file itsself gets larger with my approach. That maybe could result in a slower reading of the file. My approach is not activated by default though and it does not interfere with the current approach. There is not even a parsing speed impact if you have no comments in your current file. If you merge it in, the user can decide if he wants the description above or behind the snippet declaration.

ajzafar commented 3 years ago

I will not be merging this. Its main advantage overlaps with functionality already in SnipMate, it makes comments in snippets files meaningful, and it adds a little complexity to a codebase I've been meaning to refactor for years.

I do thank you for giving SnipMate your attention

ditodidio commented 3 years ago

Yeah, No Problem. You are the maintainer. I will keep my changes. I thought my approach is actually more "KISS". Maybe one day you will appreciate that.

By the way, there is a bug in the current version. I will report it later.