Apply versioned workspace edits in the Neovim client
apply_workspace_edit accepts a full WorkspaceEdit: a changes map or documentChanges with versioned TextDocumentEdits. Stale tracked versions and resource operations are refused before any buffer is touched, keeping the transactional rollback. The headless rename test covers the versioned apply and both refusals.
This commit is contained in:
1 parent
7e3ce6fc6c
commit
a075bd55d8
4 files changed
+86
-7
No files matched your search
@@ -82,4 +82,32 @@ 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")
|
||||
-- documentChanges: versioned edits apply and stale versions are refused.
|
||||
local doc_left_path, doc_right_path = vim.fn.tempname(), vim.fn.tempname()
|
||||
vim.fn.writefile({ "value one", "value two" }, doc_left_path)
|
||||
vim.fn.writefile({ "value three" }, doc_right_path)
|
||||
local doc_left, doc_right = vim.fn.bufadd(doc_left_path), vim.fn.bufadd(doc_right_path)
|
||||
vim.fn.bufload(doc_left)
|
||||
vim.fn.bufload(doc_right)
|
||||
local left_uri, right_uri = vim.uri_from_bufnr(doc_left), vim.uri_from_bufnr(doc_right)
|
||||
vim.lsp.util.buf_versions[vim.uri_to_bufnr(left_uri)] = 7
|
||||
vim.lsp.util.buf_versions[vim.uri_to_bufnr(right_uri)] = 7
|
||||
|
||||
local function document_changes(version)
|
||||
return { documentChanges = {
|
||||
{ textDocument = { uri = left_uri, version = version },
|
||||
edits = { edit(doc_left, 0, "value", "count"), edit(doc_left, 1, "value", "count") } },
|
||||
{ textDocument = { uri = right_uri, version = version },
|
||||
edits = { edit(doc_right, 0, "value", "count") } } } }
|
||||
end
|
||||
local stale_ok, stale_err = vls.apply_workspace_edit(document_changes(6))
|
||||
assert(not stale_ok and stale_err:find("stale", 1, true), vim.inspect({ stale_ok, stale_err }))
|
||||
assert(vim.api.nvim_buf_get_lines(doc_left, 0, 1, false)[1] == "value one")
|
||||
local applied_ok, applied_err = vls.apply_workspace_edit(document_changes(7))
|
||||
assert(applied_ok, vim.inspect(applied_err))
|
||||
assert(vim.api.nvim_buf_get_lines(doc_left, 0, 1, false)[1] == "count one")
|
||||
assert(vim.api.nvim_buf_get_lines(doc_right, 0, 1, false)[1] == "count three")
|
||||
-- Resource operations are refused explicitly.
|
||||
assert(not vls.apply_workspace_edit({ documentChanges = { { kind = "create", uri = left_uri } } }))
|
||||
|
||||
print("Neovim rename passed: atomic apply, injected-failure rollback, invalid range, read-only refusal, documentChanges and stale-version refusal")
|
||||
Reference in new issue
Block a user