robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
1local t =require ( 'test.testutil' ) 2local n =require ( 'test.functional.testnvim' )() 3local Screen =require ( 'test.functional.ui.screen' ) 4 5local t_lsp =require ( 'test.functional.plugin.lsp.testutil' ) 6 7local describe , it , before_each , after_each =t . describe , t . it , t . before_each , t . after_each 8local feed =n . feed 9local eq =t . eq 10local exec_lua =n . exec_lua 11local pcall_err =t . pcall_err 12local stop =n . stop 13local read_file =t . read_file 14local write_file =t . write_file 15local api =n . api 16local is_os =t . is_os 17local skip =t . skip 18local command =n . command 19local fn =n . fn 20local tmpname =t . tmpname 21 22local clear_notrace =t_lsp . clear_notrace 23local create_server_definition =t_lsp . create_server_definition 24 25-- TODO(justinmk): hangs on Windows https://github.com/neovim/neovim/pull/11837 26if skip ( is_os ( 'win' )) then 27return 28end 29 30describe ( 'vim.lsp.util' , function () 31before_each ( function () 32clear_notrace () 33end ) 34 35after_each ( function () 36stop () 37exec_lua ( function () 38vim . iter ( vim . lsp . get_clients ( { _uninitialized =true } )): each ( function ( client ) 39client : stop ( true ) 40end ) 41end ) 42api . nvim_exec_autocmds ( 'VimLeavePre' , { modeline =false } ) 43end ) 44 45describe ( 'lsp.util.rename' , function () 46local pathsep =n . get_pathsep () 47 48it ( 'can rename an existing file' , function () 49local old =tmpname () 50write_file ( old , 'Test content' ) 51local new =tmpname ( false ) 52local lines =exec_lua ( function () 53local old_bufnr =vim . fn . bufadd ( old ) 54vim . fn . bufload ( old_bufnr ) 55vim . lsp . util . rename ( old , new ) 56-- the existing buffer is renamed in-place and its contents is kept 57local new_bufnr =vim . fn . bufadd ( new ) 58vim . fn . bufload ( new_bufnr ) 59return ( old_bufnr == new_bufnr ) and vim . api . nvim_buf_get_lines ( new_bufnr , 0 , - 1 , true ) 60end ) 61eq ( { 'Test content' } , lines ) 62local exists =vim . uv . fs_stat ( old ) ~= nil 63eq ( false , exists ) 64exists =vim . uv . fs_stat ( new ) ~= nil 65eq ( true , exists ) 66os . remove ( new ) 67end ) 68 69it ( 'can rename a directory' , function () 70-- only reserve the name, file must not exist for the test scenario 71local old_dir =tmpname ( false ) 72local new_dir =tmpname ( false ) 73 74n . mkdir_p ( old_dir ) 75 76local file ='file.txt' 77write_file ( old_dir .. pathsep .. file , 'Test content' ) 78 79local lines =exec_lua ( function () 80local old_bufnr =vim . fn . bufadd ( old_dir .. pathsep .. file ) 81vim . fn . bufload ( old_bufnr ) 82vim . lsp . util . rename ( old_dir , new_dir ) 83-- the existing buffer is renamed in-place and its contents is kept 84local new_bufnr =vim . fn . bufadd ( new_dir .. pathsep .. file ) 85vim . fn . bufload ( new_bufnr ) 86return ( old_bufnr == new_bufnr ) and vim . api . nvim_buf_get_lines ( new_bufnr , 0 , - 1 , true ) 87end ) 88eq ( { 'Test content' } , lines ) 89eq ( false , vim . uv . fs_stat ( old_dir ) ~= nil ) 90eq ( true , vim . uv . fs_stat ( new_dir ) ~= nil ) 91eq ( true , vim . uv . fs_stat ( new_dir .. pathsep .. file ) ~= nil ) 92 93os . remove ( new_dir ) 94end ) 95 96it ( 'does not touch buffers that do not match path prefix' , function () 97local old =tmpname ( false ) 98local new =tmpname ( false ) 99n . mkdir_p ( old ) 100 101eq ( 102true , 103exec_lua ( function () 104local old_prefixed ='explorer://' .. old 105local old_suffixed =old .. '.bak' 106local new_prefixed ='explorer://' .. new 107local new_suffixed =new .. '.bak' 108 109local old_prefixed_buf =vim . fn . bufadd ( old_prefixed ) 110local old_suffixed_buf =vim . fn . bufadd ( old_suffixed ) 111local new_prefixed_buf =vim . fn . bufadd ( new_prefixed ) 112local new_suffixed_buf =vim . fn . bufadd ( new_suffixed ) 113 114vim . lsp . util . rename ( old , new ) 115 116return vim . api . nvim_buf_is_valid ( old_prefixed_buf ) 117and vim . api . nvim_buf_is_valid ( old_suffixed_buf ) 118and vim . api . nvim_buf_is_valid ( new_prefixed_buf ) 119and vim . api . nvim_buf_is_valid ( new_suffixed_buf ) 120and vim . api . nvim_buf_get_name ( old_prefixed_buf ) == old_prefixed 121and vim . api . nvim_buf_get_name ( old_suffixed_buf ) == old_suffixed 122and vim . api . nvim_buf_get_name ( new_prefixed_buf ) == new_prefixed 123and vim . api . nvim_buf_get_name ( new_suffixed_buf ) == new_suffixed 124end ) 125) 126 127os . remove ( new ) 128end ) 129 130it ( 131'does not rename file if target exists and ignoreIfExists is set or overwrite is false' , 132function () 133local old =tmpname () 134write_file ( old , 'Old File' ) 135local new =tmpname () 136write_file ( new , 'New file' ) 137 138exec_lua ( function () 139vim . lsp . util . rename ( old , new , { ignoreIfExists =true } ) 140end ) 141 142eq ( true , vim . uv . fs_stat ( old ) ~= nil ) 143eq ( 'New file' , read_file ( new )) 144 145exec_lua ( function () 146vim . lsp . util . rename ( old , new , { overwrite =false } ) 147end ) 148 149eq ( true , vim . uv . fs_stat ( old ) ~= nil ) 150eq ( 'New file' , read_file ( new )) 151end 152) 153 154it ( 'maintains undo information for loaded buffer' , function () 155local old =tmpname () 156write_file ( old , 'line' ) 157local new =tmpname ( false ) 158 159local undo_kept =exec_lua ( function () 160vim . opt . undofile =true 161vim . cmd . edit ( old ) 162vim . cmd . normal ( 'dd' ) 163vim . cmd . write () 164local undotree =vim . fn . undotree () 165vim . lsp . util . rename ( old , new ) 166-- Renaming uses :saveas, which updates the "last write" information. 167-- Other than that, the undotree should remain the same. 168undotree . save_cur =undotree . save_cur + 1 169undotree . save_last =undotree . save_last + 1 170undotree . entries [ 1 ]. save =undotree . entries [ 1 ]. save + 1 171return vim . deep_equal ( undotree , vim . fn . undotree ()) 172end ) 173eq ( false , vim . uv . fs_stat ( old ) ~= nil ) 174eq ( true , vim . uv . fs_stat ( new ) ~= nil ) 175eq ( true , undo_kept ) 176end ) 177 178it ( 'maintains undo information for unloaded buffer' , function () 179local old =tmpname () 180write_file ( old , 'line' ) 181local new =tmpname ( false ) 182 183local undo_kept =exec_lua ( function () 184vim . opt . undofile =true 185vim . cmd . split ( old ) 186vim . cmd . normal ( 'dd' ) 187vim . cmd . write () 188local undotree =vim . fn . undotree () 189vim . cmd . bdelete () 190vim . lsp . util . rename ( old , new ) 191vim . cmd . edit ( new ) 192return vim . deep_equal ( undotree , vim . fn . undotree ()) 193end ) 194eq ( false , vim . uv . fs_stat ( old ) ~= nil ) 195eq ( true , vim . uv . fs_stat ( new ) ~= nil ) 196eq ( true , undo_kept ) 197end ) 198 199it ( 'does not rename file when it conflicts with a buffer without file' , function () 200local old =tmpname () 201write_file ( old , 'Old File' ) 202local new =tmpname ( false ) 203 204local lines =exec_lua ( function () 205local old_buf =vim . fn . bufadd ( old ) 206vim . fn . bufload ( old_buf ) 207local conflict_buf =vim . api . nvim_create_buf ( true , false ) 208vim . api . nvim_buf_set_name ( conflict_buf , new ) 209vim . api . nvim_buf_set_lines ( conflict_buf , 0 , - 1 , true , { 'conflict' } ) 210vim . api . nvim_win_set_buf ( 0 , conflict_buf ) 211vim . lsp . util . rename ( old , new ) 212return vim . api . nvim_buf_get_lines ( conflict_buf , 0 , - 1 , true ) 213end ) 214eq ( { 'conflict' } , lines ) 215eq ( 'Old File' , read_file ( old )) 216end ) 217 218it ( 'does override target if overwrite is true' , function () 219local old =tmpname () 220write_file ( old , 'Old file' ) 221local new =tmpname () 222write_file ( new , 'New file' ) 223exec_lua ( function () 224vim . lsp . util . rename ( old , new , { overwrite =true } ) 225end ) 226 227eq ( false , vim . uv . fs_stat ( old ) ~= nil ) 228eq ( true , vim . uv . fs_stat ( new ) ~= nil ) 229eq ( 'Old file' , read_file ( new )) 230end ) 231end ) 232 233describe ( 'lsp.util.locations_to_items' , function () 234it ( 'convert Location[] to items' , function () 235local expected_template ={ 236{ 237filename ='/fake/uri' , 238lnum =1 , 239end_lnum =2 , 240col =3 , 241end_col =4 , 242text ='testing' , 243user_data ={} , 244} , 245} 246local test_params ={ 247{ 248{ 249uri ='file:///fake/uri' , 250range ={ 251start ={ line =0 , character =2 } , 252[ 'end' ] ={ line =1 , character =3 } , 253} , 254} , 255} , 256{ 257{ 258uri ='file:///fake/uri' , 259range ={ 260start ={ line =0 , character =2 } , 261-- LSP spec: if character > line length, default to the line length. 262[ 'end' ] ={ line =1 , character =10000 } , 263} , 264} , 265} , 266} 267for _ , params in ipairs ( test_params ) do 268local actual =exec_lua ( function ( params0 ) 269local bufnr =vim . uri_to_bufnr ( 'file:///fake/uri' ) 270local lines ={ 'testing' , '123' } 271vim . api . nvim_buf_set_lines ( bufnr , 0 , 1 , false , lines ) 272return vim . lsp . util . locations_to_items ( params0 , 'utf-16' ) 273end , params ) 274local expected =vim . deepcopy ( expected_template ) 275expected [ 1 ]. user_data =params [ 1 ] 276eq ( expected , actual ) 277end 278end ) 279 280it ( 'convert LocationLink[] to items' , function () 281local expected ={ 282{ 283filename ='/fake/uri' , 284lnum =1 , 285end_lnum =1 , 286col =3 , 287end_col =4 , 288text ='testing' , 289user_data ={ 290targetUri ='file:///fake/uri' , 291targetRange ={ 292start ={ line =0 , character =2 } , 293[ 'end' ] ={ line =0 , character =3 } , 294} , 295targetSelectionRange ={ 296start ={ line =0 , character =2 } , 297[ 'end' ] ={ line =0 , character =3 } , 298} , 299} , 300} , 301} 302local actual =exec_lua ( function () 303local bufnr =vim . uri_to_bufnr ( 'file:///fake/uri' ) 304local lines ={ 'testing' , '123' } 305vim . api . nvim_buf_set_lines ( bufnr , 0 , 1 , false , lines ) 306local locations ={ 307{ 308targetUri =vim . uri_from_bufnr ( bufnr ), 309targetRange ={ 310start ={ line =0 , character =2 } , 311[ 'end' ] ={ line =0 , character =3 } , 312} , 313targetSelectionRange ={ 314start ={ line =0 , character =2 } , 315[ 'end' ] ={ line =0 , character =3 } , 316} , 317} , 318} 319return vim . lsp . util . locations_to_items ( locations , 'utf-16' ) 320end ) 321eq ( expected , actual ) 322end ) 323end ) 324 325describe ( 'lsp.util.symbols_to_items' , function () 326describe ( 'convert DocumentSymbol[] to items' , function () 327it ( 'documentSymbol has children' , function () 328local expected ={ 329{ 330col =1 , 331end_col =1 , 332end_lnum =2 , 333filename ='' , 334kind ='File' , 335lnum =2 , 336text ='[File] TestA' , 337} , 338{ 339col =1 , 340end_col =1 , 341end_lnum =4 , 342filename ='' , 343kind ='Module' , 344lnum =4 , 345text ='[Module] TestB' , 346} , 347{ 348col =1 , 349end_col =1 , 350end_lnum =6 , 351filename ='' , 352kind ='Namespace' , 353lnum =6 , 354text ='[Namespace] TestC' , 355} , 356} 357eq ( 358expected , 359exec_lua ( function () 360local doc_syms ={ 361{ 362deprecated =false , 363detail ='A' , 364kind =1 , 365name ='TestA' , 366range ={ 367start ={ 368character =0 , 369line =1 , 370} , 371[ 'end' ] ={ 372character =0 , 373line =2 , 374} , 375} , 376selectionRange ={ 377start ={ 378character =0 , 379line =1 , 380} , 381[ 'end' ] ={ 382character =4 , 383line =1 , 384} , 385} , 386children ={ 387{ 388children ={} , 389deprecated =false , 390detail ='B' , 391kind =2 , 392name ='TestB' , 393range ={ 394start ={ 395character =0 , 396line =3 , 397} , 398[ 'end' ] ={ 399character =0 , 400line =4 , 401} , 402} , 403selectionRange ={ 404start ={ 405character =0 , 406line =3 , 407} , 408[ 'end' ] ={ 409character =4 , 410line =3 , 411} , 412} , 413} , 414} , 415} , 416{ 417deprecated =false , 418detail ='C' , 419kind =3 , 420name ='TestC' , 421range ={ 422start ={ 423character =0 , 424line =5 , 425} , 426[ 'end' ] ={ 427character =0 , 428line =6 , 429} , 430} , 431selectionRange ={ 432start ={ 433character =0 , 434line =5 , 435} , 436[ 'end' ] ={ 437character =4 , 438line =5 , 439} , 440} , 441} , 442} 443return vim . lsp . util . symbols_to_items ( doc_syms , nil , 'utf-16' ) 444end ) 445) 446end ) 447 448it ( 'documentSymbol has no children' , function () 449local expected ={ 450{ 451col =1 , 452end_col =1 , 453end_lnum =2 , 454filename ='' , 455kind ='File' , 456lnum =2 , 457text ='[File] TestA' , 458} , 459{ 460col =1 , 461end_col =1 , 462end_lnum =6 , 463filename ='' , 464kind ='Namespace' , 465lnum =6 , 466text ='[Namespace] TestC' , 467} , 468} 469eq ( 470expected , 471exec_lua ( function () 472local doc_syms ={ 473{ 474deprecated =false , 475detail ='A' , 476kind =1 , 477name ='TestA' , 478range ={ 479start ={ 480character =0 , 481line =1 , 482} , 483[ 'end' ] ={ 484character =0 , 485line =2 , 486} , 487} , 488selectionRange ={ 489start ={ 490character =0 , 491line =1 , 492} , 493[ 'end' ] ={ 494character =4 , 495line =1 , 496} , 497} , 498} , 499{ 500deprecated =false , 501detail ='C' , 502kind =3 , 503name ='TestC' , 504range ={ 505start ={ 506character =0 , 507line =5 , 508} , 509[ 'end' ] ={ 510character =0 , 511line =6 , 512} , 513} , 514selectionRange ={ 515start ={ 516character =0 , 517line =5 , 518} , 519[ 'end' ] ={ 520character =4 , 521line =5 , 522} , 523} , 524} , 525} 526return vim . lsp . util . symbols_to_items ( doc_syms , nil , 'utf-16' ) 527end ) 528) 529end ) 530 531it ( 'handles deprecated items' , function () 532local expected ={ 533{ 534col =1 , 535end_col =1 , 536end_lnum =2 , 537filename ='' , 538kind ='File' , 539lnum =2 , 540text ='[File] TestA (deprecated)' , 541} , 542{ 543col =1 , 544end_col =1 , 545end_lnum =6 , 546filename ='' , 547kind ='Namespace' , 548lnum =6 , 549text ='[Namespace] TestC (deprecated)' , 550} , 551} 552eq ( 553expected , 554exec_lua ( function () 555local doc_syms ={ 556{ 557deprecated =true , 558detail ='A' , 559kind =1 , 560name ='TestA' , 561range ={ 562start ={ 563character =0 , 564line =1 , 565} , 566[ 'end' ] ={ 567character =0 , 568line =2 , 569} , 570} , 571selectionRange ={ 572start ={ 573character =0 , 574line =1 , 575} , 576[ 'end' ] ={ 577character =4 , 578line =1 , 579} , 580} , 581} , 582{ 583detail ='C' , 584kind =3 , 585name ='TestC' , 586range ={ 587start ={ 588character =0 , 589line =5 , 590} , 591[ 'end' ] ={ 592character =0 , 593line =6 , 594} , 595} , 596selectionRange ={ 597start ={ 598character =0 , 599line =5 , 600} , 601[ 'end' ] ={ 602character =4 , 603line =5 , 604} , 605} , 606tags ={ 1 } , -- deprecated 607} , 608} 609return vim . lsp . util . symbols_to_items ( doc_syms , nil , 'utf-16' ) 610end ) 611) 612end ) 613end ) 614 615it ( 'convert SymbolInformation[] to items' , function () 616local expected ={ 617{ 618col =1 , 619end_col =1 , 620end_lnum =3 , 621filename ='/test_a' , 622kind ='File' , 623lnum =2 , 624text ='[File] TestA in TestAContainer' , 625} , 626{ 627col =1 , 628end_col =1 , 629end_lnum =5 , 630filename ='/test_b' , 631kind ='Module' , 632lnum =4 , 633text ='[Module] TestB (deprecated)' , 634} , 635} 636eq ( 637expected , 638exec_lua ( function () 639local sym_info ={ 640{ 641deprecated =false , 642kind =1 , 643name ='TestA' , 644location ={ 645range ={ 646start ={ 647character =0 , 648line =1 , 649} , 650[ 'end' ] ={ 651character =0 , 652line =2 , 653} , 654} , 655uri ='file:///test_a' , 656} , 657containerName ='TestAContainer' , 658} , 659{ 660deprecated =true , 661kind =2 , 662name ='TestB' , 663location ={ 664range ={ 665start ={ 666character =0 , 667line =3 , 668} , 669[ 'end' ] ={ 670character =0 , 671line =4 , 672} , 673} , 674uri ='file:///test_b' , 675} , 676containerName =vim . NIL , 677} , 678} 679return vim . lsp . util . symbols_to_items ( sym_info , nil , 'utf-16' ) 680end ) 681) 682end ) 683end ) 684 685describe ( 'lsp.util.show_document' , function () 686local target_bufnr --- @type integer 687local target_bufnr2 --- @type integer 688 689before_each ( function () 690target_bufnr =exec_lua ( function () 691local bufnr =vim . uri_to_bufnr ( 'file:///fake/uri' ) 692local lines ={ '1st line of text' , 'å å ɧ 汉语 ↥ 🤦 🦄' } 693vim . api . nvim_buf_set_lines ( bufnr , 0 , 1 , false , lines ) 694return bufnr 695end ) 696 697target_bufnr2 =exec_lua ( function () 698local bufnr =vim . uri_to_bufnr ( 'file:///fake/uri2' ) 699local lines ={ '1st line of text' , 'å å ɧ 汉语 ↥ 🤦 🦄' } 700vim . api . nvim_buf_set_lines ( bufnr , 0 , 1 , false , lines ) 701return bufnr 702end ) 703end ) 704 705local location =function ( start_line , start_char , end_line , end_char , second_uri ) 706return { 707uri =second_uri and 'file:///fake/uri2' or 'file:///fake/uri' , 708range ={ 709start ={ line =start_line , character =start_char } , 710[ 'end' ] ={ line =end_line , character =end_char } , 711} , 712} 713end 714 715local show_document =function ( msg , focus , reuse_win ) 716eq ( 717true , 718exec_lua ( 719'return vim.lsp.util.show_document(...)' , 720msg , 721'utf-16' , 722{ reuse_win =reuse_win , focus =focus } 723) 724) 725if focus == true or focus == nil then 726eq ( target_bufnr , fn . bufnr ( '%' )) 727end 728return { 729line =fn . line ( '.' ), 730col =fn . col ( '.' ), 731} 732end 733 734it ( 'jumps to a Location if focus is true' , function () 735local pos =show_document ( location ( 0 , 9 , 0 , 9 ), true , true ) 736eq ( 1 , pos . line ) 737eq ( 10 , pos . col ) 738 739-- expectation: Cursor is placed past EOL (append position) in insert mode 740n . feed ( 'I' ) 741pos =show_document ( location ( 0 , 16 , 0 , 16 ), true , true ) 742eq ( 1 , pos . line ) 743eq ( 17 , pos . col ) 744eq ( 'i' , api . nvim_get_mode (). mode ) 745end ) 746 747it ( 'jumps to a LocationLink' , function () 748local pos =show_document ( { 749targetUri ='file:///fake/uri' , 750targetSelectionRange ={ 751start ={ line =0 , character =4 } , 752[ 'end' ] ={ line =0 , character =4 } , 753} , 754targetRange ={ 755start ={ line =1 , character =5 } , 756[ 'end' ] ={ line =1 , character =5 } , 757} , 758} , true , true ) 759eq ( 1 , pos . line ) 760eq ( 5 , pos . col ) 761end ) 762 763it ( 'jumps to the correct multibyte column' , function () 764local pos =show_document ( location ( 1 , 2 , 1 , 2 ), true , true ) 765eq ( 2 , pos . line ) 766eq ( 4 , pos . col ) 767eq ( 'å' , fn . expand ( '<cword>' )) 768end ) 769 770it ( 'jumps to a Location if focus is true via handler' , function () 771exec_lua ( create_server_definition ) 772local result =exec_lua ( function () 773local server =_G . _create_server () 774local client_id =assert ( vim . lsp . start ( { name ='dummy' , cmd =server . cmd } )) 775local result ={ 776uri ='file:///fake/uri' , 777selection ={ 778start ={ line =0 , character =9 } , 779[ 'end' ] ={ line =0 , character =9 } , 780} , 781takeFocus =true , 782} 783local ctx ={ 784client_id =client_id , 785method ='window/showDocument' , 786} 787vim . lsp . handlers [ 'window/showDocument' ]( nil , result , ctx ) 788vim . lsp . get_client_by_id ( client_id ): stop () 789return { 790cursor =vim . api . nvim_win_get_cursor ( 0 ), 791} 792end ) 793eq ( 1 , result . cursor [ 1 ]) 794eq ( 9 , result . cursor [ 2 ]) 795end ) 796 797it ( 'jumps to a Location if focus not set' , function () 798local pos =show_document ( location ( 0 , 9 , 0 , 9 ), nil , true ) 799eq ( 1 , pos . line ) 800eq ( 10 , pos . col ) 801end ) 802 803it ( 'adds current position to jumplist before jumping' , function () 804api . nvim_win_set_buf ( 0 , target_bufnr ) 805local mark =api . nvim_buf_get_mark ( target_bufnr , "'" ) 806eq ( { 1 , 0 } , mark ) 807 808api . nvim_win_set_cursor ( 0 , { 2 , 3 } ) 809show_document ( location ( 0 , 9 , 0 , 9 ), true , true ) 810 811mark =api . nvim_buf_get_mark ( target_bufnr , "'" ) 812eq ( { 2 , 3 } , mark ) 813end ) 814 815it ( 'does not add current position to jumplist if not focus' , function () 816api . nvim_win_set_buf ( 0 , target_bufnr ) 817local mark =api . nvim_buf_get_mark ( target_bufnr , "'" ) 818eq ( { 1 , 0 } , mark ) 819 820api . nvim_win_set_cursor ( 0 , { 2 , 3 } ) 821show_document ( location ( 0 , 9 , 0 , 9 ), false , true ) 822show_document ( location ( 0 , 9 , 0 , 9 , true ), false , true ) 823 824mark =api . nvim_buf_get_mark ( target_bufnr , "'" ) 825eq ( { 1 , 0 } , mark ) 826end ) 827 828it ( 'does not change cursor position if not focus and not reuse_win' , function () 829api . nvim_win_set_buf ( 0 , target_bufnr ) 830local cursor =api . nvim_win_get_cursor ( 0 ) 831 832show_document ( location ( 0 , 9 , 0 , 9 ), false , false ) 833eq ( cursor , api . nvim_win_get_cursor ( 0 )) 834end ) 835 836it ( 'does not change window if not focus' , function () 837api . nvim_win_set_buf ( 0 , target_bufnr ) 838local win =api . nvim_get_current_win () 839 840-- same document/bufnr 841show_document ( location ( 0 , 9 , 0 , 9 ), false , true ) 842eq ( win , api . nvim_get_current_win ()) 843 844-- different document/bufnr, new window/split 845show_document ( location ( 0 , 9 , 0 , 9 , true ), false , true ) 846eq ( 2 , # api . nvim_list_wins ()) 847eq ( win , api . nvim_get_current_win ()) 848end ) 849 850it ( "respects 'reuse_win' parameter" , function () 851api . nvim_win_set_buf ( 0 , target_bufnr ) 852 853-- does not create a new window if the buffer is already open 854show_document ( location ( 0 , 9 , 0 , 9 ), false , true ) 855eq ( 1 , # api . nvim_list_wins ()) 856 857-- creates a new window even if the buffer is already open 858show_document ( location ( 0 , 9 , 0 , 9 ), false , false ) 859eq ( 2 , # api . nvim_list_wins ()) 860end ) 861 862it ( 'correctly sets the cursor of the split if range is given without focus' , function () 863api . nvim_win_set_buf ( 0 , target_bufnr ) 864 865show_document ( location ( 0 , 9 , 0 , 9 , true ), false , true ) 866 867local wins =api . nvim_list_wins () 868eq ( 2 , # wins ) 869table . sort ( wins ) 870 871eq ( { 1 , 0 } , api . nvim_win_get_cursor ( wins [ 1 ])) 872eq ( { 1 , 9 } , api . nvim_win_get_cursor ( wins [ 2 ])) 873end ) 874 875it ( 'preserves cursor positions when the handler omits selection' , function () 876exec_lua ( create_server_definition ) 877api . nvim_win_set_buf ( 0 , target_bufnr ) 878api . nvim_win_set_cursor ( 0 , { 2 , 3 } ) 879 880exec_lua ( function () 881vim . cmd . new () 882end ) 883api . nvim_win_set_buf ( 0 , target_bufnr2 ) 884api . nvim_win_set_cursor ( 0 , { 2 , 3 } ) 885 886local result =exec_lua ( function () 887local server =_G . _create_server () 888local client_id =assert ( vim . lsp . start ( { name ='dummy' , cmd =server . cmd } )) 889local result =vim . lsp . handlers [ 'window/showDocument' ]( nil , { 890uri ='file:///fake/uri2' , 891takeFocus =false , 892} , { 893client_id =client_id , 894method ='window/showDocument' , 895} ) 896vim . lsp . get_client_by_id ( client_id ): stop () 897return result 898end ) 899eq ( { success =true } , result ) 900 901local wins =api . nvim_list_wins () 902eq ( 2 , # wins ) 903eq ( { 2 , 3 } , api . nvim_win_get_cursor ( wins [ 1 ])) 904eq ( { 2 , 3 } , api . nvim_win_get_cursor ( wins [ 2 ])) 905end ) 906 907it ( 'respects existing buffers' , function () 908api . nvim_win_set_buf ( 0 , target_bufnr ) 909local win =api . nvim_get_current_win () 910 911exec_lua ( function () 912vim . cmd . new () 913end ) 914api . nvim_win_set_buf ( 0 , target_bufnr2 ) 915api . nvim_win_set_cursor ( 0 , { 2 , 3 } ) 916local split =api . nvim_get_current_win () 917 918-- reuse win for open document/bufnr if called from split 919show_document ( location ( 0 , 9 , 0 , 9 , true ), false , true ) 920eq ( { 1 , 9 } , api . nvim_win_get_cursor ( split )) 921eq ( 2 , # api . nvim_list_wins ()) 922 923api . nvim_set_current_win ( win ) 924 925-- reuse win for open document/bufnr if called outside the split 926show_document ( location ( 0 , 9 , 0 , 9 , true ), false , true ) 927eq ( { 1 , 9 } , api . nvim_win_get_cursor ( split )) 928eq ( 2 , # api . nvim_list_wins ()) 929end ) 930end ) 931 932describe ( 'lsp.util._make_floating_popup_size' , function () 933before_each ( function () 934exec_lua ( function () 935_G . contents ={ 'text tαxt txtα tex' , 'text tααt tααt text' , 'text tαxt tαxt' } 936end ) 937end ) 938 939it ( 'calculates size correctly' , function () 940eq ( 941{ 19 , 3 } , 942exec_lua ( function () 943return { vim . lsp . util . _make_floating_popup_size ( _G . contents ) } 944end ) 945) 946end ) 947 948it ( 'calculates size correctly with wrapping' , function () 949eq ( 950{ 15 , 5 } , 951exec_lua ( function () 952return { 953vim . lsp . util . _make_floating_popup_size ( _G . contents , { width =15 , wrap_at =14 } ), 954} 955end ) 956) 957end ) 958 959it ( 'handles NUL bytes in text' , function () 960exec_lua ( function () 961_G . contents ={ 962'\000\001\002\003\004\005\006\007\008\009' , 963'\010\011\012\013\014\015\016\017\018\019' , 964'\020\021\022\023\024\025\026\027\028\029' , 965} 966end ) 967command ( 'set list listchars=' ) 968eq ( 969{ 20 , 3 } , 970exec_lua ( function () 971return { vim . lsp . util . _make_floating_popup_size ( _G . contents ) } 972end ) 973) 974command ( 'set display+=uhex' ) 975eq ( 976{ 40 , 3 } , 977exec_lua ( function () 978return { vim . lsp . util . _make_floating_popup_size ( _G . contents ) } 979end ) 980) 981end ) 982it ( 'handles empty line' , function () 983exec_lua ( function () 984_G . contents ={ 985'' , 986} 987end ) 988eq ( 989{ 20 , 1 } , 990exec_lua ( function () 991return { vim . lsp . util . _make_floating_popup_size ( _G . contents , { width =20 } ) } 992end ) 993) 994end ) 995 996it ( 'considers string title when computing width' , function () 997eq ( 998{ 17 , 2 } , 999exec_lua ( function () 1000return { 1001vim . lsp . util . _make_floating_popup_size ( 1002{ 'foo' , 'bar' } , 1003{ title ='A very long title' } 1004), 1005} 1006end ) 1007) 1008end ) 1009 1010it ( 'considers [string,string][] title when computing width' , function () 1011eq ( 1012{ 17 , 2 } , 1013exec_lua ( function () 1014return { 1015vim . lsp . util . _make_floating_popup_size ( 1016{ 'foo' , 'bar' } , 1017{ title ={ { 'A very ' , 'Normal' } , { 'long title' , 'Normal' } } } 1018), 1019} 1020end ) 1021) 1022end ) 1023end ) 1024 1025describe ( 'lsp.util.convert_signature_help_to_markdown_lines' , function () 1026it ( 'can handle negative activeSignature' , function () 1027local result =exec_lua ( function () 1028local signature_help ={ 1029activeParameter =0 , 1030activeSignature =- 1 , 1031signatures ={ 1032{ 1033documentation ='some doc' , 1034label ='TestEntity.TestEntity()' , 1035parameters ={} , 1036} , 1037} , 1038} 1039return vim . lsp . util . convert_signature_help_to_markdown_lines ( signature_help , 'cs' , { ',' } ) 1040end ) 1041local expected ={ '```cs' , 'TestEntity.TestEntity()' , '```' , '---' , 'some doc' } 1042eq ( expected , result ) 1043end ) 1044 1045it ( 'highlights active parameters in multiline signature labels' , function () 1046local _ , hl =exec_lua ( function () 1047local signature_help ={ 1048activeSignature =0 , 1049signatures ={ 1050{ 1051activeParameter =1 , 1052label ='fn bar(\n _: void,\n _: void,\n) void' , 1053parameters ={ 1054{ label ='_: void' } , 1055{ label ='_: void' } , 1056} , 1057} , 1058} , 1059} 1060return vim . lsp . util . convert_signature_help_to_markdown_lines ( signature_help , 'zig' , { '(' } ) 1061end ) 1062-- Note that although the highlight positions below are 0-indexed, the 2nd parameter 1063-- corresponds to the 3rd line because the first line is the ``` from the 1064-- Markdown block. 1065local expected ={ 3 , 4 , 3 , 11 } 1066eq ( expected , hl ) 1067end ) 1068end ) 1069 1070describe ( 'lsp.util.get_effective_tabstop' , function () 1071local function test_tabstop ( tabsize , shiftwidth ) 1072exec_lua ( string . format ( 1073[[ 1074vim.bo.shiftwidth = %d 1075vim.bo.tabstop = 2 1076]] , 1077shiftwidth 1078)) 1079eq ( 1080tabsize , 1081exec_lua ( function () 1082return vim . lsp . util . get_effective_tabstop () 1083end ) 1084) 1085end 1086 1087it ( 'with shiftwidth = 1' , function () 1088test_tabstop ( 1 , 1 ) 1089end ) 1090 1091it ( 'with shiftwidth = 0' , function () 1092test_tabstop ( 2 , 0 ) 1093end ) 1094end ) 1095 1096describe ( 'markdown and floating helpers' , function () 1097before_each ( n . clear ) 1098 1099describe ( 'stylize_markdown' , function () 1100local stylize_markdown =function ( content , opts ) 1101return exec_lua ( function () 1102local bufnr =vim . uri_to_bufnr ( 'file:///fake/uri' ) 1103vim . fn . bufload ( bufnr ) 1104return vim . lsp . util . stylize_markdown ( bufnr , content , opts ) 1105end ) 1106end 1107 1108it ( 'code fences' , function () 1109local lines ={ 1110'```lua' , 1111"local hello = 'world'" , 1112'```' , 1113} 1114local expected ={ 1115"local hello = 'world'" , 1116} 1117local opts ={} 1118eq ( expected , stylize_markdown ( lines , opts )) 1119end ) 1120 1121it ( 'code fences with whitespace surrounded info string' , function () 1122local lines ={ 1123'``` lua ' , 1124"local hello = 'world'" , 1125'```' , 1126} 1127local expected ={ 1128"local hello = 'world'" , 1129} 1130local opts ={} 1131eq ( expected , stylize_markdown ( lines , opts )) 1132end ) 1133 1134it ( 'adds separator after code block' , function () 1135local lines ={ 1136'```lua' , 1137"local hello = 'world'" , 1138'```' , 1139'' , 1140'something' , 1141} 1142local expected ={ 1143"local hello = 'world'" , 1144'─────────────────────' , 1145'something' , 1146} 1147local opts ={ separator =true } 1148eq ( expected , stylize_markdown ( lines , opts )) 1149end ) 1150 1151it ( 'replaces supported HTML entities' , function () 1152local lines ={ 1153'1 < 2' , 1154'3 > 2' , 1155'"quoted"' , 1156''apos'' , 1157'   ' , 1158'&' , 1159} 1160local expected ={ 1161'1 < 2' , 1162'3 > 2' , 1163'"quoted"' , 1164"'apos'" , 1165' ' , 1166'&' , 1167} 1168local opts ={} 1169eq ( expected , stylize_markdown ( lines , opts )) 1170end ) 1171end ) 1172 1173it ( 'convert_input_to_markdown_lines' , function () 1174local r =exec_lua ( function () 1175local hover_data ={ 1176kind ='markdown' , 1177value ='```lua\nfunction vim.api.nvim_buf_attach(buffer: integer, send_buffer: boolean, opts: vim.api.keyset.buf_attach)\n -> boolean\n```\n\n---\n\n Activates buffer-update events. Example:\n\n\n\n ```lua\n events = {}\n vim.api.nvim_buf_attach(0, false, {\n on_lines = function(...)\n table.insert(events, {...})\n end,\n })\n ```\n\n\n @see `nvim_buf_detach()`\n @see `api-buffer-updates-lua`\n@*param* `buffer` — Buffer handle, or 0 for current buffer\n\n\n\n@*param* `send_buffer` — True if whole buffer.\n Else the first notification will be `nvim_buf_changedtick_event`.\n\n\n@*param* `opts` — Optional parameters.\n\n - on_lines: Lua callback. Args:\n - the string "lines"\n - buffer handle\n - b:changedtick\n@*return* — False if foo;\n\n otherwise True.\n\n@see foo\n@see bar\n\nExample:\n\n iex> params = %{title: "", topics: []}\n\n iex> changeset.changes[:topics]\n' , 1178} 1179return vim . lsp . util . convert_input_to_markdown_lines ( hover_data ) 1180end ) 1181local expected ={ 1182'```lua' , 1183'function vim.api.nvim_buf_attach(buffer: integer, send_buffer: boolean, opts: vim.api.keyset.buf_attach)' , 1184' -> boolean' , 1185'```' , 1186'' , 1187'---' , 1188'' , 1189' Activates buffer-update events. Example:' , 1190'' , 1191'' , 1192'' , 1193' ```lua' , 1194' events = {}' , 1195' vim.api.nvim_buf_attach(0, false, {' , 1196' on_lines = function(...)' , 1197' table.insert(events, {...})' , 1198' end,' , 1199' })' , 1200' ```' , 1201'' , 1202'' , 1203' @see `nvim_buf_detach()`' , 1204' @see `api-buffer-updates-lua`' , 1205'' , 1206-- For each @param/@return: #30695 1207-- - Separate each by one empty line. 1208-- - Remove all other blank lines. 1209'@*param* `buffer` — Buffer handle, or 0 for current buffer' , 1210'' , 1211'@*param* `send_buffer` — True if whole buffer.' , 1212' Else the first notification will be `nvim_buf_changedtick_event`.' , 1213'' , 1214'@*param* `opts` — Optional parameters.' , 1215' - on_lines: Lua callback. Args:' , 1216' - the string "lines"' , 1217' - buffer handle' , 1218' - b:changedtick' , 1219'' , 1220'@*return* — False if foo;' , 1221' otherwise True.' , 1222'@see foo' , 1223'@see bar' , 1224-- Blank line preceding a 4-space-indented codeblock is required, per Markdown spec. #40860 1225'Example:' , 1226'' , 1227' iex> params = %{title: "", topics: []}' , 1228'' , 1229' iex> changeset.changes[:topics]' , 1230} 1231eq ( expected , r ) 1232end ) 1233 1234describe ( '_normalize_markdown' , function () 1235it ( 'collapses consecutive blank lines' , function () 1236local result =exec_lua ( function () 1237local lines ={ 1238'foo' , 1239'' , 1240'' , 1241'' , 1242'bar' , 1243'' , 1244'baz' , 1245} 1246return vim . lsp . util . _normalize_markdown ( lines ) 1247end ) 1248eq ( { 'foo' , '' , 'bar' , '' , 'baz' } , result ) 1249end ) 1250 1251it ( 'removes preceding and trailing empty lines' , function () 1252local result =exec_lua ( function () 1253local lines ={ 1254'' , 1255'foo' , 1256'bar' , 1257'' , 1258'' , 1259} 1260return vim . lsp . util . _normalize_markdown ( lines ) 1261end ) 1262eq ( { 'foo' , 'bar' } , result ) 1263end ) 1264end ) 1265 1266describe ( 'make_floating_popup_options' , function () 1267local function assert_anchor ( anchor_bias , expected_anchor ) 1268local opts =exec_lua ( function () 1269return vim . lsp . util . make_floating_popup_options ( 30 , 10 , { anchor_bias =anchor_bias } ) 1270end ) 1271 1272eq ( expected_anchor , string . sub ( opts . anchor , 1 , 1 )) 1273end 1274 1275before_each ( function () 1276local _ =Screen . new ( 80 , 80 ) 1277feed ( '79i<CR><Esc>' ) -- fill screen with empty lines 1278end ) 1279 1280describe ( 'when on the first line it places window below' , function () 1281before_each ( function () 1282feed ( 'gg' ) 1283end ) 1284 1285it ( 'for anchor_bias = "auto"' , function () 1286assert_anchor ( 'auto' , 'N' ) 1287end ) 1288 1289it ( 'for anchor_bias = "above"' , function () 1290assert_anchor ( 'above' , 'N' ) 1291end ) 1292 1293it ( 'for anchor_bias = "below"' , function () 1294assert_anchor ( 'below' , 'N' ) 1295end ) 1296end ) 1297 1298describe ( 'when on the last line it places window above' , function () 1299before_each ( function () 1300feed ( 'G' ) 1301end ) 1302 1303it ( 'for anchor_bias = "auto"' , function () 1304assert_anchor ( 'auto' , 'S' ) 1305end ) 1306 1307it ( 'for anchor_bias = "above"' , function () 1308assert_anchor ( 'above' , 'S' ) 1309end ) 1310 1311it ( 'for anchor_bias = "below"' , function () 1312assert_anchor ( 'below' , 'S' ) 1313end ) 1314end ) 1315 1316describe ( 'with 20 lines above, 59 lines below' , function () 1317before_each ( function () 1318feed ( 'gg20j' ) 1319end ) 1320 1321it ( 'places window below for anchor_bias = "auto"' , function () 1322assert_anchor ( 'auto' , 'N' ) 1323end ) 1324 1325it ( 'places window above for anchor_bias = "above"' , function () 1326assert_anchor ( 'above' , 'S' ) 1327end ) 1328 1329it ( 'places window below for anchor_bias = "below"' , function () 1330assert_anchor ( 'below' , 'N' ) 1331end ) 1332end ) 1333 1334describe ( 'with 59 lines above, 20 lines below' , function () 1335before_each ( function () 1336feed ( 'G20k' ) 1337end ) 1338 1339it ( 'places window above for anchor_bias = "auto"' , function () 1340assert_anchor ( 'auto' , 'S' ) 1341end ) 1342 1343it ( 'places window above for anchor_bias = "above"' , function () 1344assert_anchor ( 'above' , 'S' ) 1345end ) 1346 1347it ( 'places window below for anchor_bias = "below"' , function () 1348assert_anchor ( 'below' , 'N' ) 1349end ) 1350 1351it ( 'bordered window truncates dimensions correctly' , function () 1352local opts =exec_lua ( function () 1353return vim . lsp . util . make_floating_popup_options ( 100 , 100 , { border ='single' } ) 1354end ) 1355 1356eq ( 56 , opts . height ) 1357end ) 1358 1359it ( 'title with winborder option #35179' , function () 1360local opts =exec_lua ( function () 1361vim . o . winborder ='single' 1362return vim . lsp . util . make_floating_popup_options ( 100 , 100 , { title ='Title' } ) 1363end ) 1364eq ( 'Title' , opts . title ) 1365end ) 1366end ) 1367 1368it ( 'anchor is NW for relative = "editor" regardless of cursor #39306' , function () 1369feed ( 'G' ) -- without the fix, cursor on the last line picks an 'S*' anchor 1370local opts =exec_lua ( function () 1371return vim . lsp . util . make_floating_popup_options ( 30 , 10 , { relative ='editor' } ) 1372end ) 1373eq ( 'NW' , opts . anchor ) 1374end ) 1375end ) 1376 1377describe ( 'open_floating_preview' , function () 1378before_each ( function () 1379Screen . new ( 10 , 10 ) 1380feed ( '9i<CR><Esc>G4k' ) 1381end ) 1382local var_name ='lsp_floating_preview' 1383 1384it ( 'after fclose' , function () 1385exec_lua ( function () 1386vim . lsp . util . open_floating_preview ( { 'test' } , '' , { height =5 , width =2 } ) 1387end ) 1388eq ( true , api . nvim_win_is_valid ( api . nvim_buf_get_var ( 0 , var_name ))) 1389command ( 'fclose' ) 1390-- b:lsp_floating_preview should be cleared. 1391eq ( 'Key not found: lsp_floating_preview' , pcall_err ( api . nvim_buf_get_var , 0 , var_name )) 1392end ) 1393 1394it ( 'after CursorMoved' , function () 1395local result , winfixbuf =exec_lua ( function () 1396vim . lsp . util . open_floating_preview ( { 'test' } , '' , { height =5 , width =2 } ) 1397local winnr =vim . b [ vim . api . nvim_get_current_buf ()]. lsp_floating_preview 1398local result =vim . api . nvim_win_is_valid ( winnr ) 1399local winfixbuf =vim . wo [ winnr ]. winfixbuf 1400vim . api . nvim_feedkeys ( vim . keycode ( 'G' ), 'txn' , false ) 1401return result , winfixbuf 1402end ) 1403eq ( true , result ) 1404-- 'winfixbuf' should be set. #39058 1405eq ( true , winfixbuf ) 1406-- b:lsp_floating_preview should be cleared. 1407eq ( 'Key not found: lsp_floating_preview' , pcall_err ( api . nvim_buf_get_var , 0 , var_name )) 1408end ) 1409 1410it ( 'converted to a normal window is unmanaged, not closed #36659' , function () 1411local converted =exec_lua ( function () 1412local opts ={ focus_id ='focus_test' } 1413local cur_winnr =vim . api . nvim_get_current_win () 1414vim . lsp . util . open_floating_preview ( { 'test' } , '' , opts ) 1415local converted =vim . b . lsp_floating_preview 1416vim . api . nvim_win_set_config ( converted , { win =cur_winnr , split ='right' } ) 1417-- close events unmanage the converted window instead of closing it 1418vim . api . nvim_exec_autocmds ( 'CursorMoved' , { buffer =0 } ) 1419assert ( 1420vim . wait ( 1000 , function () 1421return vim . b . lsp_floating_preview == nil 1422end ), 1423'preview should be untracked after close event' 1424) 1425-- reusing the focus_id opens a new float instead of refocusing the converted window 1426local _ , new_win =vim . lsp . util . open_floating_preview ( { 'test' } , '' , opts ) 1427assert ( new_win ~= converted , 'expected a new float' ) 1428-- also when triggered from inside the converted window 1429vim . api . nvim_set_current_win ( converted ) 1430local _ , newer_win =vim . lsp . util . open_floating_preview ( { 'test' } , '' , opts ) 1431assert ( newer_win ~= converted , 'expected a new float' ) 1432assert ( vim . api . nvim_get_current_win () == converted , 'focus changed' ) 1433return converted 1434end ) 1435eq ( true , api . nvim_win_is_valid ( converted )) 1436eq ( '' , api . nvim_win_get_config ( converted ). relative ) 1437end ) 1438end ) 1439 1440it ( 'open_floating_preview zindex greater than current window' , function () 1441local screen =Screen . new () 1442exec_lua ( function () 1443vim . api . nvim_open_win ( 0 , true , { 1444relative ='editor' , 1445border ='single' , 1446height =11 , 1447width =51 , 1448row =2 , 1449col =2 , 1450} ) 1451vim . keymap . set ( 'n' , 'K' , function () 1452vim . lsp . util . open_floating_preview ( { 'foo' } , '' , { border ='single' } ) 1453end , {} ) 1454end ) 1455feed ( 'K' ) 1456screen : expect ( [[ 1457{4:┌───────────────────────────────────────────────────┐}| 1458{4:│^ │}| 1459{4:│┌───┐}{11: }{4:│}| 1460{4:││foo│}{11: }{4:│}| 1461{4:│└───┘}{11: }{4:│}| 1462{4:│}{11:~ }{4:│}|*7 1463{4:└───────────────────────────────────────────────────┘}| 1464| 1465]] ) 1466end ) 1467 1468it ( 'open_floating_preview height reduced for concealed lines' , function () 1469local screen =Screen . new () 1470screen : add_extra_attr_ids ( { 1471[ 100 ] ={ 1472background =Screen . colors . LightMagenta , 1473foreground =Screen . colors . Brown , 1474bold =true , 1475} , 1476[ 101 ] ={ background =Screen . colors . LightMagenta , foreground =Screen . colors . Blue } , 1477[ 102 ] ={ background =Screen . colors . LightMagenta , foreground =Screen . colors . DarkCyan } , 1478} ) 1479exec_lua ( [[ 1480vim.g.syntax_on = false 1481vim.lsp.util.open_floating_preview({ '```lua', 'local foo', '```' }, 'markdown', { 1482border = 'single', 1483focus = false, 1484}) 1485]] ) 1486screen : expect ( [[ 1487^ | 1488{4:┌─────────┐}{1: }| 1489{4:│}{100:local}{101: }{102:foo}{4:│}{1: }| 1490{4:└─────────┘}{1: }| 1491{1:~ }|*9 1492| 1493]] ) 1494-- Entering window keeps lines concealed and doesn't end up below inner window size. 1495feed ( '<C-w>wG' ) 1496screen : expect ( [[ 1497| 1498{4:┌─────────┐}{1: }| 1499{4:│}{101:^```}{4: │}{1: }| 1500{4:└─────────┘}{1: }| 1501{1:~ }|*9 1502| 1503]] ) 1504-- Correct height when float inherits 'conceallevel' >= 2 #32639 1505command ( 'close | set conceallevel=2' ) 1506feed ( '<Ignore>' ) -- Prevent CursorMoved closing the next float immediately 1507exec_lua ( [[ 1508vim.lsp.util.open_floating_preview({ '```lua', 'local foo', '```' }, 'markdown', { 1509border = 'single', 1510focus = false, 1511}) 1512]] ) 1513screen : expect ( [[ 1514^ | 1515{4:┌─────────┐}{1: }| 1516{4:│}{100:local}{101: }{102:foo}{4:│}{1: }| 1517{4:└─────────┘}{1: }| 1518{1:~ }|*9 1519| 1520]] ) 1521-- This tests the valid winline code path (why doesn't the above?). 1522exec_lua ( [[ 1523vim.cmd.only() 1524vim.lsp.util.open_floating_preview({ 'foo', '```lua', 'local bar', '```' }, 'markdown', { 1525border = 'single', 1526focus = false, 1527}) 1528]] ) 1529feed ( '<C-W>wG' ) 1530screen : expect ( [[ 1531| 1532{4:┌─────────┐}{1: }| 1533{4:│}{100:local}{101: }{102:bar}{4:│}{1: }| 1534{4:│}{101:^```}{4: │}{1: }| 1535{4:└─────────┘}{1: }| 1536{1:~ }|*8 1537| 1538]] ) 1539end ) 1540 1541it ( 'open_floating_preview height does not exceed max_height' , function () 1542local screen =Screen . new () 1543exec_lua ( [[ 1544vim.lsp.util.open_floating_preview(vim.fn.range(1, 10), 'markdown', { 1545border = 'single', 1546width = 5, 1547max_height = 5, 1548focus = false, 1549}) 1550]] ) 1551screen : expect ( [[ 1552^ | 1553{4:┌─────┐}{1: }| 1554{4:│1 │}{1: }| 1555{4:│2 │}{1: }| 1556{4:│3 │}{1: }| 1557{4:│4 │}{1: }| 1558{4:│5 │}{1: }| 1559{4:└─────┘}{1: }| 1560{1:~ }|*5 1561| 1562]] ) 1563end ) 1564end ) 1565end )