11# Copyright 2017 Palantir Technologies, Inc.
22import os
33
4- from pyls import uris
4+ from pyls import uris , lsp
55from pyls .workspace import Document
66from pyls .plugins .jedi_completion import pyls_completions as pyls_jedi_completions
77from pyls .plugins .rope_completion import pyls_completions as pyls_rope_completions
@@ -26,7 +26,12 @@ class Hello():
2626 def world(self):
2727 return None
2828
29+ def everyone(self, a, b, c=None, d=2):
30+ pass
31+
2932print Hello().world
33+
34+ print Hello().every
3035"""
3136
3237
@@ -37,17 +42,17 @@ def test_rope_import_completion(config, workspace):
3742 assert items is None
3843
3944
40- def test_jedi_completion ():
45+ def test_jedi_completion (config ):
4146 # Over 'i' in os.path.isabs(...)
4247 com_position = {'line' : 1 , 'character' : 15 }
4348 doc = Document (DOC_URI , DOC )
44- items = pyls_jedi_completions (doc , com_position )
49+ items = pyls_jedi_completions (config , doc , com_position )
4550
4651 assert items
4752 assert items [0 ]['label' ] == 'isabs(s)'
4853
4954 # 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 })
5156
5257
5358def test_rope_completion (config , workspace ):
@@ -61,25 +66,46 @@ def test_rope_completion(config, workspace):
6166 assert items [0 ]['label' ] == 'isabs'
6267
6368
64- def test_jedi_completion_ordering ():
69+ def test_jedi_completion_ordering (config ):
6570 # Over the blank line
6671 com_position = {'line' : 8 , 'character' : 0 }
6772 doc = Document (DOC_URI , DOC )
68- completions = pyls_jedi_completions (doc , com_position )
73+ completions = pyls_jedi_completions (config , doc , com_position )
6974
7075 items = {c ['label' ]: c ['sortText' ] for c in completions }
7176
7277 # And that 'hidden' functions come after unhidden ones
7378 assert items ['hello()' ] < items ['_a_hello()' ]
7479
7580
76- def test_jedi_property_completion ():
81+ def test_jedi_property_completion (config ):
7782 # Over the 'w' in 'print Hello().world'
78- com_position = {'line' : 15 , 'character' : 15 }
83+ com_position = {'line' : 18 , 'character' : 15 }
7984 doc = Document (DOC_URI , DOC )
80- completions = pyls_jedi_completions (doc , com_position )
85+ completions = pyls_jedi_completions (config , doc , com_position )
8186
8287 items = {c ['label' ]: c ['sortText' ] for c in completions }
8388
8489 # Ensure we can complete the 'world' property
8590 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+ everyone_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