From 07e11b36458781d7f2cac52c9f649439b86ab455 Mon Sep 17 00:00:00 2001 From: dantleech Date: Sun, 30 Jul 2017 21:50:13 +0200 Subject: [PATCH 1/3] PHP Support via. phpactor --- pythonx/completers/php.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 pythonx/completers/php.py diff --git a/pythonx/completers/php.py b/pythonx/completers/php.py new file mode 100644 index 0000000..1006792 --- /dev/null +++ b/pythonx/completers/php.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- + +import vim +import json +import pprint + +from completor import Completor +from completor.compat import to_unicode + +class Php(Completor): + filetype = 'php' + trigger = r'(?::\w{2,}\w*|->\w*)$' + + def offset(self): + line, col = vim.current.window.cursor + line2byte = vim.Function('line2byte') + return line2byte(line) + col - 3 + + 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): + res = [] + data = to_unicode(data[0], 'utf-8') + data = json.loads(data) + + if 'error' in data: + pprint.pprint(data) + return [] + + for item in data['suggestions']: + res.append({ + 'word': item['name'], + 'menu': item['type'] + }) + + return res From 249ddffb6840ae2a6e5032e814b4082fa410d8ae Mon Sep 17 00:00:00 2001 From: dantleech Date: Sat, 5 Aug 2017 19:41:41 +0200 Subject: [PATCH 2/3] Added Phpactor completor --- pythonx/completers/php.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/pythonx/completers/php.py b/pythonx/completers/php.py index 1006792..b838163 100644 --- a/pythonx/completers/php.py +++ b/pythonx/completers/php.py @@ -9,30 +9,36 @@ class Php(Completor): filetype = 'php' - trigger = r'(?::\w{2,}\w*|->\w*)$' + trigger = r'(::\w*|->\w*)$' def offset(self): line, col = vim.current.window.cursor line2byte = vim.Function('line2byte') - return line2byte(line) + col - 3 + 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') - data = json.loads(data) - if 'error' in data: - pprint.pprint(data) + 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['type'] + 'menu': item['info'] }) return res From 68b49d2672a4fa4cc29682d65a5cb4466f3b4bda Mon Sep 17 00:00:00 2001 From: dantleech Date: Sat, 5 Aug 2017 19:43:54 +0200 Subject: [PATCH 3/3] Updated README --- README.md | 4 ++++ pythonx/completers/php.py | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) 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 index b838163..e1ef722 100644 --- a/pythonx/completers/php.py +++ b/pythonx/completers/php.py @@ -2,7 +2,6 @@ import vim import json -import pprint from completor import Completor from completor.compat import to_unicode