8000 skip invalid definition to fix #362 (#364) · mirror-dump/python-lsp-server@077e1ae · GitHub
[go: up one dir, main page]

Skip to content

Commit 077e1ae

Browse files
pixystonegatesn
authored andcommitted
skip invalid definition to fix python-lsp#362 (python-lsp#364)
1 parent d8eb65f commit 077e1ae

File tree

2 files changed

+28
-1
lines changed
Collapse file tree

2 files changed

+28
-1
lines changed

pyls/plugins/highlight.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
def pyls_document_highlight(document, position):
1010
usages = document.jedi_script(position).usages()
1111

12+
def is_valid(definition):
13+
return definition.line is not None and definition.column is not None
14+
1215
def local_to_document(definition):
1316
return not definition.module_path or uris.uri_with(document.uri, path=definition.module_path) == document.uri
1417

@@ -18,4 +21,4 @@ def local_to_document(definition):
1821
'end': {'line': d.line - 1, 'character': d.column + len(d.name)}
1922
},
2023
'kind': lsp.DocumentHighlightKind.Write if d.is_definition() else lsp.DocumentHighlightKind.Read
21-
} for d in usages if local_to_document(d)]
24+
} for d in usages if is_valid(d) and local_to_document(d)]

test/plugins/test_highlight.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,27 @@ def test_highlight():
3030
# The second usage is Read
3131
'kind': lsp.DocumentHighlightKind.Read
3232
}]
33+
34+
35+
SYS_DOC = '''import sys
36+
print sys.path
37+
'''
38+
39+
40+
def test_sys_highlight():
41+
cursor_pos = {'line': 0, 'character': 8}
42+
43+
doc = Document(DOC_URI, SYS_DOC)
44+
assert pyls_document_highlight(doc, cursor_pos) == [{
45+
'range': {
46+
'start': {'line': 0, 'character': 7},
47+
'end': {'line': 0, 'character': 10}
48+
},
49+
'kind': lsp.DocumentHighlightKind.Write
50+
}, {
51+
'range': {
52+
'start': {'line': 1, 'character': 6},
53+
'end': {'line': 1, 'character': 9}
54+
},
55+
'kind': lsp.DocumentHighlightKind.Read
56+
}]

0 commit comments

Comments
 (0)
0