diff --git a/pyls/plugins/jedi_completion.py b/pyls/plugins/jedi_completion.py index f5acacbf..ed61dba6 100644 --- a/pyls/plugins/jedi_completion.py +++ b/pyls/plugins/jedi_completion.py @@ -101,18 +101,25 @@ def _format_completion(d, include_params=True): } if include_params and hasattr(d, 'params') and d.params: - positional_args = [param for param in d.params if '=' not in param.description] - # For completions with params, we can generate a snippet instead - completion['insertTextFormat'] = lsp.InsertTextFormat.Snippet - snippet = d.name + '(' - for i, param in enumerate(positional_args): - name = param.name if param.name != '/' else '\\/' - snippet += '${%s:%s}' % (i + 1, name) - if i < len(positional_args) - 1: - snippet += ', ' - snippet += ')$0' - completion['insertText'] = snippet + + def positional_args(): + # return params until kwarg + for param in d.params: + if param.name == '/': + continue + if param.name == '*' or '=' in param.description: + break + yield param + + snippet_params = ', '.join( + '${{{}:{}}}'.format(i + 1, param.name) for i, param in enumerate(positional_args()) + ) + + completion.update( + insertTextFormat=lsp.InsertTextFormat.Snippet, + insertText='{}({})$0'.format(d.name, snippet_params) + ) return completion diff --git a/test/plugins/test_completion.py b/test/plugins/test_completion.py index b054c510..2632ae45 100644 --- a/test/plugins/test_completion.py +++ b/test/plugins/test_completion.py @@ -194,7 +194,7 @@ def test_snippet_parsing(config): 'completion': {'completionItem': {'snippetSupport': True}}} config.update({'plugins': {'jedi_completion': {'include_params': True}}}) completions = pyls_jedi_completions(config, doc, completion_position) - out = 'logical_and(${1:x1}, ${2:x2}, ${3:\\/}, ${4:*})$0' + out = 'logical_and(${1:x1}, ${2:x2})$0' assert completions[0]['insertText'] == out