diff --git a/README.md b/README.md index f672638..864590d 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/pythonx/completers/php.py b/pythonx/completers/php.py new file mode 100644 index 0000000..e1ef722 --- /dev/null +++ b/pythonx/completers/php.py @@ -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