From b08891f9345a5bbd543c657d1251cceed9f79b01 Mon Sep 17 00:00:00 2001 From: Stephannie Jimenez Gacha Date: Tue, 19 Nov 2019 22:42:34 -0500 Subject: [PATCH] PR: Fix snippet parsing when a slash character is present (#701) --- pyls/plugins/jedi_completion.py | 3 ++- test/plugins/test_completion.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/pyls/plugins/jedi_completion.py b/pyls/plugins/jedi_completion.py index b310e81f..34c90e68 100644 --- a/pyls/plugins/jedi_completion.py +++ b/pyls/plugins/jedi_completion.py @@ -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' diff --git a/test/plugins/test_completion.py b/test/plugins/test_completion.py index 1980016c..3f09eab7 100644 --- a/test/plugins/test_completion.py +++ b/test/plugins/test_completion.py @@ -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)