[gnome-builder] Improve snippets



commit 3c4926ad019b03115369c7012463999b5d41fded
Author: Ricardo Silva Veloso <ricvelozo gmail com>
Date:   Sat Jul 28 03:18:25 2018 -0300

    Improve snippets

 data/snippets/c.snippets        |  98 ++++++++++++-
 data/snippets/java.snippets     |  11 +-
 data/snippets/js.snippets       |  83 +++++++++++
 data/snippets/licenses.snippets |  18 +++
 data/snippets/python.snippets   |  26 ++++
 data/snippets/rust.snippets     | 299 +++++++++++++++++++++++++---------------
 data/snippets/vala.snippets     |   4 +-
 7 files changed, 416 insertions(+), 123 deletions(-)
---
diff --git a/data/snippets/c.snippets b/data/snippets/c.snippets
index d0b21e7d1..b5030007f 100644
--- a/data/snippets/c.snippets
+++ b/data/snippets/c.snippets
@@ -1,23 +1,113 @@
 snippet Widget
-- desc Quick definition for a GtkWidget local.
 - scope c, chdr
+- desc Quick definition for a GtkWidget local
        GtkWidget *
 snippet function_prefix
 - scope c, chdr
        ${$filename|stripsuffix|functify}_
-snippet forloop
+snippet struct
+- scope c, chdr
+       typedef struct
+       {
+           $0
+       } ${1:StructName};
+snippet union
+- scope c, chdr
+       typedef union
+       {
+           $0
+       } ${1:UnionName};
+snippet enum
+- scope c, chdr
+       typedef enum
+       {
+           $0
+       } ${1:EnumName};
+snippet fn
+- scope c, chdr
+- desc Create function
+       ${1:void}
+       ${2:function_name} (${3:void})
+       {
+           $0
+       }
+snippet fns
+- scope c, chdr
+- desc Create function signature
+       ${1:void}
+       ${2:function_name} (${3:void});$0
+snippet if
+- scope c, chdr
+       if (${1:condition})
+         {
+           $0
+         }
+snippet else
+- scope c, chdr
+       else
+         {
+           $0
+         }
+snippet elseif
+- scope c, chdr
+- desc else if
+       else if (${1:condition})
+         {
+           $0
+         }
+snippet switch
+- scope c, chdr
+       switch (${1:expression})
+         {
+         case ${2:value}:
+           $0
+           break;
+         }
+snippet case
+- scope c, chdr
+       case ${1:value}:
+         $0
+         break;
+snippet default
+- scope c, chdr
+       default:
+         $0
+         break;
+snippet while
+- scope c, chdr
+       while (${1:condition})
+         {
+           $0
+         }
+snippet for
 - scope c, chdr
        for (${1:i = 0}; ${2:i < }; ${3:i++})
          {
            $0
          }
+snippet var
+- scope c, chdr
+- desc Create variable
+       ${1:type} ${2:variable} = ${3:expression};$0
+snippet printf
+- scope c, chdr
+- desc printf(…)
+       printf("${1:%s\\n}", ${2:expression});$0
+snippet eprintf
+- scope c, chdr
+- desc eprintf(…)
+       eprintf("${1:%s\\n}", ${2:expression});$0
+snippet scanf
+- scope c, chdr
+- desc scanf(…)
+       scanf("${1:%d}", ${2:variable});$0
 snippet include
 - scope c, chdr
-- desc Include a file relative to the file or configured include paths.
+- desc Include a file relative to the file or configured include paths
        #include "${1}"$0
 snippet Include
 - scope c, chdr
-- desc Include a file from the global include path.
+- desc Include a file from the global include path
        #include <${1}>$0
 snippet Classname
 - scope c, chdr
diff --git a/data/snippets/java.snippets b/data/snippets/java.snippets
index c7329ee58..2ef738b88 100644
--- a/data/snippets/java.snippets
+++ b/data/snippets/java.snippets
@@ -1,5 +1,5 @@
 snippet clas
-- desc Creates a java class definition
+- desc Create class definition
 - scope java, groovy
        package ${$relative_dirname|descend_path|descend_path|descend_path|slash_to_dots};
        
@@ -8,7 +8,7 @@ snippet clas
            $0
          }
 snippet iface
-- desc Creates a java interface definition
+- desc Create interface definition
 - scope java, groovy
        package ${$relative_dirname|descend_path|descend_path|descend_path|slash_to_dots};
        
@@ -24,21 +24,21 @@ snippet psvm
            $0
          }
 snippet itar
