This repository was archived by the owner on Mar 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathrust.py
More file actions
101 lines (78 loc) · 2.74 KB
/
rust.py
File metadata and controls
101 lines (78 loc) · 2.74 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
"""Rust completion via Racer"""
import os
import re
import subprocess
import tempfile
from .base import Base
from deoplete.logger import getLogger
logger = getLogger('rust')
VAR_RACER_BINARY = 'deoplete#sources#rust#racer_binary'
VAR_RUST_SOURCE = 'deoplete#sources#rust#rust_source_path'
VAR_DUPLICATION = 'deoplete#sources#rust#show_duplicates'
class Source(Base):
"""Deoplete Rust source"""
def __init__(self, vim):
Base.__init__(self, vim)
self.name = 'rust'
self.mark = '[Rust]'
self.filetypes = ['rust']
self.input_pattern = r'(\.|::)\w*'
self.rank = 500
self.__racer = self.vim.vars.get(VAR_RACER_BINARY)
self.__dup = self.vim.vars.get(VAR_DUPLICATION)
self.__encoding = self.vim.eval('&encoding')
self.__rust_re = re.compile(r'\w*$|(?<=")[./\-\w]*$')
if 'RUST_SRC_PATH' not in os.environ:
rust_path = self.vim.vars.get(VAR_RUST_SOURCE)
if rust_path:
os.environ['RUST_SRC_PATH'] = rust_path
def get_complete_position(self, ctx):
"""Missing"""
if not self.__check_binary():
return -1
method = self.__rust_re.search(ctx['input'])
return method.start() if method else -1
def gather_candidates(self, ctx):
"""Missing"""
candidates = []
lines = self.__retrieve()
matches = [line[6:] for line in lines if line.startswith('MATCH')]
if not bool(self.__dup):
matches = set(matches)
for match in matches:
tokens = match.split(",")
if len(tokens) > 5:
candidate = {
'word': tokens[0],
'kind': tokens[4],
'menu': tokens[5],
'info': ','.join(tokens[5:]),
'dup': self.__dup,
}
candidates.append(candidate)
return candidates
def __retrieve(self):
"""Missing"""
content = self.vim.current.buffer
line, column = self.vim.current.window.cursor
with tempfile.NamedTemporaryFile(mode='w') as buf:
buf.write("\n".join(content))
buf.flush()
args = [
self.__racer,
'complete',
str(line),
str(column),
content.name,
buf.name
]
results = []
try:
results = subprocess.check_output(args) \
.decode(self.__encoding).splitlines()
except Exception:
pass
return results
def __check_binary(self):
"""Missing"""
return os.path.isfile(self.__racer) and os.environ.get('RUST_SRC_PATH')