Skip to content

Commit

Permalink
PR: Fix snippet parsing when a slash character is present (#701)
Browse files Browse the repository at this point in the history
  • Loading branch information
steff456 authored and ccordoba12 committed Nov 20, 2019
1 parent 803d8a5 commit b08891f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pyls/plugins/jedi_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ def _format_completion(d, include_params=True):
completion['insertTextFormat'] = lsp.InsertTextFormat.Snippet
snippet = d.name + '('
for i, param in enumerate(positional_args):
snippet += '${%s:%s}' % (i + 1, param.name)
name = param.name if param.name != '/' else '\\/'
snippet += '${%s:%s}' % (i + 1, name)
if i < len(positional_args) - 1:
snippet += ', '
snippet += ')$0'
Expand Down
12 changes: 12 additions & 0 deletions test/plugins/test_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,18 @@ def test_snippets_completion(config):
assert completions[0]['insertText'] == out


def test_snippet_parsing(config):
doc = 'import numpy as np\nnp.logical_and'
completion_position = {'line': 1, 'character': 14}
doc = Document(DOC_URI, doc)
config.capabilities['textDocument'] = {
'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'
assert completions[0]['insertText'] == out


def test_multiline_snippets(config):
document = 'from datetime import\\\n date,\\\n datetime \na=date'
doc = Document(DOC_URI, document)
Expand Down

0 comments on commit b08891f

Please sign in to comment.