phpactor / ncm2-phpactor

NCM2 Integration for Phpactor
55 stars 6 forks source link

AttributeError: 'NoneType' object has no attribute 'group' #22

Closed elynnaie closed 1 year ago

elynnaie commented 5 years ago

I get the following error occasionally while writing in insert mode. [ncm2_phpactor@yarp] AttributeError: 'NoneType' object has no attribute 'group'

NVIM v0.3.5 phpactor 0.12.0 ncm2-phpactor 90e6b7dfcaabe767156086c6aa032e069e8c8874

For me, this is reproducible in my code base (but not a new file) when typing $model->parent on a new line. I would expect it to autocomplete to $model->parent_id or some such, but it does not and displays the error in vim's gutter instead.

I would be happy to provide any other information that would be useful.

dantleech commented 5 years ago

It might be useful if you could check the log for this request by following the instructions for enabling replay. This will allow you to replay the last invocation from the CLI and see the logs.

Otherwise it might be necessary to debug NCM2 itself.

dantleech commented 5 years ago

But I'm guessing the probem might be here:

            menu = e['short_description']
            word = e['name']
            t = e['type']

            item = dict(word=word, menu=menu, info=menu)

            # snippet support
            m = re.search(r'(\w+\s+)?\w+\((.*)\)', menu)

Perhaps menu is invalid. If you are familiar with Python you could also try debugging this to extract more information.

indeedhat commented 4 years ago

i am getting the same issue nvim v0.4.2 phpactor: 72bb79a ncm-phpactor 90e6b7dfcaabe767156086c6aa032e069e8c8874

for me the issue is triggering from ncm2_phpactor.py:90 I havnt found any real commonality between places that it is not working and places that are but one place i can always trigger it is with the gocardless/gocardless-pro-php package

use GoCardlessPro\Client;

$payments = (new Client())
    ->payments()
    ->|

Note: Doesn't seem to be anything to do with method chaining as that is working just fine in other places

it is not causing me enough grief to spend any real time on tracking down but i figured id post up the extra info just in case it helps anyone who is trying,

tweekmonster commented 2 years ago

@dantleech The issue appears to be functions with variable length arguments that follow an argument.

It's fine when a function signature is f($a), or f(...$a), or f($a, $b), but crashes when it's f($a, ...$b).

Working example (where | is the cursor):

/**
 * @method null testFunction($arg1, ...$arg2)
 */
class Test {};

$t = new Test();
$t->|

It causes phpactor to return this result:

{
  "type": "method",
  "name": "testFunction",
  "snippet": "testFunction(${1:\\$arg1,(})${0}",
  "label": "testFunction",
  "short_description": "pub testFunction($arg1,(): null",
  "documentation": "",
  "class_import": null,
  "name_import": null,
  "range": null,
  "info": "pub testFunction($arg1,(): null"
}

The issue is it being parsed as pub testFunction($arg1,(): null

It crashes on line 90 because it assumes that it'll match '\$\w+' when it encounters ( as a parameter.

https://github.com/phpactor/ncm2-phpactor/blob/90e6b7dfcaabe767156086c6aa032e069e8c8874/pythonx/ncm2_phpactor.py#L90

It also crashes when the function signature has extraneous commas in them, such as f($a,). When defaults are used in arguments, it parses similarly, but doesn't crash because $ is present in the parameters, but will prevent the remaining arguments from being included. For example: f($a='default', $b='default') will parse as f($a=()

I don't know enough about phpactor or this plugin, but this seems like a phpactor issue, though it's also not being guarded against in this plugin.

roxma commented 1 year ago

Thanks to @nacholibre https://github.com/phpactor/ncm2-phpactor/issues/22

This issue should be closed.