-- desc Creates a for loop
+- desc Create a for loop
 - scope java, groovy
        for (int ${1:i = 0}; ${2:i < }; ${3:i++})
          {
            $0
          }
 snippet iter
-- desc Creates a for each loop on a collection
+- desc Create a for each loop on a collection
 - scope java, groovy
        for (${2:type} ${3:var}: ${1:collection})
          {
            $0
          }
 snippet itit
-- desc Creates a for loop on an iterator
+- desc Create a for loop on an iterator
 - scope java, groovy
        while (${1:it}.hasNext())
          {
@@ -61,4 +61,3 @@ snippet sout
 snippet serr
 - scope java
        System.err.println($0);
-
diff --git a/data/snippets/js.snippets b/data/snippets/js.snippets
index 0829be202..734395a27 100644
--- a/data/snippets/js.snippets
+++ b/data/snippets/js.snippets
@@ -7,6 +7,9 @@ snippet lang
 snippet import
        const ${1:ModuleName} = imports.${2:path}.${$1|decapitalize};
        $0
+snippet require
+       const ${1:ModuleName} = require("${$1|lower}");
+       $0
 snippet class
        const ${1:ClassName} = new Lang.Class({
                Name: '$1',
@@ -35,3 +38,83 @@ snippet gproperty
                $0),
 snippet gsignal
        '${1:signal}': {$0},
+snippet function
+       function ${1:name}(${2}) {
+               $0
+       }
+snippet arrow
+- desc Create arrow function
+       (${1}) => {
+               $0
+       }
+snippet if
+       if (${1:condition}) {
+               $0
+       }
+snippet else
+       else {
+               $0
+       }
+snippet elseif
+- desc else if
+       else if (${1:condition}) {
+               $0
+       }
+snippet switch
+       switch (${1:expression}) {
+               case ${2:value}:
+                       $0
+                       break;
+       }
+snippet case
+       case ${1:value}:
+               $0
+               break;
+snippet default
+       default:
+               $0
+               break;
+snippet while
+       while (${1:condition}) {
+               $0
+       }
+snippet for
+       for (${1:let i = 0}; ${2:i < }; ${3:i++}) {
+               $0
+       }
+snippet forin
+- desc for … in
+       for (${1:let item} in ${2:enumerable}) {
+               $0
+       }
+snippet forof
+- desc for … of
+       for (${1:let item} of ${2:iterable}) {
+               $0
+       }
+snippet try
+       try {
+               $0
+       }
+snippet catch
+       catch (${1:e}) {
+               $0
+       }
+snippet finally
+       finally {
+               $0
+       }
+snippet const
+       const ${1:variable} = ${2:expression};$0
+snippet let
+       let ${1:variable} = ${2:expression};$0
+snippet var
+       var ${1:variable} = ${2:expression};$0
+snippet log
+       console.log("${1:message}");$0
+snippet error
+       console.error("${1:message}");$0
+snippet info
+       console.info("${1:message}");$0
+snippet warn
+       console.warn("${1:message}");$0
diff --git a/data/snippets/licenses.snippets b/data/snippets/licenses.snippets
index 36df20c3b..3e0a0ea7a 100644
--- a/data/snippets/licenses.snippets
+++ b/data/snippets/licenses.snippets
@@ -18,6 +18,7 @@ snippet apache
         *
         * SPDX-License-Identifier: Apache-2.0
         */
+
        $0
 - scope python, python3
        # ${1:$filename}
@@ -37,6 +38,7 @@ snippet apache
        # limitations under the License.
        #
        # SPDX-License-Identifier: Apache-2.0
+
        $0
 - scope c-sharp, rust
        // ${1:$filename}
@@ -56,6 +58,7 @@ snippet apache
        // limitations under the License.
        //
        // SPDX-License-Identifier: Apache-2.0
+
        $0
 snippet gpl
 - scope c, chdr, cpp, css, js, vala, java
@@ -78,6 +81,7 @@ snippet gpl
         *
         * SPDX-License-Identifier: GPL-3.0-or-later
         */
+
        $0
 - scope python, python3
        # ${1:$filename}
@@ -98,6 +102,7 @@ snippet gpl
        # along with this program.  If not, see <http://www.gnu.org/licenses/>.
        #
        # SPDX-License-Identifier: GPL-3.0-or-later
+
        $0
 - scope c-sharp, rust
        // ${1:$filename}
@@ -118,6 +123,7 @@ snippet gpl
        // along with this program.  If not, see <http://www.gnu.org/licenses/>.
        //
        // SPDX-License-Identifier: GPL-3.0-or-later
+
        $0
 snippet lgpl
 - scope c, chdr, cpp, css, js, vala, java
@@ -140,6 +146,7 @@ snippet lgpl
         *
         * SPDX-License-Identifier: LGPL-3.0-or-later
         */
+
        $0
 - scope python, python3
        # ${1:$filename}
@@ -160,6 +167,7 @@ snippet lgpl
        # License along with this program.  If not, see <http://www.gnu.org/licenses/>.
        #
        # SPDX-License-Identifier: LGPL-3.0-or-later
+
        $0
 - scope c-sharp, rust
        // ${1:$filename}
@@ -180,6 +188,7 @@ snippet lgpl
        // License along with this program.  If not, see <http://www.gnu.org/licenses/>.
        //
        // SPDX-License-Identifier: LGPL-3.0-or-later
+
        $0
 snippet mit
 - scope c, chdr, cpp, css, js, vala, java
@@ -207,6 +216,7 @@ snippet mit
         *
         * SPDX-License-Identifier: MIT
         */
+
        $0
 - scope c-sharp, rust
        // ${1:$filename}
@@ -232,6 +242,7 @@ snippet mit
        // IN THE SOFTWARE.
        //
        // SPDX-License-Identifier: MIT
+
        $0
 - scope python, python3
        # ${1:$filename}
@@ -257,9 +268,11 @@ snippet mit
        # IN THE SOFTWARE.
        #
        # SPDX-License-Identifier: MIT
+
        $0
 snippet mitapache
 - scope c, chdr, cpp, css, js, vala, java
+- desc MIT OR Apache
        /* ${1:$filename}
         *
         * Copyright $year ${2:$fullname} <${3:$email}>
@@ -272,8 +285,10 @@ snippet mitapache
         *
         * SPDX-License-Identifier: (MIT OR Apache-2.0)
         */
+
        $0
 - scope python, python3
+- desc MIT OR Apache
        # ${1:$filename}
        #
        # Copyright $year ${2:$fullname} <${3:$email}>
@@ -285,8 +300,10 @@ snippet mitapache
        # except according to those terms.
        #
        # SPDX-License-Identifier: (MIT OR Apache-2.0)
+
        $0
 - scope c-sharp, rust
+- desc MIT OR Apache
        // ${1:$filename}
        //
        // Copyright $year ${2:$fullname} <${3:$email}>
@@ -298,4 +315,5 @@ snippet mitapache
        // except according to those terms.
        //
        // SPDX-License-Identifier: (MIT OR Apache-2.0)
+
        $0
diff --git a/data/snippets/python.snippets b/data/snippets/python.snippets
index 0a2ad78a4..31630baa7 100644
--- a/data/snippets/python.snippets
+++ b/data/snippets/python.snippets
@@ -21,6 +21,32 @@ snippet class
                        ${4:pass}
        
        $0
+snippet if
+       if ${1:condition}:
+               $0
+snippet else
+       else:
+               $0
+snippet elif
+       elif ${1:condition}:
+               $0
+snippet while
+       while ${1:condition}:
+               $0
+snippet for
+       for ${1:item} in ${2:collection}:
+               $0
+snippet try
+       try:
+               $0
+snippet except
+       except ${1:Exception}:
+               $0
+snippet finally
+       finally:
+               $0
+snippet lambda
+       lambda ${1:name}: $0
 snippet gobject
 - scope python
        class ${1:ClassName}(${2:GObject.Object}):
diff --git a/data/snippets/rust.snippets b/data/snippets/rust.snippets
index 9f32de6bc..96dc80a4e 100644
--- a/data/snippets/rust.snippets
+++ b/data/snippets/rust.snippets
@@ -1,197 +1,274 @@
 snippet allow
-- scope rust
-       #[allow(${1:lint})]$0
-
+- desc #[allow(…)]
+       #[allow(${1:lint})]
+       $0
 snippet deny
-- scope rust
-       #[deny(${1:lint})]$0
-
+- desc #[deny(…)]
+       #[deny(${1:lint})]
+       $0
 snippet forbid
-- scope rust
-       #[forbid(${1:lint})]$0
-
+- desc #[forbid(…)]
+       #[forbid(${1:lint})]
+       $0
 snippet warn
-- scope rust
-       #[warn(${1:lint})]$0
-
+- desc #[warn(…)]
+       #[warn(${1:lint})]
+       $0
 snippet deprecated
-- scope rust
-       #[deprecated(since = "${1:version}", note = "${2:note}")]$0
-
+- desc #[deprecated(…)]
+       #[deprecated(since = "${1:version}", note = "${2:reason}")]
+       $0
+snippet must_use
+- desc #[must_use]
+       #[must_use]
+       $0
+snippet should_panic
+- desc #[should_panic(…)]
+       #[should_panic(expected = "${1:reason}")]
+       $0
 snippet cfg
-- scope rust
-       #[cfg(${1:key} = "${2:value}")]$0
-
+- desc #[cfg(…)]
+       #[cfg(${1:expression})]
+       $0
 snippet derive
-- scope rust
-       #[derive(${1:Trait})]$0
-
+- desc #[derive(…)]
+       #[derive(${1:Debug})]
+       $0
+snippet repr
+- desc #[repr(…)]
+       #[repr(${1:C})]
+       $0
+snippet link
+- desc #[link(…)]
+       #[link(name = "${1:library}")]
+       $0
+snippet no_mangle
+- desc #[no_mangle]
+       #[no_mangle]
+       $0
+snippet inline
+- desc #[inline]
+       #[inline]
+       $0
 snippet struct
-- scope rust
        struct ${1:StructName} {
            $0
        }
-
+snippet tuple
+- desc Create tuple struct
+       struct ${1:TupleName}(${2:i32});$0
+snippet unit
+- desc Create unit-like struct
+       struct ${1:StructName};$0
 snippet union
-- scope rust
        #[repr(C)]
        union ${1:UnionName} {
            $0
        }
-
 snippet enum
-- scope rust
        enum ${1:EnumName} {
            $0
        }
-
 snippet trait
-- scope rust
        trait ${1:TraitName} {
            $0
        }
-
 snippet impl
-- scope rust
-       impl ${1:StructName} {
+       impl ${1:Type} {
+           $0
+       }
+snippet impltrait
+- desc Implement trait
+       impl ${1:Trait} for ${2:Type} {
+           $0
+       }
+snippet default
+- desc Implement Default trait
+       impl Default for ${1:Type} {
+           fn default() -> Self {
+               $0
+           }
+       }
+snippet drop
+- desc Implement Drop trait
+       impl Drop for ${1:Type} {
+           fn drop(&mut self) {
+               $0
+           }
+       }
+snippet constructor
+- desc Create a constructor
+       #[inline]
+       pub fn ${1:new}(${2}) -> Self {
+           Self {}$0
+       }
+snippet builder
+- desc Create a builder
+       struct ${1:Struct}Builder {
            $0
        }
 
+       impl $1Builder {
+           #[inline]
+           pub fn new() -> Self {
+               Self {}
+           }
+
+           pub fn build(&self) -> $1 {
+               unimplemented!()
+           }
+       }
 snippet fn
-- scope rust
-       fn ${1:function_name}(${2:&self}) {
-           ${3:unimplemented!()}
+       fn ${1:function_name}(${2:&mut self}) {
+           unimplemented!()$0
        }
-
 snippet fnr
-- scope rust
-       fn ${1:function_name}(${2:&self}) -> ${3:TypeName} {
-           ${4:unimplemented!()}
+- desc Create function with return
+       fn ${1:function_name}(${2:&mut self}) -> ${3:&mut Self} {
+           unimplemented!()$0
        }
-
 snippet fns
-- scope rust
-       fn ${1:function_name}(${2:&self});$0
-
+- desc Create function signature
+       fn ${1:function_name}(${2:&mut self});$0
 snippet fnrs
-- scope rust
-       fn ${1:function_name}(${2:&self}) -> ${3:TypeName};$0
-
-snippet macro
-- scope rust
-       macro_rules! ${1:macro_name} {
-           ( ${2:expression} ) => {
-               $0
-           };
+- desc Create function signature with return
+       fn ${1:function_name}(${2:&mut self}) -> ${3:&mut Self};$0
+snippet closure
+- desc Create closure
+       |${1}| {
+           $0
        }
-
-snippet unsafe
-- scope rust
-       unsafe {
+snippet move
+- desc Create move closure
+       move |${1}| {
            $0
        }
-
-snippet loop
-- scope rust
-       loop {
+snippet match
+       match ${1:expression} {
            $0
        }
-
-snippet for
-- scope rust
-       for ${1:variable} in ${2:iterator}.iter() {
+snippet option
+- desc Pattern matching for Option
+       match ${1:expression} {
+           None => ${2},
+           Some(${3:val}) => ${4},
+       }$0
+snippet result
+- desc Pattern matching for Result
+       match ${1:expression} {
+           Ok(${2:val}) => ${3},
+           Err(${4:err}) => ${5},
+       }$0
+snippet if
+       if ${1:condition} {
+           $0
+       }
+snippet else
+       else {
+           $0
+       }
+snippet elseif
+- desc else if
+       else if ${1:condition} {
+           $0
+       }
+snippet iflet
+- desc if let
+       if let ${1:Some(val)} = ${2:expression} {
            $0
        }
-
 snippet while
-- scope rust
-       while ${1:expression} {
+       while ${1:condition} {
            $0
        }
-
-snippet if
-- scope rust
-       if ${1:expression} {
+snippet whilelet
+- desc while let
+       while let ${1:Some(val)} = ${2:expression} {
            $0
        }
-
-snippet match
-- scope rust
-       match ${1:expression} {
+snippet for
+       for ${1:item} in ${2:collection}.iter() {
+           $0
+       }
+snippet loop
+       loop {
+           $0
+       }
+snippet unsafe
+       unsafe {
+           $0
+       }
+snippet extern
+       extern {
            $0
        }
-
 snippet const
-- scope rust
        const ${1:CONST_NAME}: ${2:type} = ${3:expression};$0
-
 snippet static
-- scope rust
        static ${1:STATIC_NAME}: ${2:type} = ${3:expression};$0
-
 snippet let
-- scope rust
        let ${1:variable} = ${2:expression};$0
-
 snippet type
-- scope rust
-       type ${1:AliasName} = ${2:TypeName};$0
-
-snippet fmt
-- scope rust
+       type ${1:Alias} = ${2:Type};$0
+snippet vec
+- desc vec![…]
+       vec![${1:expression}; ${2:size}];$0
+snippet format_args
+- desc format_args!(…)
+       format_args!("${1:{}}", ${2:expression})$0
+snippet format
+- desc format!(…)
        format!("${1:{}}", ${2:expression})$0
-
 snippet write
-- scope rust
+- desc write!(…)
        write!(${1:buffer}, "${2:{}}", ${3:expression});$0
-
 snippet writeln
-- scope rust
+- desc writeln!(…)
        writeln!(${1:buffer}, "${2:{}}", ${3:expression});$0
-
 snippet print
-- scope rust
+- desc print!(…)
        print!("${1:{}}", ${2:expression});$0
-
 snippet println
-- scope rust
+- desc println!(…)
        println!("${1:{}}", ${2:expression});$0
-
 snippet eprint
-- scope rust
+- desc eprint!(…)
        eprint!("${1:{}}", ${2:expression});$0
-
 snippet eprintln
-- scope rust
+- desc eprintln!(…)
        eprintln!("${1:{}}", ${2:expression});$0
-
+snippet panic
+- desc panic!(…)
+       panic!("${1:{}}", ${2:expression});$0
+snippet unreachable
+- desc unreachable!(…)
+       unreachable!("${1:reason}")$0
+snippet unimplemented
+- desc unimplemented!(…)
+       unimplemented!()$0
 snippet assert
-- scope rust
+- desc assert!(…)
        assert!(${1:expression});$0
-
 snippet assert_eq
-- scope rust
+- desc assert_eq!(…)
        assert_eq!(${1:expression1}, ${2:expression2});$0
-
 snippet assert_ne
-- scope rust
+- desc assert_ne!(…)
        assert_ne!(${1:expression1}, ${2:expression2});$0
-
-snippet testmod
-- scope rust
+snippet testsmod
+- desc Create tests module
        #[cfg(test)]
        mod tests {
            use super::*;
 
            #[test]
            fn ${1:function_name}() {
-               ${2:unimplemented!()}
+               unimplemented!()$0
            }
        }
-
 snippet test
-- scope rust
+- desc Create test
        #[test]
        fn ${1:function_name}() {
-           ${2:unimplemented!()}
+           unimplemented!()$0
        }
diff --git a/data/snippets/vala.snippets b/data/snippets/vala.snippets
index e096f2e5e..1d80baf5d 100644
--- a/data/snippets/vala.snippets
+++ b/data/snippets/vala.snippets
@@ -1,6 +1,6 @@
 snippet class
 - scope vala
-- desc Create Class
+- desc Create class
        class ${1:$filename|stripsuffix|camelize} : ${2:Object} {
                public $1 () {
                        $0
@@ -14,7 +14,7 @@ snippet comment
         */
 snippet async
 - scope vala
-- desc call an async function
+- desc Call an async function
        ${1:func}.begin (${2:args, }(obj, res) => {
                ${3:var result = }$1.end (res);$0
        });


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]