77
88from pylsp import uris
99from pylsp .plugins .jedi_rename import pylsp_rename
10+ from pylsp .text_edit import apply_text_edits
1011from pylsp .workspace import Document
1112
1213DOC_NAME = "test1.py"
@@ -33,6 +34,32 @@ def tmp_workspace(temp_workspace_factory):
3334 )
3435
3536
37+ @pytest .mark .parametrize (
38+ ("source" , "end" ),
39+ [
40+ ("foo = 12" , {"line" : 0 , "character" : 8 }),
41+ ("foo = 12\n foo" , {"line" : 1 , "character" : 3 }),
42+ ("foo = 12\r \n foo" , {"line" : 1 , "character" : 3 }),
43+ ("foo = 12\n " , {"line" : 1 , "character" : 0 }),
44+ ('foo = "\U0001f600 \u2028 "' , {"line" : 0 , "character" : 11 }),
45+ ],
46+ )
47+ def test_jedi_rename_replaces_entire_document (
48+ temp_workspace_factory , config , source , end
49+ ):
50+ workspace = temp_workspace_factory ({"rename.py" : source })
51+ uri = uris .from_fs_path (os .path .join (workspace .root_path , "rename.py" ))
52+ doc = workspace .get_document (uri )
53+
54+ result = pylsp_rename (
55+ config , workspace , doc , {"line" : 0 , "character" : 0 }, "renamed"
56+ )
57+
58+ edits = result ["documentChanges" ][0 ]["edits" ]
59+ assert apply_text_edits (doc , edits ) == source .replace ("foo" , "renamed" )
60+ assert edits [0 ]["range" ]["end" ] == end
61+
62+
3663def test_jedi_rename (tmp_workspace , config ) -> None :
3764 # rename the `Test1` class
3865 position = {"line" : 0 , "character" : 6 }
@@ -98,7 +125,7 @@ def test_jedi_rename(tmp_workspace, config) -> None:
98125 {
99126 "range" : {
100127 "start" : {"line" : 0 , "character" : 0 },
101- "end" : {"line" : 0 , "character" : 0 },
128+ "end" : {"line" : 0 , "character" : 8 },
102129 },
103130 "newText" : "bar = 12" ,
104131 }
0 commit comments