-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathphp.py
More file actions
43 lines (32 loc) · 1023 Bytes
/
php.py
File metadata and controls
43 lines (32 loc) · 1023 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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