Files
neovim/test/functional/plugin/lsp/linked_editing_range_spec.lua
Justin M. Keyes 6d8c8b18d5 test(harness): migrate away from magic globals
Problem:
The magic globals `it`, `describe`, etc., are more trouble than they are
worth.

- Hooking into `after_each` requires `getfenv()` hacks.
- They confuse luals/emmylua, because the top-level `.luarc.json` isn't
  merged with `test/.luarc.json` (apparently a luals limitation?)
- They totally defeat discoverability because the user just has to
  "know" about the various magic symbols.

So they harm DX, which means they serve no purpose at all.

Solution:
- Expose the test API from `testutil`, so tests can call `t.it()`,
  `t.describe()`, etc., in the conventional way.
- Drop `getfenv()` hacks.
- Drop the `setfenv()` injection in `load_chunk`.
- Drop `test/_meta.lua`.
2026-07-21 13:22:39 +02:00

139 lines
3.0 KiB
Lua

local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local t_lsp = require('test.functional.plugin.lsp.testutil')
local describe, it, before_each = t.describe, t.it, t.before_each
local eq = t.eq
local exec_lua = n.exec_lua
local insert = n.insert
local feed = n.feed
local clear_notrace = t_lsp.clear_notrace
local create_server_definition = t_lsp.create_server_definition
describe('vim.lsp.linked_editing_range', function()
before_each(function()
clear_notrace()
insert([[
hello
hello
hello]])
exec_lua(create_server_definition)
exec_lua(function()
vim.lsp.linked_editing_range.enable()
_G.server = _G._create_server({
capabilities = {
linkedEditingRangeProvider = true,
},
handlers = {
['textDocument/linkedEditingRange'] = function(_, _, callback)
callback(nil, {
ranges = {
{ start = { line = 0, character = 0 }, ['end'] = { line = 0, character = 5 } },
{ start = { line = 1, character = 0 }, ['end'] = { line = 1, character = 5 } },
{ start = { line = 2, character = 0 }, ['end'] = { line = 2, character = 5 } },
},
})
end,
},
})
_G.server_id = vim.lsp.start({ name = 'dummy', cmd = _G.server.cmd })
end)
end)
it('initiates linked editing', function()
exec_lua(function()
local win = vim.api.nvim_get_current_win()
vim.api.nvim_win_set_cursor(win, { 1, 0 })
end)
-- Deletion
feed('ldw')
eq(
{
'h',
'h',
'h',
},
exec_lua(function()
return vim.api.nvim_buf_get_lines(0, 0, -1, false)
end)
)
-- Insertion
feed('Apt<Esc>')
eq(
{
'hpt',
'hpt',
'hpt',
},
exec_lua(function()
return vim.api.nvim_buf_get_lines(0, 0, -1, false)
end)
)
-- Undo/redo
feed('0xx')
eq(
{
't',
't',
't',
},
exec_lua(function()
return vim.api.nvim_buf_get_lines(0, 0, -1, false)
end)
)
feed('u')
eq(
{
'pt',
'pt',
'pt',
},
exec_lua(function()
return vim.api.nvim_buf_get_lines(0, 0, -1, false)
end)
)
feed('u')
eq(
{
'hpt',
'hpt',
'hpt',
},
exec_lua(function()
return vim.api.nvim_buf_get_lines(0, 0, -1, false)
end)
)
feed('<C-r><C-r>')
eq(
{
't',
't',
't',
},
exec_lua(function()
return vim.api.nvim_buf_get_lines(0, 0, -1, false)
end)
)
-- Disabling
exec_lua(function()
vim.lsp.linked_editing_range.enable(false, { client_id = _G.server_id })
end)
feed('Ipp<Esc>')
eq(
{
'ppt',
't',
't',
},
exec_lua(function()
return vim.api.nvim_buf_get_lines(0, 0, -1, false)
end)
)
end)
end)