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 clear =n . clear 7local eq =t . eq 8local exec_lua =n . exec_lua 9 10local create_server_definition =t_lsp . create_server_definition 11 12describe ( ':lsp' , function () 13before_each ( function () 14clear () 15exec_lua ( create_server_definition ) 16exec_lua ( function () 17local server =_G . _create_server () 18vim . lsp . config ( 'dummy' , { 19filetypes ={ 'lua' } , 20cmd =server . cmd , 21} ) 22vim . cmd ( 'set ft=lua' ) 23end ) 24end ) 25 26it ( 'fails if runtime is missing/broken' , function () 27clear { 28args_rm ={ '-u' } , 29args ={ '-u' , 'NONE' } , 30env ={ VIMRUNTIME ='non-existent' } , 31} 32t . matches ( 33[[.*module 'vim%.lsp' not found:]] , 34vim . split ( t . pcall_err ( n . command , 'lsp enable dummy' ), '\n' )[ 1 ] 35) 36end ) 37 38for _ , test_with_arguments in ipairs ( { true , false } ) do 39local test_message_suffix , lsp_command_suffix 40if test_with_arguments then 41test_message_suffix =' with arguments' 42lsp_command_suffix =' dummy' 43else 44test_message_suffix =' without arguments' 45lsp_command_suffix ='' 46end 47 48it ( 'enable' .. test_message_suffix , function () 49local is_enabled =exec_lua ( function () 50vim . cmd ( 'lsp enable' .. lsp_command_suffix ) 51return vim . lsp . is_enabled ( 'dummy' ) 52end ) 53eq ( true , is_enabled ) 54end ) 55 56it ( 'disable' .. test_message_suffix , function () 57local is_enabled =exec_lua ( function () 58vim . lsp . enable ( 'dummy' ) 59vim . cmd ( 'lsp disable' .. lsp_command_suffix ) 60return vim . lsp . is_enabled ( 'dummy' ) 61end ) 62eq ( false , is_enabled ) 63end ) 64 65it ( 'restart' .. test_message_suffix , function () 66--- @type boolean, integer? 67local ids_differ , attached_buffer_count =exec_lua ( function () 68vim . lsp . enable ( 'dummy' ) 69local old_id =vim . lsp . get_clients ()[ 1 ]. id 70 71vim . cmd ( 'lsp restart' .. lsp_command_suffix ) 72return vim . wait ( 1000 , function () 73local new_client =vim . lsp . get_clients ()[ 1 ] 74if new_client == nil then 75return false 76end 77return old_id ~= new_client . id , # new_client . attached_buffers 78end ) 79end ) 80eq ( true , ids_differ ) 81eq ( 1 , attached_buffer_count ) 82end ) 83 84it ( 'stop' .. test_message_suffix , function () 85local running_clients =exec_lua ( function () 86vim . lsp . enable ( 'dummy' ) 87vim . cmd ( 'lsp stop' .. lsp_command_suffix ) 88vim . wait ( 1000 , function () 89return # vim . lsp . get_clients () == 0 90end ) 91return # vim . lsp . get_clients () 92end ) 93eq ( 0 , running_clients ) 94end ) 95end 96 97it ( 'subcommand completion' , function () 98local completions =exec_lua ( function () 99return vim . fn . getcompletion ( 'lsp ' , 'cmdline' ) 100end ) 101eq ( { 'disable' , 'enable' , 'restart' , 'stop' } , completions ) 102end ) 103 104it ( 'argument completion' , function () 105local completions =exec_lua ( function () 106return vim . fn . getcompletion ( 'lsp enable ' , 'cmdline' ) 107end ) 108eq ( { 'dummy' } , completions ) 109end ) 110 111it ( 'argument completion with spaces' , function () 112local cmd_length =exec_lua ( function () 113local server =_G . _create_server () 114vim . lsp . config ( 'client name with space' , { 115cmd =server . cmd , 116} ) 117local completion =vim . fn . getcompletion ( 'lsp enable cl ' , 'cmdline' )[ 1 ] 118return # vim . api . nvim_parse_cmd ( 'lsp enable ' .. completion , {} ). args 119end ) 120eq ( 2 , cmd_length ) 121end ) 122 123it ( 'argument completion with special characters' , function () 124local cmd_length =exec_lua ( function () 125local server =_G . _create_server () 126vim . lsp . config ( 'client"name|with\tsymbols' , { 127cmd =server . cmd , 128} ) 129local completion =vim . fn . getcompletion ( 'lsp enable cl ' , 'cmdline' )[ 1 ] 130return # vim . api . nvim_parse_cmd ( 'lsp enable ' .. completion , {} ). args 131end ) 132eq ( 2 , cmd_length ) 133end ) 134end )