File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change 99def 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 )]
Original file line number Diff line number Diff 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+ }]
You can’t perform that action at this time.
0 commit comments