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 9
9
def pyls_document_highlight (document , position ):
10
10
usages = document .jedi_script (position ).usages ()
11
11
12
+ def is_valid (definition ):
13
+ return definition .line is not None and definition .column is not None
14
+
12
15
def local_to_document (definition ):
13
16
return not definition .module_path or uris .uri_with (document .uri , path = definition .module_path ) == document .uri
14
17
@@ -18,4 +21,4 @@ def local_to_document(definition):
18
21
'end' : {'line' : d .line - 1 , 'character' : d .column + len (d .name )}
19
22
},
20
23
'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():
30
30
# The second usage is Read
31
31
'kind' : lsp .DocumentHighlightKind .Read
32
32
}]
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