Files
outline.nvim/lua/outline/rename.lua
hedy e705330e40 feat: Per-tabpage outlines
Closes #37

Almost completely refactored the UI parts outline.nvim to use a Sidebar
object that implements an outline window. In init.lua, we can then store
a table of the outline for each tabpage ID.

When tabs are closed the outline is closed and sidebar reset
responsibly.

This simplifies `init.lua` quite a lot, making it the highest level
control center for the outline elements.

All lua APIs and commands should work as before.
2023-11-24 14:50:24 +08:00

38 lines
1.0 KiB
Lua

local outline = 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(outline.current.view.winnr)[1]
local node = outline.current.flats[current_line]
local params = get_rename_params(node, outline.current.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