From a8dd6866ee16704a76845bc101b21bdb6b967343 Mon Sep 17 00:00:00 2001 From: mpanarin Date: Wed, 17 Jul 2019 20:32:50 +0300 Subject: [PATCH 1/2] Do not escape `*` in docs, as it is crucial part of markdown --- pyls/_utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pyls/_utils.py b/pyls/_utils.py index 6e9bfbdf..6faac8d1 100644 --- a/pyls/_utils.py +++ b/pyls/_utils.py @@ -136,7 +136,6 @@ def format_docstring(contents): """ contents = contents.replace('\t', u'\u00A0' * 4) contents = contents.replace(' ', u'\u00A0' * 2) - contents = contents.replace('*', '\\*') return contents From 85b2322329f8db4b471c582263ccd618581ed684 Mon Sep 17 00:00:00 2001 From: mpanarin Date: Wed, 17 Jul 2019 20:33:47 +0300 Subject: [PATCH 2/2] Update pyls hover to specify language of signature. LSP supports `MarkedString[]` to specify render engine. We can definitely say that function signature should be rendered as python. For the docstring, as we have no good way of parsing it to guess the engine, we can pass it as markdown. --- pyls/plugins/hover.py | 27 ++++++++++++++++++++++----- setup.py | 2 +- test/plugins/test_hover.py | 2 +- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/pyls/plugins/hover.py b/pyls/plugins/hover.py index 605ba893..86f80c31 100644 --- a/pyls/plugins/hover.py +++ b/pyls/plugins/hover.py @@ -10,9 +10,26 @@ def pyls_hover(document, position): definitions = document.jedi_script(position).goto_definitions() word = document.word_at_position(position) - # Find an exact match for a completion - for d in definitions: - if d.name == word: - return {'contents': _utils.format_docstring(d.docstring()) or ''} + # Find first exact matching definition + definition = next((x for x in definitions if x.name == word), None) - return {'contents': ''} + if not definition: + return {'contents': ''} + + # raw docstring returns only doc, without signature + doc = _utils.format_docstring(definition.docstring(raw=True)) + + # Find first exact matching signature + signature = next((x.to_string() for x in definition.get_signatures() if x.name == word), '') + + contents = [] + if signature: + contents.append({ + 'language': 'python', + 'value': signature, + }) + if doc: + contents.append(doc) + if not contents: + return {'contents': ''} + return {'contents': contents} diff --git a/setup.py b/setup.py index d0f7f7db..fcd37272 100755 --- a/setup.py +++ b/setup.py @@ -36,7 +36,7 @@ 'future>=0.14.0', 'futures; python_version<"3.2"', 'backports.functools_lru_cache; python_version<"3.2"', - 'jedi>=0.14.1,<0.15', + 'jedi>=0.15.0,<0.16', 'python-jsonrpc-server>=0.1.0', 'pluggy' ], diff --git a/test/plugins/test_hover.py b/test/plugins/test_hover.py index 5d3baf83..9b56d2e2 100644 --- a/test/plugins/test_hover.py +++ b/test/plugins/test_hover.py @@ -21,7 +21,7 @@ def test_hover(): doc = Document(DOC_URI, DOC) assert { - 'contents': 'main()\n\nhello world' + 'contents': [{'language': 'python', 'value': 'main()'}, 'hello world'] } == pyls_hover(doc, hov_position) assert {'contents': ''} == pyls_hover(doc, no_hov_position)