Native VBS and CMake builds of the server and every registered suite: protocol and document sync, VBS/compdb providers, stock GCC diagnostics (including in-process default profile preparation), the stock occurrence observer and hover/definition, the bounded Scheduler, C++ module graph, scan and artifact cache with real CMI production, the context-aware symbol index with schema-2 snapshot migration, navigation and guarded rename, reflection provenance with splice-origin extraction, index-backed completion and signature help, live GCC worker control with a registered DAP suite, and the Neovim and VS Code clients. VoidLibrary follows main. The private GCC 16.2.0 frontend is reproduced from the versioned patches and verified stepping reflection/template code with projected values 17/34 and 41/82.
86 lines
3.4 KiB
Lua
86 lines
3.4 KiB
Lua
-- Run with nvim --headless -u NONE -i NONE -l tests/native/NeovimRename.lua.
|
|
local repository = vim.fn.fnamemodify(debug.getinfo(1, "S").source:sub(2), ":p:h:h:h")
|
|
vim.opt.runtimepath:prepend(repository .. "/clients/neovim")
|
|
local vls = require("vls")
|
|
|
|
local root = vim.fn.tempname()
|
|
vim.fn.mkdir(root .. "/left", "p")
|
|
vim.fn.mkdir(root .. "/right", "p")
|
|
local left = root .. "/left/unit.cpp"
|
|
local right = root .. "/right/header.hpp"
|
|
vim.fn.writefile({ "int value = 17;", "int read() { return value; }" }, left)
|
|
vim.fn.writefile({ "int value = 3;" }, right)
|
|
|
|
local function load(path)
|
|
vim.cmd.edit(vim.fn.fnameescape(path))
|
|
return vim.api.nvim_get_current_buf()
|
|
end
|
|
local left_buffer = load(left)
|
|
local right_buffer = load(right)
|
|
|
|
local function snapshot(buffer)
|
|
return table.concat(vim.api.nvim_buf_get_lines(buffer, 0, -1, false), "\n")
|
|
end
|
|
|
|
local function edit(buffer, line, spelling, replacement)
|
|
local text = vim.api.nvim_buf_get_lines(buffer, line, line + 1, false)[1]
|
|
local start = assert(text:find(spelling, 1, true)) - 1
|
|
return { range = { start = { line = line, character = start },
|
|
["end"] = { line = line, character = start + #spelling } },
|
|
newText = replacement }
|
|
end
|
|
|
|
local function changes()
|
|
return {
|
|
[vim.uri_from_bufnr(left_buffer)] = {
|
|
edit(left_buffer, 0, "value", "count"),
|
|
edit(left_buffer, 1, "value", "count"),
|
|
},
|
|
[vim.uri_from_bufnr(right_buffer)] = {
|
|
edit(right_buffer, 0, "value", "count"),
|
|
},
|
|
}
|
|
end
|
|
|
|
local before_left, before_right = snapshot(left_buffer), snapshot(right_buffer)
|
|
assert(vls.apply_workspace_edit(changes()))
|
|
assert(snapshot(left_buffer):find("count", 1, true))
|
|
assert(snapshot(right_buffer):find("count", 1, true))
|
|
|
|
vim.api.nvim_buf_set_lines(left_buffer, 0, -1, false,
|
|
{ "int value = 17;", "int read() { return value; }" })
|
|
vim.api.nvim_buf_set_lines(right_buffer, 0, -1, false, { "int value = 3;" })
|
|
vim.bo[left_buffer].modified = false
|
|
vim.bo[right_buffer].modified = false
|
|
assert(snapshot(left_buffer) == before_left and snapshot(right_buffer) == before_right)
|
|
|
|
-- Inject a failure in the second buffer write and require a full rollback.
|
|
local original = vim.api.nvim_buf_set_text
|
|
local calls = 0
|
|
vim.api.nvim_buf_set_text = function(...)
|
|
calls = calls + 1
|
|
if calls == 2 then
|
|
error("injected buffer failure")
|
|
end
|
|
return original(...)
|
|
end
|
|
local ok, err = vls.apply_workspace_edit(changes())
|
|
vim.api.nvim_buf_set_text = original
|
|
assert(not ok and err:find("injected", 1, true), vim.inspect({ ok, err }))
|
|
assert(snapshot(left_buffer) == before_left and snapshot(right_buffer) == before_right)
|
|
assert(not vim.bo[left_buffer].modified and not vim.bo[right_buffer].modified)
|
|
|
|
-- An invalid range is rejected before any buffer is touched.
|
|
local invalid = changes()
|
|
invalid[vim.uri_from_bufnr(right_buffer)][1].range.start.line = 99
|
|
assert(not vls.apply_workspace_edit(invalid))
|
|
assert(snapshot(left_buffer) == before_left and snapshot(right_buffer) == before_right)
|
|
|
|
-- A read-only buffer refuses the whole transaction.
|
|
vim.bo[right_buffer].modifiable = false
|
|
assert(not vls.apply_workspace_edit(changes()))
|
|
vim.bo[right_buffer].modifiable = true
|
|
assert(snapshot(left_buffer) == before_left and snapshot(right_buffer) == before_right)
|
|
|
|
print("Neovim rename passed: atomic apply, injected-failure rollback, invalid range and read-only refusal")
|