Git Product home page Git Product logo

ncm2-phpactor's Introduction

phpactor integration for ncm2

phpactor

Installation

Assuming you're using vim-plug

" Include Phpactor
Plug 'phpactor/phpactor' ,  {'do': 'composer install', 'for': 'php'}

" Require ncm2 and this plugin
Plug 'ncm2/ncm2'
Plug 'roxma/nvim-yarp'
Plug 'phpactor/ncm2-phpactor'

Additionally you will need to set the following options:

autocmd BufEnter * call ncm2#enable_for_buffer()
set completeopt=noinsert,menuone,noselect

ncm2-phpactor's People

Contributors

dantleech avatar filipekiss avatar jessarcher avatar nacholibre avatar roxma avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ncm2-phpactor's Issues

Composer and git only found when opening a file directly

I can get ncm2-phpactor to work only when I open a file directly from the command line, e.g.: nvim ~/Projects//src/Controller/SomeController.php

If i open nvim in ~/Project/ and use NERDTree to open a file, composer and git are not found and completion does not function as expected.

Is there something I can do to fix this? Thanks,

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

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 90e6b7d

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.

How to get import auto completion?

When I am writing a use statement I am getting a lot of suggestions from cwd with no useful class path suggestions, like this:

screenshot from 2019-01-23 17-14-42

What I would expect is a list of next possible class path components - not files from my cwd.

If I start to write the class name (without the path) in the use statement i get this:

screenshot from 2019-01-23 17-12-24

so I know that the class names are recognized, however I don't know any means of inserting the displayed path.

Is there a way to get class path components suggested while writing?
Is there a way to insert the class path from the list seen in the second screenshot?

The `$` is doubled when autocompleting variables

If I search a variable after typing as $ (so $ + C-n), for a $foo variable, I end up with a $$foo instead of expected $foo.

Not sure if it's phpactor or ncm, but I think it's form the plugin, as I didn't have the issue with deoplete.

Automatic class import.

The current develop branch for Phpactor now supports automatically importing classes upon completion with OmniComplete.

recording

Would be great to implement this in NCM2 also.

The suggestion format now looks like:

{
    "type":"class",
    "name":"ProcessUtilsTest",
    "short_description":"Symfony\\Component\\Process\\Tests\\ProcessUtilsTest",
    "class_import":"Symfony\\Component\\Process\\Tests\\ProcessUtilsTest",
}

Where class_import is non-empty it can call the import_class RPC method.

Different class list than the omnifunc

When I compare the list of classes I get with ncm2-phpactor and phpactor's omnifunc class list, I very clearly see different lists. Even stranger, if I trigger the omni func, close the menu, and go back into insert mode to get ncm2 to open up, I see the classes from omnifunc; however, that only happens sometimes (but I was unable to reproduce when creating this issue).

I think screenshots will illustrate this best:

ncm2 completion:
image

omnifunc:
image

Exception thrown

Sometimes I get this error when working in a php file and it prevents you from working. This never happened before. I saw this for the first time today after I did :call dein#update()

