diff --git a/pyls/plugins/completion.py b/pyls/plugins/completion.py index 1818cd36..0354448b 100644 --- a/pyls/plugins/completion.py +++ b/pyls/plugins/completion.py @@ -10,14 +10,27 @@ def pyls_completions(document, position): definitions = document.jedi_script(position).completions() return [{ - 'label': d.name, + 'label': _label(d), 'kind': _kind(d), - 'detail': d.description or "", + 'detail': _detail(d), 'documentation': d.docstring(), - 'sortText': _sort_text(d) + 'sortText': _sort_text(d), + 'insertText': d.name } for d in definitions] +def _label(definition): + if definition.type in ('function', 'method'): + params = ", ".join(param.name for param in definition.params) + return "{}({})".format(definition.name, params) + + return definition.name + + +def _detail(definition): + return "builtin" if definition.in_builtin_module() else definition.parent().full_name or "" + + def _sort_text(definition): """ Ensure builtins appear at the bottom. Description is of format : . diff --git a/test/plugins/test_completion.py b/test/plugins/test_completion.py index 50cf63b3..9095ea0b 100644 --- a/test/plugins/test_completion.py +++ b/test/plugins/test_completion.py @@ -1,4 +1,5 @@ # Copyright 2017 Palantir Technologies, Inc. +import sys from pyls import uris from pyls.plugins.completion import pyls_completions from pyls.workspace import Document @@ -23,7 +24,10 @@ def test_completion(): items = pyls_completions(doc, com_position) assert len(items) > 0 - assert items[0]['label'] == 'read' + if (sys.version_info > (3, 0)): + assert items[0]['label'] == 'read(args)' + else: + assert items[0]['label'] == 'read()' def test_completion_ordering(): @@ -35,6 +39,6 @@ def test_completion_ordering(): items = {c['label']: c['sortText'] for c in completions} # Assert that builtins come after our own functions even if alphabetically they're before - assert items['hello'] < items['dict'] + assert items['hello()'] < items['dict'] # And that 'hidden' functions come after unhidden ones - assert items['hello'] < items['_a_hello'] + assert items['hello()'] < items['_a_hello()']