aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp/util.lua
diff options
context:
space:
mode:
authorMathias Fussenegger <f.mathias@zignar.net>2021-03-18 11:32:33 +0100
committerMathias Fussenegger <f.mathias@zignar.net>2021-03-18 19:53:43 +0100
commit84213b5b9adfaaf133771432ca468cea8faa4cc9 (patch)
tree1c949c17cf99f1b4e144ad8ae9aab33d122a9137 /runtime/lua/vim/lsp/util.lua
parent191afb42be90c3f39f445c8340632e732e6710f8 (diff)
downloadrneovim-84213b5b9adfaaf133771432ca468cea8faa4cc9.tar.gz
rneovim-84213b5b9adfaaf133771432ca468cea8faa4cc9.tar.bz2
rneovim-84213b5b9adfaaf133771432ca468cea8faa4cc9.zip
lsp: Add support for delete workspaceEdit resource operation
Diffstat (limited to 'runtime/lua/vim/lsp/util.lua')
-rw-r--r--runtime/lua/vim/lsp/util.lua24
1 files changed, 23 insertions, 1 deletions
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua
index 82fd77ea90..6945d0f1ec 100644
--- a/runtime/lua/vim/lsp/util.lua
+++ b/runtime/lua/vim/lsp/util.lua
@@ -647,6 +647,27 @@ local function create_file(change)
end
+local function delete_file(change)
+ local opts = change.options or {}
+ local fname = vim.uri_to_fname(change.uri)
+ local stat = vim.loop.fs_stat(fname)
+ if opts.ignoreIfNotExists and not stat then
+ return
+ end
+ assert(stat, "Cannot delete not existing file or folder " .. fname)
+ local flags
+ if stat and stat.type == 'directory' then
+ flags = opts.recursive and 'rf' or 'd'
+ else
+ flags = ''
+ end
+ local bufnr = vim.fn.bufadd(fname)
+ local result = tonumber(vim.fn.delete(fname, flags))
+ assert(result == 0, 'Could not delete file: ' .. fname .. ', stat: ' .. vim.inspect(stat))
+ api.nvim_buf_delete(bufnr, { force = true })
+end
+
+
--- Applies a `WorkspaceEdit`.
---
--@param workspace_edit (table) `WorkspaceEdit`
@@ -662,8 +683,9 @@ function M.apply_workspace_edit(workspace_edit)
)
elseif change.kind == 'create' then
create_file(change)
+ elseif change.kind == 'delete' then
+ delete_file(change)
elseif change.kind then
- -- TODO(ashkan) handle DeleteFile
error(string.format("Unsupported change: %q", vim.inspect(change)))
else
M.apply_text_document_edit(change, idx)