MAJOR: Project rename and preparation for v1.0.0
I hope I haven't missed any for the renames!
This commit is contained in:
42
lua/outline/rename.lua
Normal file
42
lua/outline/rename.lua
Normal file
@@ -0,0 +1,42 @@
|
||||
local so = require 'outline'
|
||||
|
||||
local M = {}
|
||||
|
||||
local function get_rename_params(node, winnr)
|
||||
local bufnr = vim.api.nvim_win_get_buf(winnr)
|
||||
local fn = 'file://' .. vim.api.nvim_buf_get_name(bufnr)
|
||||
|
||||
return {
|
||||
textDocument = { uri = fn },
|
||||
position = { line = node.line, character = node.character },
|
||||
bufnr = bufnr,
|
||||
}
|
||||
end
|
||||
|
||||
function M.rename()
|
||||
local current_line = vim.api.nvim_win_get_cursor(so.view.winnr)[1]
|
||||
local node = so.state.flattened_outline_items[current_line]
|
||||
|
||||
local params = get_rename_params(node, so.state.code_win)
|
||||
|
||||
local new_name = vim.fn.input({ prompt = 'New Name: ', default = node.name })
|
||||
if not new_name or new_name == '' or new_name == node.name then
|
||||
return
|
||||
end
|
||||
|
||||
params.newName = new_name
|
||||
|
||||
vim.lsp.buf_request(
|
||||
params.bufnr,
|
||||
'textDocument/rename',
|
||||
params,
|
||||
function(_, result, ctx)
|
||||
if result ~= nil then
|
||||
local client = vim.lsp.get_client_by_id(ctx.client_id)
|
||||
vim.lsp.util.apply_workspace_edit(result, client.offset_encoding)
|
||||
end
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user