2019-05-21 12:53:09 +00:00
|
|
|
"""
|
|
|
|
A Deoplete source for ALE completion via tsserver and LSP.
|
|
|
|
"""
|
|
|
|
__author__ = 'Joao Paulo, w0rp'
|
|
|
|
|
|
|
|
try:
|
|
|
|
from deoplete.source.base import Base
|
|
|
|
except ImportError:
|
|
|
|
# Mock the Base class if deoplete isn't available, as mock isn't available
|
|
|
|
# in the Docker image.
|
|
|
|
class Base(object):
|
|
|
|
def __init__(self, vim):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
# Make sure this code is valid in Python 2, used for running unit tests.
|
|
|
|
class Source(Base):
|
|
|
|
|
|
|
|
def __init__(self, vim):
|
|
|
|
super(Source, self).__init__(vim)
|
|
|
|
|
|
|
|
self.name = 'ale'
|
|
|
|
self.mark = '[L]'
|
2019-06-15 07:57:11 +00:00
|
|
|
self.rank = 1000
|
2019-05-21 12:53:09 +00:00
|
|
|
self.is_bytepos = True
|
|
|
|
self.min_pattern_length = 1
|
2020-01-01 19:00:41 +00:00
|
|
|
self.is_volatile = True
|
2019-06-25 08:57:38 +00:00
|
|
|
# Do not forget to update s:trigger_character_map in completion.vim in
|
|
|
|
# updating entries in this map.
|
|
|
|
self.input_patterns = {
|
|
|
|
'_': r'\.\w*$',
|
|
|
|
'rust': r'(\.|::)\w*$',
|
|
|
|
'typescript': r'(\.|\'|")\w*$',
|
2019-07-14 13:20:44 +00:00
|
|
|
'cpp': r'(\.|::|->)\w*$',
|
2019-06-25 08:57:38 +00:00
|
|
|
}
|
2019-05-21 12:53:09 +00:00
|
|
|
|
|
|
|
# Returns an integer for the start position, as with omnifunc.
|
2019-06-19 04:25:41 +00:00
|
|
|
def get_complete_position(self, context):
|
|
|
|
return self.vim.call(
|
|
|
|
'ale#completion#GetCompletionPositionForDeoplete', context['input']
|
|
|
|
)
|
2019-05-21 12:53:09 +00:00
|
|
|
|
|
|
|
def gather_candidates(self, context):
|
|
|
|
# Stop early if ALE can't provide completion data for this buffer.
|
|
|
|
if not self.vim.call('ale#completion#CanProvideCompletions'):
|
|
|
|
return None
|
|
|
|
|
2020-01-01 19:00:41 +00:00
|
|
|
event = context.get('event')
|
2019-05-21 12:53:09 +00:00
|
|
|
|
2020-01-01 19:00:41 +00:00
|
|
|
if event == 'Async':
|
2019-05-21 12:53:09 +00:00
|
|
|
result = self.vim.call('ale#completion#GetCompletionResult')
|
2020-01-01 19:00:41 +00:00
|
|
|
return result or []
|
2019-05-21 12:53:09 +00:00
|
|
|
|
2020-01-01 19:00:41 +00:00
|
|
|
if context.get('is_refresh'):
|
|
|
|
self.vim.command(
|
|
|
|
"call ale#completion#GetCompletions('ale-callback', " + \
|
|
|
|
"{'callback': {completions -> deoplete#auto_complete() }})"
|
|
|
|
)
|
2019-05-21 12:53:09 +00:00
|
|
|
|
|
|
|
return []
|