Python code style fixes
This commit is contained in:
parent
0954ff31d9
commit
4d95e32a1e
@ -35,69 +35,75 @@ sys.path.pop(0)
|
|||||||
|
|
||||||
|
|
||||||
class JediCompleter(Completer):
|
class JediCompleter(Completer):
|
||||||
"""
|
"""
|
||||||
A Completer that uses the Jedi completion engine.
|
A Completer that uses the Jedi completion engine.
|
||||||
https://jedi.readthedocs.org/en/latest/
|
https://jedi.readthedocs.org/en/latest/
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(JediCompleter, self).__init__()
|
super(JediCompleter, self).__init__()
|
||||||
self._query_ready = Event()
|
self._query_ready = Event()
|
||||||
self._candidates_ready = Event()
|
self._candidates_ready = Event()
|
||||||
self._query = None
|
self._query = None
|
||||||
self._candidates = None
|
self._candidates = None
|
||||||
self._exit = False
|
self._exit = False
|
||||||
self._start_completion_thread()
|
self._start_completion_thread()
|
||||||
|
|
||||||
def _start_completion_thread(self):
|
|
||||||
self._completion_thread = Thread(target=self.SetCandidates)
|
|
||||||
self._completion_thread.start()
|
|
||||||
|
|
||||||
def SupportedFiletypes(self):
|
def _start_completion_thread(self):
|
||||||
""" Just python """
|
self._completion_thread = Thread(target=self.SetCandidates)
|
||||||
return ['python']
|
self._completion_thread.start()
|
||||||
|
|
||||||
def CandidatesForQueryAsyncInner(self, query):
|
|
||||||
self._query = query
|
|
||||||
self._candidates = None
|
|
||||||
self._candidates_ready.clear()
|
|
||||||
self._query_ready.set()
|
|
||||||
|
|
||||||
def AsyncCandidateRequestReadyInner(self):
|
def SupportedFiletypes(self):
|
||||||
if self._completion_thread.is_alive():
|
""" Just python """
|
||||||
return WaitAndClear(self._candidates_ready, timeout=0.005)
|
return ['python']
|
||||||
else:
|
|
||||||
self._start_completion_thread()
|
|
||||||
return False
|
|
||||||
|
|
||||||
def CandidatesFromStoredRequestInner(self):
|
|
||||||
return self._candidates or []
|
|
||||||
|
|
||||||
def SetCandidates(self):
|
def CandidatesForQueryAsyncInner(self, query):
|
||||||
while True:
|
self._query = query
|
||||||
WaitAndClear(self._query_ready)
|
self._candidates = None
|
||||||
|
self._candidates_ready.clear()
|
||||||
|
self._query_ready.set()
|
||||||
|
|
||||||
if self._exit:
|
|
||||||
return
|
|
||||||
|
|
||||||
filename = vim.current.buffer.name
|
def AsyncCandidateRequestReadyInner(self):
|
||||||
query = self._query
|
if self._completion_thread.is_alive():
|
||||||
line, column = CurrentLineAndColumn()
|
return WaitAndClear(self._candidates_ready, timeout=0.005)
|
||||||
lines = map(str, vim.current.buffer)
|
else:
|
||||||
if query is not None and lines[line]:
|
self._start_completion_thread()
|
||||||
before, after = lines[line].rsplit('.', 1)
|
return False
|
||||||
lines[line] = before + '.'
|
|
||||||
column = len(before) + 1
|
|
||||||
|
|
||||||
source = "\n".join(lines)
|
|
||||||
script = Script(source, line + 1, column, filename)
|
|
||||||
|
|
||||||
self._candidates = [{'word': str(completion.word),
|
def CandidatesFromStoredRequestInner(self):
|
||||||
'menu': str(completion.description),
|
return self._candidates or []
|
||||||
'info': str(completion.doc)}
|
|
||||||
for completion in script.complete()]
|
|
||||||
|
|
||||||
self._candidates_ready.set()
|
|
||||||
|
def SetCandidates(self):
|
||||||
|
while True:
|
||||||
|
WaitAndClear(self._query_ready)
|
||||||
|
|
||||||
|
if self._exit:
|
||||||
|
return
|
||||||
|
|
||||||
|
filename = vim.current.buffer.name
|
||||||
|
query = self._query
|
||||||
|
line, column = CurrentLineAndColumn()
|
||||||
|
lines = map(str, vim.current.buffer)
|
||||||
|
if query is not None and lines[line]:
|
||||||
|
before, after = lines[line].rsplit('.', 1)
|
||||||
|
lines[line] = before + '.'
|
||||||
|
column = len(before) + 1
|
||||||
|
|
||||||
|
source = "\n".join(lines)
|
||||||
|
script = Script(source, line + 1, column, filename)
|
||||||
|
|
||||||
|
self._candidates = [{'word': str(completion.word),
|
||||||
|
'menu': str(completion.description),
|
||||||
|
'info': str(completion.doc)}
|
||||||
|
for completion in script.complete()]
|
||||||
|
|
||||||
|
self._candidates_ready.set()
|
||||||
|
|
||||||
|
|
||||||
def WaitAndClear(event, timeout=None):
|
def WaitAndClear(event, timeout=None):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user