robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

robinmerge: 1dc9728daa1d8a2702

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