Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ let g:completor_gocode_binary = '/path/to/gocode'

Use [completor-swift](https://github.com/maralla/completor-swift).

#### PHP

Use [phpactor](https://github.com/phpactor/phpactor).

#### other languages

For other omni completions completor not natively implemented, auto completion
Expand Down
43 changes: 43 additions & 0 deletions pythonx/completers/php.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-

import vim
import json

from completor import Completor
from completor.compat import to_unicode

class Php(Completor):
filetype = 'php'
trigger = r'(::\w*|->\w*)$'

def offset(self):
line, col = vim.current.window.cursor
line2byte = vim.Function('line2byte')
return line2byte(line) + col - 1

def format_cmd(self):
binary = self.get_option('phpactor_binary') or 'phpactor'
return [binary, 'complete', self.tempname, self.offset(), '--format=json']

def parse(self, data):
if len(data) == 0:
return []

res = []
data = to_unicode(data[0], 'utf-8')

try:
data = json.loads(data)
except json.decoder.JSONDecodeError:
return []

if not 'suggestions' in data:
return []

for item in data['suggestions']:
res.append({
'word': item['name'],
'menu': item['info']
})

return res