|
1 | 1 | # Copyright 2017 Palantir Technologies, Inc.
|
2 | 2 | import logging
|
3 |
| -from pyls.lsp import CompletionItemKind |
4 |
| -from pyls import hookimpl, _utils |
| 3 | +from pyls import hookimpl, lsp, _utils |
5 | 4 |
|
6 | 5 | log = logging.getLogger(__name__)
|
7 | 6 |
|
8 | 7 |
|
9 | 8 | @hookimpl
|
10 | 9 | def pyls_completions(document, position):
|
11 |
| - log.debug('Launching Jedi') |
12 | 10 | definitions = document.jedi_script(position).completions()
|
13 |
| - definitions = [{ |
| 11 | + return [{ |
14 | 12 | 'label': _label(d),
|
15 | 13 | 'kind': _kind(d),
|
16 | 14 | 'detail': _detail(d),
|
17 | 15 | 'documentation': _utils.format_docstring(d.docstring()),
|
18 | 16 | 'sortText': _sort_text(d),
|
19 | 17 | 'insertText': d.name
|
20 |
| - } for d in definitions] |
21 |
| - log.debug('Jedi finished') |
22 |
| - return definitions |
| 18 | + } for d in definitions] or None |
23 | 19 |
|
24 | 20 |
|
25 | 21 | def _label(definition):
|
@@ -53,36 +49,36 @@ def _sort_text(definition):
|
53 | 49 | def _kind(d):
|
54 | 50 | """ Return the VSCode type """
|
55 | 51 | MAP = {
|
56 |
| - 'none': CompletionItemKind.Value, |
57 |
| - 'type': CompletionItemKind.Class, |
58 |
| - 'tuple': CompletionItemKind.Class, |
59 |
| - 'dict': CompletionItemKind.Class, |
60 |
| - 'dictionary': CompletionItemKind.Class, |
61 |
| - 'function': CompletionItemKind.Function, |
62 |
| - 'lambda': CompletionItemKind.Function, |
63 |
| - 'generator': CompletionItemKind.Function, |
64 |
| - 'class': CompletionItemKind.Class, |
65 |
| - 'instance': CompletionItemKind.Reference, |
66 |
| - 'method': CompletionItemKind.Method, |
67 |
| - 'builtin': CompletionItemKind.Class, |
68 |
| - 'builtinfunction': CompletionItemKind.Function, |
69 |
| - 'module': CompletionItemKind.Module, |
70 |
| - 'file': CompletionItemKind.File, |
71 |
| - 'xrange': CompletionItemKind.Class, |
72 |
| - 'slice': CompletionItemKind.Class, |
73 |
| - 'traceback': CompletionItemKind.Class, |
74 |
| - 'frame': CompletionItemKind.Class, |
75 |
| - 'buffer': CompletionItemKind.Class, |
76 |
| - 'dictproxy': CompletionItemKind.Class, |
77 |
| - 'funcdef': CompletionItemKind.Function, |
78 |
| - 'property': CompletionItemKind.Property, |
79 |
| - 'import': CompletionItemKind.Module, |
80 |
| - 'keyword': CompletionItemKind.Keyword, |
81 |
| - 'constant': CompletionItemKind.Variable, |
82 |
| - 'variable': CompletionItemKind.Variable, |
83 |
| - 'value': CompletionItemKind.Value, |
84 |
| - 'param': CompletionItemKind.Variable, |
85 |
| - 'statement': CompletionItemKind.Keyword, |
| 52 | + 'none': lsp.CompletionItemKind.Value, |
| 53 | + 'type': lsp.CompletionItemKind.Class, |
| 54 | + 'tuple': lsp.CompletionItemKind.Class, |
| 55 | + 'dict': lsp.CompletionItemKind.Class, |
| 56 | + 'dictionary': lsp.CompletionItemKind.Class, |
| 57 | + 'function': lsp.CompletionItemKind.Function, |
| 58 | + 'lambda': lsp.CompletionItemKind.Function, |
| 59 | + 'generator': lsp.CompletionItemKind.Function, |
| 60 | + 'class': lsp.CompletionItemKind.Class, |
| 61 | + 'instance': lsp.CompletionItemKind.Reference, |
| 62 | + 'method': lsp.CompletionItemKind.Method, |
| 63 | + 'builtin': lsp.CompletionItemKind.Class, |
| 64 | + 'builtinfunction': lsp.CompletionItemKind.Function, |
| 65 | + 'module': lsp.CompletionItemKind.Module, |
| 66 | + 'file': lsp.CompletionItemKind.File, |
| 67 | + 'xrange': lsp.CompletionItemKind.Class, |
| 68 | + 'slice': lsp.CompletionItemKind.Class, |
| 69 | + 'traceback': lsp.CompletionItemKind.Class, |
| 70 | + 'frame': lsp.CompletionItemKind.Class, |
| 71 | + 'buffer': lsp.CompletionItemKind.Class, |
| 72 | + 'dictproxy': lsp.CompletionItemKind.Class, |
| 73 | + 'funcdef': lsp.CompletionItemKind.Function, |
| 74 | + 'property': lsp.CompletionItemKind.Property, |
| 75 | + 'import': lsp.CompletionItemKind.Module, |
| 76 | + 'keyword': lsp.CompletionItemKind.Keyword, |
| 77 | + 'constant': lsp.CompletionItemKind.Variable, |
| 78 | + 'variable': lsp.CompletionItemKind.Variable, |
| 79 | + 'value': lsp.CompletionItemKind.Value, |
| 80 | + 'param': lsp.CompletionItemKind.Variable, |
| 81 | + 'statement': lsp.CompletionItemKind.Keyword, |
86 | 82 | }
|
87 | 83 |
|
88 | 84 | return MAP.get(d.type)
|
0 commit comments