@@ -261,4 +261,87 @@ describe("LSP renaming", function()
261
261
end )
262
262
end )
263
263
end )
264
+
265
+ describe (" LSP changes and documentChanges" , function ()
266
+ local err_spy = nil
267
+ local buf_request_all_spy = nil
268
+ local make_position_params_spy = nil
269
+ local get_client_by_id_spy = nil
270
+ local apply_workspace_edit_spy = nil
271
+ local get_clients = nil
272
+
273
+ before_each (function ()
274
+ textcase .setup ({})
275
+
276
+ local buf = vim .api .nvim_create_buf (false , true )
277
+ vim .api .nvim_command (" buffer " .. buf )
278
+
279
+ err_spy = spy .new (function () end )
280
+ get_client_by_id_spy = spy .new (function (id )
281
+ assert (id == " 1" , " Bad client id" )
282
+ return {
283
+ id = 1 ,
284
+ offset_encoding = " utf-8" ,
285
+ }
286
+ end )
287
+ buf_request_all_spy = spy .new (function (buffer , method , params , callback )
288
+ callback (buf_request_all_results )
289
+ end )
290
+ make_position_params_spy = spy .new (function ()
291
+ return {}
292
+ end )
293
+ apply_workspace_edit_spy = spy .new (function ()
294
+ return {}
295
+ end )
296
+ get_clients = function ()
297
+ return {
298
+ {
299
+ supports_method = function ()
300
+ return true
301
+ end ,
302
+ },
303
+ }
304
+ end
305
+
306
+ vim .api .nvim_err_writeln = err_spy
307
+ vim .lsp .get_active_clients = get_clients
308
+ vim .lsp .get_client_by_id = get_client_by_id_spy
309
+ vim .lsp .buf_request_all = buf_request_all_spy
310
+ vim .lsp .util .make_position_params = make_position_params_spy
311
+ vim .lsp .util .apply_workspace_edit = apply_workspace_edit_spy
312
+ end )
313
+
314
+ after_each (function ()
315
+ vim .api .nvim_err_writeln = err_fn
316
+ vim .lsp .get_active_clients = get_active_clients_fn
317
+ vim .lsp .get_client_by_id = get_client_by_id_fn
318
+ vim .lsp .buf_request_all = buf_request_all_fn
319
+ vim .lsp .util .make_position_params = make_position_params_fn
320
+ vim .lsp .util .apply_workspace_edit = apply_workspace_edit_fn
321
+ end )
322
+
323
+ it (" should count `documentChanges` if it is set instead of `changes`" , function ()
324
+ buf_request_all_results = {}
325
+ buf_request_all_results [" 1" ] = {
326
+ result = {
327
+ documentChanges = {
328
+ { " document change 1" },
329
+ { " document change 2" },
330
+ },
331
+ },
332
+ }
333
+ vim .api .nvim_buf_set_lines (0 , 0 , - 1 , true , { " plain text" })
334
+
335
+ test_helpers .execute_keys (" <CMD>lua require('textcase').lsp_rename('to_upper_case')<CR>" )
336
+
337
+ assert .spy (buf_request_all_spy ).was .called_with (0 , " textDocument/rename" , match ._ , match ._ )
338
+ assert .spy (apply_workspace_edit_spy ).was .called_with ({
339
+ documentChanges = {
340
+ { " document change 1" },
341
+ { " document change 2" },
342
+ },
343
+ }, " utf-8" )
344
+ assert .spy (err_spy ).was .not_called ()
345
+ end )
346
+ end )
264
347
end )
0 commit comments