feat: Update outline on rename symbol
Also added ability to show provider status from code_action and rename_symbol
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
local cfg = require('outline.config')
|
local cfg = require('outline.config')
|
||||||
local outline = require('outline')
|
local outline = require('outline')
|
||||||
local util = vim.lsp.util
|
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
@@ -15,7 +14,6 @@ local function get_hover_params(node, winnr)
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
-- handler yoinked from the default implementation
|
|
||||||
function M.show_hover()
|
function M.show_hover()
|
||||||
local current_line = vim.api.nvim_win_get_cursor(outline.current.view.win)[1]
|
local current_line = vim.api.nvim_win_get_cursor(outline.current.view.win)[1]
|
||||||
local node = outline.current.flats[current_line]
|
local node = outline.current.flats[current_line]
|
||||||
@@ -26,18 +24,16 @@ function M.show_hover()
|
|||||||
hover_params.bufnr,
|
hover_params.bufnr,
|
||||||
'textDocument/hover',
|
'textDocument/hover',
|
||||||
hover_params,
|
hover_params,
|
||||||
---@diagnostic disable-next-line: param-type-mismatch
|
|
||||||
function(_, result, _, config)
|
function(_, result, _, config)
|
||||||
if not (result and result.contents) then
|
if not (result and result.contents) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local markdown_lines = util.convert_input_to_markdown_lines(result.contents)
|
local markdown_lines = vim.lsp.util.convert_input_to_markdown_lines(result.contents)
|
||||||
markdown_lines = util.trim_empty_lines(markdown_lines)
|
markdown_lines = vim.lsp.util.trim_empty_lines(markdown_lines)
|
||||||
if vim.tbl_isempty(markdown_lines) then
|
if vim.tbl_isempty(markdown_lines) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- FIXME
|
local bufnr, winnr = vim.lsp.util.open_floating_preview(markdown_lines, 'markdown', config)
|
||||||
local bufnr, winnr = util.open_floating_preview(markdown_lines, 'markdown', config)
|
|
||||||
vim.api.nvim_win_set_option(winnr, 'winhighlight', cfg.o.preview_window.winhl)
|
vim.api.nvim_win_set_option(winnr, 'winhighlight', cfg.o.preview_window.winhl)
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -27,9 +27,13 @@ end
|
|||||||
---@param args any[]
|
---@param args any[]
|
||||||
function M.action(sidebar, method, args)
|
function M.action(sidebar, method, args)
|
||||||
if not sidebar.provider or not sidebar.provider[method] then
|
if not sidebar.provider or not sidebar.provider[method] then
|
||||||
|
require('outline.utils').echo('No supported providers to perform this action.')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
return sidebar.provider[method](unpack(args))
|
local ok = sidebar.provider[method](unpack(args))
|
||||||
|
if not ok then
|
||||||
|
require('outline.utils').echo('The provider could not perform this action successfully.')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ function M.get_status()
|
|||||||
return { 'client: ' .. M.client.name }
|
return { 'client: ' .. M.client.name }
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.hover_info(bufnr, params, on_info)
|
local function get_appropriate_client(bufnr, capability)
|
||||||
local clients = vim.lsp.get_active_clients({ bufnr = bufnr })
|
local clients = vim.lsp.get_active_clients({ bufnr = bufnr })
|
||||||
local use_client
|
local use_client
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ function M.hover_info(bufnr, params, on_info)
|
|||||||
if config.is_client_blacklisted(client) then
|
if config.is_client_blacklisted(client) then
|
||||||
goto continue
|
goto continue
|
||||||
else
|
else
|
||||||
if client.server_capabilities.hoverProvider then
|
if client.server_capabilities[capability] then
|
||||||
use_client = client
|
use_client = client
|
||||||
M.client = client
|
M.client = client
|
||||||
break
|
break
|
||||||
@@ -31,39 +31,16 @@ function M.hover_info(bufnr, params, on_info)
|
|||||||
end
|
end
|
||||||
::continue::
|
::continue::
|
||||||
end
|
end
|
||||||
|
return use_client
|
||||||
if not use_client then
|
|
||||||
on_info(nil, {
|
|
||||||
contents = {
|
|
||||||
kind = 'markdown',
|
|
||||||
content = { 'No extra information availaible' },
|
|
||||||
},
|
|
||||||
})
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
use_client.request('textDocument/hover', params, on_info, bufnr)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---@return boolean
|
---@return boolean
|
||||||
function M.supports_buffer(bufnr)
|
function M.supports_buffer(bufnr)
|
||||||
local clients = vim.lsp.get_active_clients({ bufnr = bufnr })
|
local client = get_appropriate_client(bufnr, 'documentSymbolProvider')
|
||||||
local ret = false
|
if not client then
|
||||||
|
return false
|
||||||
for _, client in ipairs(clients) do
|
|
||||||
if config.is_client_blacklisted(client) then
|
|
||||||
goto continue
|
|
||||||
else
|
|
||||||
if client.server_capabilities.documentSymbolProvider then
|
|
||||||
M.client = client
|
|
||||||
ret = true
|
|
||||||
break
|
|
||||||
end
|
end
|
||||||
end
|
return true
|
||||||
::continue::
|
|
||||||
end
|
|
||||||
|
|
||||||
return ret
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param response outline.ProviderSymbol[]
|
---@param response outline.ProviderSymbol[]
|
||||||
@@ -95,17 +72,74 @@ end
|
|||||||
-- No good way to update outline when LSP action complete for now
|
-- No good way to update outline when LSP action complete for now
|
||||||
|
|
||||||
---@param sidebar outline.Sidebar
|
---@param sidebar outline.Sidebar
|
||||||
|
---@return boolean success
|
||||||
function M.code_actions(sidebar)
|
function M.code_actions(sidebar)
|
||||||
|
local client = get_appropriate_client(sidebar.code.buf, 'codeActionProvider')
|
||||||
|
if not client then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
-- NOTE: Unfortunately the code_action function provided by neovim does a
|
||||||
|
-- lot, yet it doesn't let us filter clients. Since handling of code_actions
|
||||||
|
-- is beyond the scope of outline.nvim itself, we will not respect
|
||||||
|
-- blacklist_clients for code actions for now. Code actions feature would not
|
||||||
|
-- actually be included if I were to write this plugin from scratch. However
|
||||||
|
-- we still keep it because many people are moving here from
|
||||||
|
-- symbols-outline.nvim, which happened to implement this feature.
|
||||||
sidebar:wrap_goto_location(function()
|
sidebar:wrap_goto_location(function()
|
||||||
vim.lsp.buf.code_action()
|
vim.lsp.buf.code_action()
|
||||||
end)
|
end)
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Synchronously request rename from LSP
|
||||||
---@param sidebar outline.Sidebar
|
---@param sidebar outline.Sidebar
|
||||||
|
---@return boolean success
|
||||||
function M.rename_symbol(sidebar)
|
function M.rename_symbol(sidebar)
|
||||||
sidebar:wrap_goto_location(function()
|
local client = get_appropriate_client(sidebar.code.buf, 'renameProvider')
|
||||||
vim.lsp.buf.rename()
|
if not client then
|
||||||
end)
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local node = sidebar:_current_node()
|
||||||
|
|
||||||
|
-- Using fn.input so it's synchronous
|
||||||
|
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 true
|
||||||
|
end
|
||||||
|
|
||||||
|
local params = {
|
||||||
|
textDocument = { uri = 'file://' .. vim.api.nvim_buf_get_name(sidebar.code.buf) },
|
||||||
|
position = { line = node.line, character = node.character },
|
||||||
|
bufnr = sidebar.code.buf,
|
||||||
|
newName = new_name,
|
||||||
|
}
|
||||||
|
local timeout = 2000
|
||||||
|
local status, err = client.request_sync('textDocument/rename', params, timeout, sidebar.code.buf)
|
||||||
|
if status == nil or status.err or err or status.result == nil then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.lsp.util.apply_workspace_edit(status.result, client.offset_encoding)
|
||||||
|
node.name = new_name
|
||||||
|
sidebar:_update_lines(false)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.hover_info(bufnr, params, on_info)
|
||||||
|
local use_client = get_appropriate_client(bufnr, 'hoverProvider')
|
||||||
|
|
||||||
|
if not use_client then
|
||||||
|
on_info(nil, {
|
||||||
|
contents = {
|
||||||
|
kind = 'markdown',
|
||||||
|
content = { 'No extra information availaible' },
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
use_client.request('textDocument/hover', params, on_info, bufnr)
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
@@ -67,8 +67,8 @@
|
|||||||
---@field supports_buffer fun(bufnr:integer):boolean
|
---@field supports_buffer fun(bufnr:integer):boolean
|
||||||
---@field request_symbols fun(on_symbols:fun(symbols?:outline.ProviderSymbol[], opts:table?), opts:table?)
|
---@field request_symbols fun(on_symbols:fun(symbols?:outline.ProviderSymbol[], opts:table?), opts:table?)
|
||||||
---@field hover_info? fun(bufnr:integer, params:table, on_info:function)
|
---@field hover_info? fun(bufnr:integer, params:table, on_info:function)
|
||||||
---@field rename_symbol? fun(sidebar:outline.Sidebar)
|
---@field rename_symbol? fun(sidebar:outline.Sidebar):boolean
|
||||||
---@field code_actions? fun(sidebar:outline.Sidebar)
|
---@field code_actions? fun(sidebar:outline.Sidebar):boolean
|
||||||
|
|
||||||
-- HELP
|
-- HELP
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user