Why is this snippets.cson not working?


#1

Hey guys, I’m just trying to add some snippets form https://github.com/paulredmond/atom-larasnippets/tree/master/snippets

so my snippets.cson looks like

# Your snippets
#
# Atom snippets allow you to enter a simple prefix in the editor and hit tab to
# expand the prefix into a larger code block with templated values.
#
# You can create a new snippet in this file by typing "snip" and then hitting
# tab.
#
# An example CoffeeScript snippet to expand log to console.log:
#
# '.source.coffee':
#   'Console log':
#     'prefix': 'log'
#     'body': 'console.log $1'
#
# Each scope (e.g. '.source.coffee' above) can only be declared once.
#
# This file uses CoffeeScript Object Notation (CSON).
# If you are unfamiliar with CSON, you can read more about it in the
# Atom Flight Manual:
# https://atom.io/docs/latest/using-atom-basic-customization#cson

'.source.sass, .source.css.sass, .source.scss, .source.less':
  'box-shadow':
    'prefix': 'boxs'
    'body': 'box-shadow:'

'.text.html':
  'Basic Placeholder Image':
    'prefix': 'placeholder'
    'body': '<img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=${3}&w=${1}&h=${2}" alt="Decorative Image" aria-hidden="true" role="presentation" />${5}'

'.php':
  'Basic Decorative Image':
    'prefix': 'ariaalt'
    'body': 'alt="decorative image" role="presentation" aria-hidden="true"'
  'Crud Field':
    'prefix': 'crudfield'
    'body': '$this->crud->addField([\n    \'name\'  => \'${1}\',\n    \'label\' => \'${2}\',\n    \'type\'  => \'${3}\'\n]);${4}'
  'Crud Column':
    'prefix': 'crudcolumn'
    'body': '$this->crud->addColumn([\n    \'name\'  => \'${1}\',\n    \'label\' => \'${2}\',\n    \'type\'  => \'${3}\'\n]);${4}'

'.source.php':
    'Laravel Test Case':
        'prefix': 'testcase'
        'body': """
            use Illuminate\\\\Foundation\\\\Testing\\\\WithoutMiddleware;
            use Illuminate\\\\Foundation\\\\Testing\\\\DatabaseMigrations;
            use Illuminate\\\\Foundation\\\\Testing\\\\DatabaseTransactions;

            class $1Test extends TestCase
            {
                $2
            }
        """
    'PHP Unit Test':
        'prefix': 'test'
        'body': """
            /** @test */
            function $1()
            {
                $2
            }
        """

'.source.php':

    'Route':
        'prefix': 'route'
        'body': """
            Route::$1('$2', '$3Controller@$4');
        """

    'Route Group':
        'prefix': 'route:group'
        'body': """
            Route::group([
                $1
            ], function () {
                $2
            });
        """

'.source.php':

    '"Has One" Relationship':
        'prefix': 'hasone'
        'body': """
            public function $1()
            {
                return $this->hasOne($2::class);
            }
        """

    '"Has Many" Relationship':
        'prefix': 'hasmany'
        'body': """
            public function $1()
            {
                return $this->hasMany($2::class);
            }
        """

    '"Belongs To" Relationship':
        'prefix': 'belongsto'
        'body': """
            public function $1()
            {
                return $this->belongsTo($2::class);
            }
        """

    '"Belongs To Many" Relationship':
        'prefix': 'btm'
        'body': """
            public function $1()
            {
                return $this->belongsToMany($2::class);
            }
        """

    '"Has Many Through" Relationship':
        'prefix': 'hasmanythrough'
        'body': """
            public function $1()
            {
                return $this->hasManyThrough($2::class, $3::class);
            }
        """

    'Polymorphism: Morph To':
        'prefix': 'morphto'
        'body': """
            public function $1()
            {
                return $this->morphTo();
            }
        """

    'Polymorphism: Morph Many':
        'prefix': 'morph'
        'body': """
            public function $1()
            {
                return $this->morphMany($2::class, '${3:commentable}');
            }
        """

    'Polymorphism: Morph Many (Long Prefix)':
        'prefix': 'morphmany'
        'body': """
            public function $1()
            {
                return $this->morphMany($2::class, '${3:commentable}');
            }
        """

'.source.php':

    'Laravel Factory Definition':
        'prefix': 'factory'
        'body': """
            $factory->define(App\\\\$1::class, function (Faker\\\\Generator $faker) {
                return [
                    $2
                ];
            });
        """

    'Laravel Factory State Definition':
        'prefix': 'factory:state'
        'body': """
            $factory->state(App\\\\$1::class, '${2:state}', function (Faker\\\\Generator $faker) {
                return [
                    $3
                ];
            });
        """

'.source.php':

    'Validation in the controller':
        'prefix': 'validate'
        'body': """
            $this->validate(request(), [
                $1
            ]);
        """

    'Json Response':
        'prefix': 'rjson'
        'body': """
            response()->json($1);
        """

    'View With':
        'prefix': 'vieww'
        'body': """
            view('$1')${2:->with([$3])};
        """

    'View':
        'prefix': 'view'
        'body': """
            view('$1', [$2]);
        """

However when I’m in a php file and type something like testcase and hit tab, it just does nothing, anybody got any suggestions how to debug the issue or spot why it might not be working?

Cheers


#2

I think the PHP grammar scope is text.html.php:

http://take.ms/zhxiP

Can you update the language scope and try again? E.g.:

'.text.html.php':
    'Laravel Test Case':
        'prefix': 'testcase'
        'body': """
            use Illuminate\\\\Foundation\\\\Testing\\\\WithoutMiddleware;
            use Illuminate\\\\Foundation\\\\Testing\\\\DatabaseMigrations;
            use Illuminate\\\\Foundation\\\\Testing\\\\DatabaseTransactions;

            class $1Test extends TestCase
            {
                $2
            }
        """

#3

@rsese source.php is correct in this case - PHP is a bit different with how it handles scopes (text.html.php is used for the regular HTML, and source.php is used for the actual PHP).

@OwenMelbz I believe your problem is that you’re specifying source.php multiple times. When you do that, only the last source.php block is added. You may want to read http://flight-manual.atom.io/using-atom/sections/basic-customization/#configuring-with-cson for more information.


#4

Thanks for clearing that up @Wliu :bow: