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
5 changes: 4 additions & 1 deletion pyls/plugins/highlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
def pyls_document_highlight(document, position):
usages = document.jedi_script(position).usages()

def is_valid(definition):
return definition.line is not None and definition.column is not None

def local_to_document(definition):
return not definition.module_path or uris.uri_with(document.uri, path=definition.module_path) == document.uri

Expand All @@ -18,4 +21,4 @@ def local_to_document(definition):
'end': {'line': d.line - 1, 'character': d.column + len(d.name)}
},
'kind': lsp.DocumentHighlightKind.Write if d.is_definition() else lsp.DocumentHighlightKind.Read
} for d in usages if local_to_document(d)]
} for d in usages if is_valid(d) and local_to_document(d)]
24 changes: 24 additions & 0 deletions test/plugins/test_highlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,27 @@ def test_highlight():
# The second usage is Read
'kind': lsp.DocumentHighlightKind.Read
}]


SYS_DOC = '''import sys
print sys.path
'''


def test_sys_highlight():
cursor_pos = {'line': 0, 'character': 8}

doc = Document(DOC_URI, SYS_DOC)
assert pyls_document_highlight(doc, cursor_pos) == [{
'range': {
'start': {'line': 0, 'character': 7},
'end': {'line': 0, 'character': 10}
},
'kind': lsp.DocumentHighlightKind.Write
}, {
'range': {
'start': {'line': 1, 'character': 6},
'end': {'line': 1, 'character': 9}
},
'kind': lsp.DocumentHighlightKind.Read
}]