|
1 | 1 | # Copyright 2017 Palantir Technologies, Inc.
|
2 | 2 | import logging
|
| 3 | +import parso |
3 | 4 | from pyls import hookimpl, lsp, _utils
|
4 | 5 |
|
5 | 6 | log = logging.getLogger(__name__)
|
@@ -50,8 +51,25 @@ def pyls_completions(config, document, position):
|
50 | 51 |
|
51 | 52 | settings = config.plugin_settings('jedi_completion', document_path=document.path)
|
52 | 53 | should_include_params = settings.get('include_params')
|
| 54 | + include_params = (use_snippets(document, position) and |
| 55 | + snippet_support and should_include_params) |
| 56 | + return [_format_completion(d, include_params) for d in definitions] or None |
53 | 57 |
|
54 |
| - return [_format_completion(d, snippet_support and should_include_params) for d in definitions] or None |
| 58 | + |
| 59 | +def use_snippets(document, position): |
| 60 | + """ |
| 61 | + Determine if it's necessary to return snippets in code completions. |
| 62 | +
|
| 63 | + This returns `False` if a completion is being requested on an import |
| 64 | + statement, `True` otherwise. |
| 65 | + """ |
| 66 | + lines = document.source.split('\n') |
| 67 | + act_line = lines[position['line']] |
| 68 | + tokens = parso.parse(act_line) |
| 69 | + act_statement = tokens.children[0].get_code() |
| 70 | + if act_statement.startswith('import') or act_statement.startswith('from'): |
| 71 | + return False |
| 72 | + return True |
55 | 73 |
|
56 | 74 |
|
57 | 75 | def _format_completion(d, include_params=True):
|
|
0 commit comments