Skip to content

Commit

Permalink
Support again Jedi 0.14.1 (#683)
Browse files Browse the repository at this point in the history
  • Loading branch information
ccordoba12 authored Oct 27, 2019
1 parent f619d3a commit 19b10c4
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 38 deletions.
6 changes: 6 additions & 0 deletions pyls/_utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# Copyright 2017 Palantir Technologies, Inc.
from distutils.version import LooseVersion
import functools
import inspect
import logging
import os
import sys
import threading

import jedi

PY2 = sys.version_info.major == 2
JEDI_VERSION = jedi.__version__

if PY2:
import pathlib2 as pathlib
Expand Down Expand Up @@ -136,6 +140,8 @@ def format_docstring(contents):
"""
contents = contents.replace('\t', u'\u00A0' * 4)
contents = contents.replace(' ', u'\u00A0' * 2)
if LooseVersion(JEDI_VERSION) < LooseVersion('0.15.0'):
contents = contents.replace('*', '\\*')
return contents


Expand Down
52 changes: 31 additions & 21 deletions pyls/plugins/hover.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Copyright 2017 Palantir Technologies, Inc.
from distutils.version import LooseVersion
import logging

from pyls import hookimpl, _utils

log = logging.getLogger(__name__)
Expand All @@ -10,26 +12,34 @@ def pyls_hover(document, position):
definitions = document.jedi_script(position).goto_definitions()
word = document.word_at_position(position)

# Find first exact matching definition
definition = next((x for x in definitions if x.name == word), None)

if not definition:
return {'contents': ''}
if LooseVersion(_utils.JEDI_VERSION) >= LooseVersion('0.15.0'):
# Find first exact matching definition
definition = next((x for x in definitions if x.name == word), None)

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}
else:
# Find an exact match for a completion
for d in definitions:
if d.name == word:
return {'contents': _utils.format_docstring(d.docstring()) or ''}

# 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}
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
'configparser; python_version<"3.0"',
'future>=0.14.0; python_version<"3"',
'backports.functools_lru_cache; python_version<"3.2"',
'jedi>=0.15.0,<0.16',
'jedi>=0.14.1,<0.16',
'python-jsonrpc-server>=0.1.0',
'pluggy'
],
Expand Down
2 changes: 0 additions & 2 deletions test/plugins/test_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ def test_rope_import_completion(config, workspace):
assert items is None


@pytest.mark.skipif(LooseVersion(jedi.__version__) < LooseVersion('0.14.0'),
reason='This test fails with previous versions of Jedi')
def test_jedi_completion(config):
# Over 'i' in os.path.isabs(...)
com_position = {'line': 1, 'character': 15}
Expand Down
6 changes: 0 additions & 6 deletions test/plugins/test_definitions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# Copyright 2017 Palantir Technologies, Inc.
from distutils.version import LooseVersion
import jedi
import pytest

from pyls import uris
from pyls.plugins.definition import pyls_definitions
from pyls.workspace import Document
Expand Down Expand Up @@ -38,8 +34,6 @@ def test_definitions(config):
assert [{'uri': DOC_URI, 'range': def_range}] == pyls_definitions(config, doc, cursor_pos)


@pytest.mark.skipif(LooseVersion(jedi.__version__) < LooseVersion('0.14.0'),
reason='This test fails with previous versions of jedi')
def test_builtin_definition(config):
# Over 'i' in dict
cursor_pos = {'line': 8, 'character': 24}
Expand Down
11 changes: 9 additions & 2 deletions test/plugins/test_hover.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Copyright 2017 Palantir Technologies, Inc.
from pyls import uris
from distutils.version import LooseVersion

from pyls import uris, _utils
from pyls.plugins.hover import pyls_hover
from pyls.workspace import Document

Expand All @@ -20,8 +22,13 @@ def test_hover():

doc = Document(DOC_URI, DOC)

if LooseVersion(_utils.JEDI_VERSION) >= LooseVersion('0.15.0'):
contents = [{'language': 'python', 'value': 'main()'}, 'hello world']
else:
contents = 'main()\n\nhello world'

assert {
'contents': [{'language': 'python', 'value': 'main()'}, 'hello world']
'contents': contents
} == pyls_hover(doc, hov_position)

assert {'contents': ''} == pyls_hover(doc, no_hov_position)
6 changes: 0 additions & 6 deletions test/plugins/test_symbols.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# Copyright 2017 Palantir Technologies, Inc.
from distutils.version import LooseVersion
import jedi
import pytest

from pyls import uris
from pyls.plugins.symbols import pyls_document_symbols
from pyls.lsp import SymbolKind
Expand All @@ -25,8 +21,6 @@ def main(x):
"""


@pytest.mark.skipif(LooseVersion(jedi.__version__) < LooseVersion('0.14.0'),
reason='This test fails with previous versions of jedi')
def test_symbols(config):
doc = Document(DOC_URI, DOC)
config.update({'plugins': {'jedi_symbols': {'all_scopes': False}}})
Expand Down

0 comments on commit 19b10c4

Please sign in to comment.