diff options
author | Mathias Fussenegger <f.mathias@zignar.net> | 2021-03-15 22:34:22 +0100 |
---|---|---|
committer | Mathias Fussenegger <f.mathias@zignar.net> | 2021-03-18 19:53:14 +0100 |
commit | 5e401b693b929da36d08943d4fda0191fe12f02c (patch) | |
tree | b63f977c4ef16e5ac22fe0342dcbb9fd731d9fe6 /test | |
parent | 0ab88c2ea80caa7cda97b3a8479d0d32e4636ab6 (diff) | |
download | rneovim-5e401b693b929da36d08943d4fda0191fe12f02c.tar.gz rneovim-5e401b693b929da36d08943d4fda0191fe12f02c.tar.bz2 rneovim-5e401b693b929da36d08943d4fda0191fe12f02c.zip |
lsp: Add support for file rename via workspaceEdit
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/plugin/lsp_spec.lua | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index c62d91cb6d..2fd9934e7d 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -11,6 +11,8 @@ local pesc = helpers.pesc local insert = helpers.insert local retry = helpers.retry local NIL = helpers.NIL +local read_file = require('test.helpers').read_file +local write_file = require('test.helpers').write_file -- Use these to get access to a coroutine so that I can run async tests and use -- yield. @@ -1309,6 +1311,72 @@ describe('LSP', function() end) end) + describe('lsp.util.rename', function() + it('Can rename an existing file', function() + local old = helpers.tmpname() + write_file(old, 'Test content') + local new = helpers.tmpname() + os.remove(new) -- only reserve the name, file must not exist for the test scenario + local lines = exec_lua([[ + local old = select(1, ...) + local new = select(2, ...) + vim.lsp.util.rename(old, new) + + -- after rename the target file must have the contents of the source file + local bufnr = vim.fn.bufadd(new) + return vim.api.nvim_buf_get_lines(bufnr, 0, -1, true) + ]], old, new) + eq({'Test content'}, lines) + local exists = exec_lua('return vim.loop.fs_stat(...) ~= nil', old) + eq(false, exists) + exists = exec_lua('return vim.loop.fs_stat(...) ~= nil', new) + eq(true, exists) + os.remove(new) + end) + it('Does not rename file if target exists and ignoreIfExists is set or overwrite is false', function() + local old = helpers.tmpname() + write_file(old, 'Old File') + local new = helpers.tmpname() + write_file(new, 'New file') + + exec_lua([[ + local old = select(1, ...) + local new = select(2, ...) + + vim.lsp.util.rename(old, new, { ignoreIfExists = true }) + ]], old, new) + + eq(true, exec_lua('return vim.loop.fs_stat(...) ~= nil', old)) + eq('New file', read_file(new)) + + exec_lua([[ + local old = select(1, ...) + local new = select(2, ...) + + vim.lsp.util.rename(old, new, { overwrite = false }) + ]], old, new) + + eq(true, exec_lua('return vim.loop.fs_stat(...) ~= nil', old)) + eq('New file', read_file(new)) + end) + it('Does override target if overwrite is true', function() + local old = helpers.tmpname() + write_file(old, 'Old file') + local new = helpers.tmpname() + write_file(new, 'New file') + exec_lua([[ + local old = select(1, ...) + local new = select(2, ...) + + vim.lsp.util.rename(old, new, { overwrite = true }) + ]], old, new) + + eq(false, exec_lua('return vim.loop.fs_stat(...) ~= nil', old)) + eq(true, exec_lua('return vim.loop.fs_stat(...) ~= nil', new)) + eq('Old file\n', read_file(new)) + end) + end) + describe('lsp.util.locations_to_items', function() it('Convert Location[] to items', function() local expected = { |