php-auto-yasnippets icon indicating copy to clipboard operation
php-auto-yasnippets copied to clipboard

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

Open MarTango opened this issue 7 years ago • 8 comments

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)

MarTango avatar Mar 31 '17 17:03 MarTango

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.

ejmr avatar Mar 31 '17 17:03 ejmr

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

<?php

class MyClass
{
    public function __construct()
    {
        array_chunk|
    }
}

MarTango avatar Mar 31 '17 18:03 MarTango

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

ejmr avatar Mar 31 '17 18:03 ejmr

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]

MarTango avatar Mar 31 '17 19:03 MarTango

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.

ejmr avatar Apr 02 '17 06:04 ejmr

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

chrissound avatar May 23 '17 13:05 chrissound

@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.

ejmr avatar May 26 '17 00:05 ejmr

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

chrissound avatar May 26 '17 10:05 chrissound