[ncm2_phpactor@yarp] error caught in notification handler 'on_complete [{'filepath': '/Users/juju/Projects/PHP/knights/app/Http/Controllers/BalanceController.php', 'typed': '        dd($', 'scope_match': 'php', 'startccol': 12, 'scope_level': 1, 'word_pattern': '[\\$\\w][\\w]*', 'time': 1544893109.6483479, 'lnum': 71, 'bufnr': 14, 'changedtick': 148, 'manual': 0, 'base': '$', 'ccol': 13, 'filetype': 'php', 'curpos': [0, 71, 13, 0, 13], 'tick': [[0, 71, 13], 14], 'early_cache': False, 'context_id': 1298, 'scope': 'php', 'matcher': {'name': 'abbrfuzzy'}, 'source': {'on_complete': 'ncm2_phpactor#on_complete', 'subscope_enable': 1, 'early_cache': 0, 'name': 'phpactor', 'scope': ['php'], 'mark': 'b', 'on_warmup': 'ncm2_phpactor#on_warmup', 'ready': 1, 'enable': 1, 'auto_popup': 1, 'priority': 9, 'complete_pattern': ['\\$', '-\\>', '::'], 'word_pattern': '[\\$\\w][\\w]*'}, 'bcol': 13, 'match_end': 12}, ['<?php', '', 'namespace App\\Http\\Controllers;', '', 'use App\\Http\\Controllers\\Controller;', 'use Illuminate\\Http\\Request;', 'use Spatie\\QueryBuilder\\QueryBuilder;', '', 'use App\\Balance;', 'use App\\Office;', 'use App\\Merchant;', 'use App\\Product;', '', 'use App\\Http\\Requests\\Balances\\StoreBalance;', 'use App\\Http\\Requests\\Balances\\UpdateBalance;', 'use App\\Http\\Requests\\Balances\\RemoveBalance;', '', 'class BalanceController extends Controller', '{', '    /**', '     * Create a new controller instance.', '     *', '     * @return void', '     */', '    public function __construct()', '    {', "        $this->middleware(['auth', 'user.id']);", "        $this->middleware('permission:view_balance', ['only' => ['index', 'list']]);", "        $this->middleware('permission:create_balance|create_transaction', ['only' => ['create']]);", "        $this->middleware('permission:update_balance', ['only' => ['update']]);", "        $this->middleware('permission:destroy_balance', ['only' => ['destroy']]);", '    }', '', '    public function index()', '    {', "        return view('balances.index');", '    }', '', '    public function list(Request $request)', '    {', '        return QueryBuilder::for(Balance::class)', "            ->LeftJoin('products', 'balances.product_id', 'products.id')", "            ->LeftJoin('merchants', 'balances.merchant_id', 'merchants.id')", "            ->LeftJoin('offices', 'balances.office_id', 'offices.id')", "            ->selectRaw('balances.*, merchants.name as merchant_name, offices.name as office_name, offices.phone as office_phone, merchants.phone as merchant_phone, products.name as product_name, products.amount_limit as amount_limit')", '            ->allowedFilters(', "                'balance',", "                'balances.id',", "                'expiry_date',", "                'products.amount_limit',", "                'balances.car_limit',", "                'products.name',", "                'balances.note',", "                'products.name',", "                'merchants.name',", "                'offices.name'", '            )', "            ->orderBy('id', 'desc')", '            ->jsonPaginate();', '    }', '', '', '    /**', '     * Create a new _balance instance after a valid registration.', '     *', '     * @param  array  $data', '     * @return \\App\\Balance', '     */', '    protected function create(StoreBalance $request)', '    {', '        dd($)', "        $product = Product::where(['name' =>$request->product_name])->firstOrFail();", '', "        $merchant_id = merchant::where(['name' =>$request->merchant_name])->firstOrFail()->id;", '', "        $office_id = office::where(['name' =>$request->office_name])->firstOrFail()->id;", '', "        if($product->requiresCarBalance() && !$request->filled('car_limit'))", "            return ezReturnErrorMessage('Number of cars is required!');", '', '        $balance = Balance::create(array_merge($request->input(), [', "            'product_id' => $product->id,", "            'office_id' => $office_id,", "            'merchant_id' => $merchant_id", '        ]));', '', "        return ezReturnSuccessMessage('Balance created successfully!', $balance);", '    }', '', '    public function update(UpdateBalance $request)', '    {', '        $Balance = Balance::findOrFail($request->id);', '', '        $Balance->update($request->input());', '', "        return ezReturnSuccessMessage('Balance updated successfully!');", '    }', '', '    public function destroy(Request $request)', '    {', '', '        $Balance = Balance::findOrFail($request->id);', '', '        $Balance->delete();', '', "        return ezReturnSuccessMessage('Balance removed successfully!');", '', '    }', '', '    public function productBalance(Request $request){', '', "        if(!$request->filled('product_name'))", '            return;', '', '        $balanceInfo = [', "            'product_requires_balance' =>null,", "            'rows' => []", '        ];', '', '        //Data template', "        //[{name:'n11',value:'v12',editor:'text',group:'Product Information'}]", '', "        $product = Product::where(['name' =>$request->product_name])->first();", '', '        if($product == null)', '            return $balanceInfo;', '', "        $balanceInfo['product_requires_balance'] = $product->requiresBalance();", '', '        $this->setProductInformation($product, $balanceInfo);', '        $this->setCheckTypeInformation($product, $balanceInfo);', '        return $balanceInfo;', '', '    }', '', '    function setProductInformation($product, &$balanceInfo)', '    {', '        if($product->requiresBalance())', '        {', "            $balanceInfo['product'] = $product;", "            $balanceInfo['merchant'] = $product->requiresBalance();", "            array_push($balanceInfo['rows'], ['name'=>'Name','value'=>$product->name,'group'=>'Product Information']);", '            array_push($balanceInfo[\'rows\'], [\'name\'=>\'Requires Balance\',\'value\'=>\'<span style="color:red; font-weight:bold;">Yes</span>\',\'group\'=>\'Product Information\']);', '', "            array_push($balanceInfo['rows'],", '                [', "                    'name'=>'Has Amount Limit',", "                    'value'=> $product->requiresAmountBalance() ? 'Yes' : 'No',", "                    'group'=>'Product Information'", '                ]);', '', "            array_push($balanceInfo['rows'],", '                [', "                    'name'=>'Has Car Limit',", "                    'value'=> $product->requiresCarBalance() ? 'Yes' : 'No',", "                    'group'=>'Product Information'", '                ]);', '', '            if($product->amount_limit != null){', "                array_push($balanceInfo['rows'],", '                    [', "                        'name'=>'Amount Limit',", "                        'value'=>$product->amount_limit . ' ' . $product->amount_limit_unit . '(s)',", "                        'group'=>'Product Information'", '                    ]);', '            }', '', '            if($product->date_limit != null){', "                array_push($balanceInfo['rows'],", '                    [', "                        'name'=>'Day Limit',", "                        'value'=>'Expires in '.$product->date_limit. ' days',", "                        'group'=>'Product Information'", '                    ]);', '            }', '        }', '        else {', "            array_push($balanceInfo['rows'],", '                [', "                    'name'=>'Requires Balance',", "                    'value'=>'No',", "                    'group'=>'Product Information'", '                ]);', '            return $balanceInfo;', '        }', '    }', '', '    function setCheckTypeInformation($product, &$balanceInfo)', '    {', "        $checkTypes = \\App\\CheckType:: LeftJoin('product_check_type', 'product_check_type.check_type_id', 'check_types.id')", "            ->selectRaw('id,category,subcategory,price')", "            ->where('product_id', $product->id)->get();", '', '        foreach($checkTypes as $checkType)', '        {', "            array_push($balanceInfo['rows'],", '                [', "                    'name'=>$checkType->category,", "                    'value'=>$checkType->price
[ncm2_phpactor@yarp] ,", "                    'group'=>'Test Information'", '                ]);', '        }', '', '    }', '', '', '}'], '/Users/juju/Projects/PHP/knights', ['php', '/Users/juju/.config/nvim/dein/repos/github.com/phpactor/phpactor/plugin/../bin/phpactor', 'complete', '-d', '/Users/juju/Development/Applications/neovim-qt/neovim-qt/build/bin', '--format=json', '--', 'stdin', '2221']]'
[ncm2_phpactor@yarp] Traceback (most recent call last):
[ncm2_phpactor@yarp]   File "/Users/juju/.config/nvim/dein/.cache/init.vim/.dein/pythonx/yarp.py", line 30, in on_notification
[ncm2_phpactor@yarp]     getattr(module_obj, method)(*args)
[ncm2_phpactor@yarp]   File "/Users/juju/.config/nvim/dein/.cache/init.vim/.dein/pythonx/ncm2.py", line 206, in on_complete
[ncm2_phpactor@yarp]     on_complete_impl(context, *args)
[ncm2_phpactor@yarp]   File "/Users/juju/.config/nvim/dein/.cache/init.vim/.dein/pythonx/ncm2_phpactor.py", line 55, in on_complete
[ncm2_phpactor@yarp]     for e in result['suggestions']:
[ncm2_phpactor@yarp] KeyError: 'suggestions'
[php]  syntax error, unexpected ')', expecting variable (T_VARIABLE) or '{' or '$'

Trouble with dynamic snippets for method parameter expansion

When the completion suggestions are displayed, I am not able to trigger the dynamic snippet functionality to complete the method parameters as pictured in the GIF in the project README. When I trigger ncm2_ultisnips#expand_or("\<CR>", 'n') with a completion option selected, it just inserts a return instead of inserting the method arguments.

The popup menu does not display a [+] to indicate that there is a snippet to complete.

I believe I have everything configured correctly because it's working fine for ncm2-tern for JavaScript.

neovim: v0.3.1

phpactor: occurs with f629a23 (latest develop) and f53bec1 (latest master) and I made sure to rm -rf vendor && composer install after changing branches.

ncm2-phpactor: 5999f57 (latest master)

minimal init.vim:

call plug#begin('~/.vim/plugged')

Plug 'phpactor/phpactor', {'for': 'php', 'do': 'composer install'}

Plug 'ncm2/ncm2'
Plug 'roxma/nvim-yarp'

Plug 'phpactor/ncm2-phpactor'

Plug 'ncm2/ncm2-ultisnips'
Plug 'SirVer/ultisnips'

call plug#end()

set completeopt=noinsert,menuone,noselect
autocmd BufEnter * call ncm2#enable_for_buffer()

let g:phpactorOmniError = v:true

autocmd FileType php setlocal omnifunc=phpactor#Complete

inoremap <silent> <expr> <CR> ncm2_ultisnips#expand_or("\<CR>", 'n')

Demo:
asciicast

Any help would be appreciated, thanks.

no $ when call static methods

Here is my neovim config

if has('nvim')
  "     插件
  " 自动补全框架:NCM2
  Plug 'ncm2/ncm2'
  Plug 'roxma/nvim-yarp'
  autocmd BufEnter * call ncm2#enable_for_buffer()
  set completeopt=noinsert,menuone,noselect
  set shortmess+=c

  "     插件
  " 自动补全插件:PHP
  Plug 'phpactor/phpactor', { 'branch': 'develop', 'do': 'composer install', 'for': 'php' }
  Plug 'phpactor/ncm2-phpactor'
  autocmd BufEnter * call ncm2#enable_for_buffer()
  nmap <Leader>u :call phpactor#UseAdd()<CR>
  nmap <Leader>mm :call phpactor#ContextMenu()<CR>
  nmap <Leader>nn :call phpactor#Navigate()<CR>
  nmap <Leader>o :call phpactor#GotoDefinition()<CR>
  nmap <Leader>K :call phpactor#Hover()<CR>
  nmap <Leader>tt :call phpactor#Transform()<CR>
  nmap <Leader>cc :call phpactor#ClassNew()<CR>
  nmap <silent><Leader>ee :call phpactor#ExtractExpression(v:false)<CR>
  vmap <silent><Leader>ee :<C-U>call phpactor#ExtractExpression(v:true)<CR>
  vmap <silent><Leader>em :<C-U>call phpactor#ExtractMethod()<CR>
...

REC

Open preview window on auto completing

Currently, NCM2 doesn't seem to provide detailed info about functions being completed which, in result, does not display the preview window (or the brand new floating window as of neovim 4.0).

There are cases though where opening the preview window would be great, e.g. when you have a method suggestion with tons of default arguments, which don't get auto-completed.

Obs: It would also be really nice to have ncm2 providing a basic description to the suggested methods/functions (like their phpDoc comment if any i.e)

JSONDecodeError (Error on insert mode)

I used to work in vim but I find out that autocompletion in nvim using phpactor is so much better that vim's YouCompleteMe so I just set it up but I am facing this problem in one of my laravel project. Every time I try to write some code inside controller or any other php file it throws an error.

Error:
[ncm2_phpactor@yarp] json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

NVM:

NVIM v0.4.0-126-g88963a18d
Build type: Release
LuaJIT 2.0.5
Compilation: /usr/bin/cc -Wshadow -Wconversion -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -O2 -DNDEBUG -DMIN_LOG_LEVEL=3 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fdiagnostics-color=auto -Wno-array-bounds -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -I/home/talha/neovim/build/config -I/home/talha/neovim/src -I/home/talha/neovim/.deps/usr/include -I/usr/include -I/home/talha/neovim/build/src/nvim/auto -I/home/talha/neovim/build/include
Compiled by talha@talha-XPS-13-9360

Features: +acl +iconv +jemalloc +tui 
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/share/nvim"

Run :checkhealth for more info

PHP:
PHP 7.2.10-0ubuntu0.18.04.1 (cli) (built: Sep 13 2018 13:45:02) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.10-0ubuntu0.18.04.1, Copyright (c) 1999-2018, by Zend Technologies

.vimrc (simplified):

if empty(glob('~/.config/nvim/autoload/plug.vim'))
    silent !curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs
                \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
    autocmd!
    autocmd VimEnter * PlugInstall
endif

call plug#begin('~/.config/nvim/plugged')
Plug 'ncm2/ncm2'
Plug 'roxma/nvim-yarp'
Plug 'roxma/vim-hug-neovim-rpc'

Plug 'phpactor/phpactor' ,  {'do': 'composer install', 'for': 'php'}
Plug 'phpactor/ncm2-phpactor'
Plug 'ncm2/ncm2-ultisnips'
Plug 'ludovicchabant/vim-gutentags'
Plug 'SirVer/ultisnips' | Plug 'phux/vim-snippets'
call plug#end()

let g:UltiSnipsExpandTrigger="<c-j>"
let g:UltiSnipsJumpForwardTrigger="<c-j>"
let g:UltiSnipsJumpBackwardTrigger="<c-b>"

" PHP7
let g:ultisnips_php_scalar_types = 1

augroup ncm2
  au!
  autocmd BufEnter * call ncm2#enable_for_buffer()
  set completeopt=noinsert,menuone,noselect
  au User Ncm2PopupOpen set completeopt=noinsert,menuone,noselect
  au User Ncm2PopupClose set completeopt=menuone
augroup END

" parameter expansion for selected entry via Enter
inoremap <silent> <expr> <CR> (pumvisible() ? ncm2_ultisnips#expand_or("\<CR>", 'n') : "\<CR>")

" cycle through completion entries with tab/shift+tab
inoremap <expr> <TAB> pumvisible() ? "\<c-n>" : "\<TAB>"
inoremap <expr> <s-tab> pumvisible() ? "\<c-p>" : "\<TAB>"

Default completion is ncm2

I know this is more a missconfiguration than an issue, and I've been looking but I don't know how to fix it.
By default I'm getting what I think is the default ncm2 autocompletion (triggered automatically):
ncm2completion
Then, if I press <C-x><C-o> I get the phpactor source:
ncm2completionphpactor
How can I set up ncm2 in order to trigger automatically the phpactor suggestions instead of the default ones?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.