1
1
# Copyright 2017 Palantir Technologies, Inc.
2
2
import os
3
3
4
- from pyls import uris
4
+ from pyls import uris , lsp
5
5
from pyls .workspace import Document
6
6
from pyls .plugins .jedi_completion import pyls_completions as pyls_jedi_completions
7
7
from pyls .plugins .rope_completion import pyls_completions as pyls_rope_completions
@@ -26,7 +26,12 @@ class Hello():
26
26
def world(self):
27
27
return None
28
28
29
+ def everyone(self, a, b, c=None, d=2):
30
+ pass
31
+
29
32
print Hello().world
33
+
34
+ print Hello().every
30
35
"""
31
36
32
37
@@ -37,17 +42,17 @@ def test_rope_import_completion(config, workspace):
37
42
assert items is None
38
43
39
44
40
- def test_jedi_completion ():
45
+ def test_jedi_completion (config ):
41
46
# Over 'i' in os.path.isabs(...)
42
47
com_position = {'line' : 1 , 'character' : 15 }
43
48
doc = Document (DOC_URI , DOC )
44
- items = pyls_jedi_completions (doc , com_position )
49
+ items = pyls_jedi_completions (config , doc , com_position )
45
50
46
51
assert items
47
52
assert items [0 ]['label' ] == 'isabs(s)'
48
53
49
54
# Test we don't throw with big character
50
- pyls_jedi_completions (doc , {'line' : 1 , 'character' : 1000 })
55
+ pyls_jedi_completions (config , doc , {'line' : 1 , 'character' : 1000 })
51
56
52
57
53
58
def test_rope_completion (config , workspace ):
@@ -61,25 +66,46 @@ def test_rope_completion(config, workspace):
61
66
assert items [0 ]['label' ] == 'isabs'
62
67
63
68
64
- def test_jedi_completion_ordering ():
69
+ def test_jedi_completion_ordering (config ):
65
70
# Over the blank line
66
71
com_position = {'line' : 8 , 'character' : 0 }
67
72
doc = Document (DOC_URI , DOC )
68
- completions = pyls_jedi_completions (doc , com_position )
73
+ completions = pyls_jedi_completions (config , doc , com_position )
69
74
70
75
items = {c ['label' ]: c ['sortText' ] for c in completions }
71
76
72
77
# And that 'hidden' functions come after unhidden ones
73
78
assert items ['hello()' ] < items ['_a_hello()' ]
74
79
75
80
76
- def test_jedi_property_completion ():
81
+ def test_jedi_property_completion (config ):
77
82
# Over the 'w' in 'print Hello().world'
78
- com_position = {'line' : 15 , 'character' : 15 }
83
+ com_position = {'line' : 18 , 'character' : 15 }
79
84
doc = Document (DOC_URI , DOC )
80
- completions = pyls_jedi_completions (doc , com_position )
85
+ completions = pyls_jedi_completions (config , doc , com_position )
81
86
82
87
items = {c ['label' ]: c ['sortText' ] for c in completions }
83
88
84
89
# Ensure we can complete the 'world' property
85
90
assert 'world' in items
91
+
92
+
93
+ def test_jedi_method_completion (config ):
94
+ # Over the 'y' in 'print Hello().every'
95
+ com_position = {'line' : 20 , 'character' : 19 }
96
+ doc = Document (DOC_URI , DOC )
97
+
98
+ completions = pyls_jedi_completions (config , doc , com_position )
99
+ everyone_method = [completion for completion in completions if completion ['label' ] == 'everyone(a, b, c, d)' ][0 ]
100
+
101
+ assert everyone_method ['insertTextFormat' ] == lsp .InsertTextFormat .Snippet
102
+ assert everyone_method ['insertText' ] == 'everyone(${1:a}, ${2:b}, ${3:c}, ${4:d})$0'
103
+
104
+ # Disable param snippets
105
+ config .update ({'plugins' : {'jedi_completion' : {'include_params' : False }}})
106
+
107
+ completions = pyls_jedi_completions (config , doc , com_position )
108
+ every
A5C0
one_method = [completion for completion in completions if completion ['label' ] == 'everyone(a, b, c, d)' ][0 ]
109
+
110
+ assert 'insertTextFormat' not in everyone_method
111
+ assert everyone_method ['insertText' ] == 'everyone'
0 commit comments