robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
1local t =require ( 'test.testutil' ) 2local n =require ( 'test.functional.testnvim' )() 3local t_lsp =require ( 'test.functional.plugin.lsp.testutil' ) 4local Screen =require ( 'test.functional.ui.screen' ) 5 6local describe , it , before_each =t . describe , t . it , t . before_each 7local dedent =t . dedent 8local exec_lua =n . exec_lua 9local insert =n . insert 10 11local clear_notrace =t_lsp . clear_notrace 12local create_server_definition =t_lsp . create_server_definition 13 14describe ( 'vim.lsp.selection_range' , function () 15local text =dedent ( [[ 16hello 17hello 18hello 19hello 20hello]] ) 21 22--- @type test.functional.ui.screen 23local screen 24 25before_each ( function () 26clear_notrace () 27screen =Screen . new ( 50 , 9 ) 28 29exec_lua ( create_server_definition ) 30exec_lua ( function () 31_G . server =_G . _create_server ( { 32capabilities ={ 33selectionRangeProvider =true , 34} , 35handlers ={ 36[ 'textDocument/selectionRange' ] =function ( _ , _ , callback ) 37callback ( nil , { 38{ 39range ={ 40start ={ line =2 , character =0 } , 41[ 'end' ] ={ line =2 , character =5 } , 42} , 43parent ={ 44range ={ 45start ={ line =1 , character =0 } , 46[ 'end' ] ={ line =3 , character =5 } , 47} , 48parent ={ 49range ={ 50start ={ line =0 , character =0 } , 51[ 'end' ] ={ line =4 , character =5 } , 52} , 53parent =nil , 54} , 55} , 56} , 57} ) 58end , 59} , 60} ) 61 62return vim . lsp . start ( { name ='dummy' , cmd =_G . server . cmd } ) 63end ) 64 65insert ( text ) 66end ) 67 68it ( 'selects ranges' , function () 69-- Initial range 70exec_lua ( function () 71local win =vim . api . nvim_get_current_win () 72vim . api . nvim_win_set_cursor ( win , { 3 , 0 } ) 73vim . lsp . buf . selection_range ( 1 ) 74end ) 75 76screen : expect ( [[ 77hello |*2 78{17:hell^o} | 79hello |*2 80{1:~ }|*3 81{5:-- VISUAL --} | 82]] ) 83 84-- Outermost range 85exec_lua ( function () 86vim . lsp . buf . selection_range ( 99 ) 87end ) 88 89screen : expect ( [[ 90{17:hello} |*4 91{17:hell^o} | 92{1:~ }|*3 93{5:-- VISUAL --} | 94]] ) 95 96-- Back to innermost 97exec_lua ( function () 98vim . lsp . buf . selection_range ( - 99 ) 99end ) 100 101screen : expect ( [[ 102hello |*2 103{17:hell^o} | 104hello |*2 105{1:~ }|*3 106{5:-- VISUAL --} | 107]] ) 108 109-- Middle range 110exec_lua ( function () 111vim . lsp . buf . selection_range ( 1 ) 112end ) 113 114screen : expect ( [[ 115hello | 116{17:hello} |*2 117{17:hell^o} | 118hello | 119{1:~ }|*3 120{5:-- VISUAL --} | 121]] ) 122end ) 123end )