robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
1local t =require ( 'test.testutil' ) 2local n =require ( 'test.functional.testnvim' )() 3local t_lsp =require ( 'test.functional.plugin.lsp.testutil' ) 4 5local describe , it , before_each =t . describe , t . it , t . before_each 6local eq =t . eq 7local exec_lua =n . exec_lua 8local insert =n . insert 9local feed =n . feed 10 11local clear_notrace =t_lsp . clear_notrace 12local create_server_definition =t_lsp . create_server_definition 13 14describe ( 'vim.lsp.linked_editing_range' , function () 15before_each ( function () 16clear_notrace () 17 18insert ( [[ 19hello 20hello 21hello]] ) 22 23exec_lua ( create_server_definition ) 24exec_lua ( function () 25vim . lsp . linked_editing_range . enable () 26 27_G . server =_G . _create_server ( { 28capabilities ={ 29linkedEditingRangeProvider =true , 30} , 31handlers ={ 32[ 'textDocument/linkedEditingRange' ] =function ( _ , _ , callback ) 33callback ( nil , { 34ranges ={ 35{ start ={ line =0 , character =0 } , [ 'end' ] ={ line =0 , character =5 } } , 36{ start ={ line =1 , character =0 } , [ 'end' ] ={ line =1 , character =5 } } , 37{ start ={ line =2 , character =0 } , [ 'end' ] ={ line =2 , character =5 } } , 38} , 39} ) 40end , 41} , 42} ) 43 44_G . server_id =vim . lsp . start ( { name ='dummy' , cmd =_G . server . cmd } ) 45end ) 46end ) 47 48it ( 'initiates linked editing' , function () 49exec_lua ( function () 50local win =vim . api . nvim_get_current_win () 51vim . api . nvim_win_set_cursor ( win , { 1 , 0 } ) 52end ) 53-- Deletion 54feed ( 'ldw' ) 55eq ( 56{ 57'h' , 58'h' , 59'h' , 60} , 61exec_lua ( function () 62return vim . api . nvim_buf_get_lines ( 0 , 0 , - 1 , false ) 63end ) 64) 65-- Insertion 66feed ( 'Apt<Esc>' ) 67eq ( 68{ 69'hpt' , 70'hpt' , 71'hpt' , 72} , 73exec_lua ( function () 74return vim . api . nvim_buf_get_lines ( 0 , 0 , - 1 , false ) 75end ) 76) 77-- Undo/redo 78feed ( '0xx' ) 79eq ( 80{ 81't' , 82't' , 83't' , 84} , 85exec_lua ( function () 86return vim . api . nvim_buf_get_lines ( 0 , 0 , - 1 , false ) 87end ) 88) 89feed ( 'u' ) 90eq ( 91{ 92'pt' , 93'pt' , 94'pt' , 95} , 96exec_lua ( function () 97return vim . api . nvim_buf_get_lines ( 0 , 0 , - 1 , false ) 98end ) 99) 100feed ( 'u' ) 101eq ( 102{ 103'hpt' , 104'hpt' , 105'hpt' , 106} , 107exec_lua ( function () 108return vim . api . nvim_buf_get_lines ( 0 , 0 , - 1 , false ) 109end ) 110) 111feed ( '<C-r><C-r>' ) 112eq ( 113{ 114't' , 115't' , 116't' , 117} , 118exec_lua ( function () 119return vim . api . nvim_buf_get_lines ( 0 , 0 , - 1 , false ) 120end ) 121) 122-- Disabling 123exec_lua ( function () 124vim . lsp . linked_editing_range . enable ( false , { client_id =_G . server_id } ) 125end ) 126feed ( 'Ipp<Esc>' ) 127eq ( 128{ 129'ppt' , 130't' , 131't' , 132} , 133exec_lua ( function () 134return vim . api . nvim_buf_get_lines ( 0 , 0 , - 1 , false ) 135end ) 136) 137end ) 138end )