emacs-php / php-auto-yasnippets

Dynamically Generated YASnippets for PHP Code in GNU Emacs
GNU General Public License v3.0
41 stars 12 forks source link

`Wrong type argument: stringp, nil` while in class method #28

Open MarTango opened 7 years ago

MarTango commented 7 years ago

It looks like somehow, (thing-at-point 'sexp) is returning nil when I call (yas/create-php-snippet) inside a class method. If I bring the cursor out of the method, then the function works correctly. Is this a problem with thing-at-point or php-auto-yasnippets? (Calling (thing-at-point 'string) is also returning nil). I'm not sure.

Click for error. ``` Debugger entered--Lisp error: (wrong-type-argument stringp nil) string-match("[ \f \n ]+" nil 0) split-string(nil) payas/create-template(nil) payas/define-template(nil) yas/create-php-snippet(nil) funcall-interactively(yas/create-php-snippet nil) call-interactively(yas/create-php-snippet nil nil) command-execute(yas/create-php-snippet) ```
ejmr commented 7 years ago

Are you calling (yas/create-php-snippet) inside a method for a method call that's not the method you're currently inside? I.e. a different method? If so that's a bug with php-auto-yasnippets. If you're trying to call (yas/create-php-snippet) inside a method of the same name it's arguably probably a bug anyways too.

MarTango commented 7 years ago

This is the example that I tested. (| is my cursor position).

<?php

class MyClass
{
    public function __construct()
    {
        array_chunk|
    }
}
ejmr commented 7 years ago

That is one-hundred percent a bug due on the part of this package then.

MarTango commented 7 years ago

I don't quite understand how though. at [1], [2], [3], [4] and [5] below, evaluating (thing-at-point 'sexp) returns:

  1. nil
  2. nil
  3. #("array_chunk" 0 11 (fontified t))
  4. #("array_chunk" 0 11 (c-in-sws t fontified t face font-lock-doc-face))
  5. #("array_chunk" 0 11 (c-in-sws t fontified t face font-lock-comment-face))
<?php

class MyClass
{
    /**
     * @comment array_chunk[4]
     */
    public function hello() // array_chunk[5]
    {
        array_chunk[1]
    }
    array_chunk[2]
}
array_chunk[3]
ejmr commented 7 years ago

I half-wonder if the problems of instances 1 and 2 are not caused by bugs of my own in PHP Mode. Regardless, php-auto-yasnippets should be smarter about looking (backwards) at the current thing at point to see if whether or not it matches a known function or method it can expand.

chrissound commented 7 years ago

I get this same issue in a constructor of a object. So just new Classname(|) where | is my cursor.

ejmr commented 7 years ago

@chrissound Thank you for the additional info. I have to apologize because I am busy over this weekend and next week, so I won't be able to look into this again soon. But I will try to fix it when my personal life schedule allows me a big chunk of free time. Sorry again for the delay.

chrissound commented 7 years ago

@ejmr No need to apologize! Thank you for your effort and this plugin!