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