summaryrefslogtreecommitdiff
path: root/rplugin/python3/deoplete/sources/ale.py
blob: 7f1c1d609a864a2872190f1087c46ddf1453470e (plain)
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
"""
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]'
        self.rank = 1000
        self.is_bytepos = True
        self.min_pattern_length = 1

    # Returns an integer for the start position, as with omnifunc.
    def get_completion_position(self):
        return self.vim.call('ale#completion#GetCompletionPosition')

    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

        if context.get('is_refresh'):
            context['is_async'] = False

        if context['is_async']:
            # Result is the same as for omnifunc, or None.
            result = self.vim.call('ale#completion#GetCompletionResult')

            if result is not None:
                context['is_async'] = False

                return result
        else:
            context['is_async'] = True

            # Request some completion results.
            self.vim.call('ale#completion#GetCompletions', 'deoplete')

        return []