Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pyls/plugins/hover.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ def pyls_hover(document, position):
# Find first exact matching definition
definition = next((x for x in definitions if x.name == word), None)

# Ensure a definition is used if only one is available
# even if the word doesn't match. An example of this case is 'np'
# where 'numpy' doesn't match with 'np'. Same for NumPy ufuncs
if len(definitions) == 1:
definition = definitions[0]

if not definition:
return {'contents': ''}

Expand Down
39 changes: 39 additions & 0 deletions test/plugins/test_hover.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,45 @@ def main():
pass
"""

NUMPY_DOC = """

import numpy as np
np.sin

"""


def test_numpy_hover():
# Over the blank line
no_hov_position = {'line': 1, 'character': 0}
# Over 'numpy' in import numpy as np
numpy_hov_position_1 = {'line': 2, 'character': 8}
# Over 'np' in import numpy as np
numpy_hov_position_2 = {'line': 2, 'character': 17}
# Over 'np' in np.sin
numpy_hov_position_3 = {'line': 3, 'character': 1}
# Over 'sin' in np.sin
numpy_sin_hov_position = {'line': 3, 'character': 4}

doc = Document(DOC_URI, NUMPY_DOC)

if LooseVersion(_utils.JEDI_VERSION) >= LooseVersion('0.15.0'):
contents = ''
assert contents in pyls_hover(doc, no_hov_position)['contents']

contents = 'NumPy\n=====\n\nProvides\n'
assert contents in pyls_hover(doc, numpy_hov_position_1)['contents'][0]

contents = 'NumPy\n=====\n\nProvides\n'
assert contents in pyls_hover(doc, numpy_hov_position_2)['contents'][0]

contents = 'NumPy\n=====\n\nProvides\n'
assert contents in pyls_hover(doc, numpy_hov_position_3)['contents'][0]

contents = 'Trigonometric sine, element-wise.\n\n'
assert contents in pyls_hover(
doc, numpy_sin_hov_position)['contents'][0]


def test_hover():
# Over 'main' in def main():
Expand Down