feat: Add follow_cursor and restore_location
New lua API function: follow_cursor (supports opts.focus_outline). This sets location in outline to match location in code. New keymap: restore_location (C-g) by default. This provides the same functionality as follow_cursor. I've also refactored other lua API functions for consistency of using `opts.focus_outline`. If opts is not provided, focus_outline is defaulted to true. To change this behaviour, set it to false.
This commit is contained in:
@@ -83,11 +83,12 @@ local function convert_symbols(result)
|
||||
end
|
||||
|
||||
---@param on_symbols function
|
||||
function M.request_symbols(on_symbols)
|
||||
---@param opts table
|
||||
function M.request_symbols(on_symbols, opts)
|
||||
vim.fn.call('CocActionAsync', {
|
||||
'documentSymbols',
|
||||
function(_, symbols)
|
||||
on_symbols { [1000000] = { result = convert_symbols(symbols) } }
|
||||
on_symbols({ [1000000] = { result = convert_symbols(symbols) } }, opts)
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
@@ -21,13 +21,13 @@ function M.has_provider()
|
||||
end
|
||||
|
||||
---@param on_symbols function
|
||||
function M.request_symbols(on_symbols)
|
||||
function M.request_symbols(on_symbols, opts)
|
||||
for _, value in ipairs(providers) do
|
||||
local provider = require(value)
|
||||
if provider.should_use_provider(0) then
|
||||
_G._symbols_outline_current_provider = provider
|
||||
_G._symbols_outline_current_provider.name = value
|
||||
provider.request_symbols(on_symbols)
|
||||
provider.request_symbols(on_symbols, opts)
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
@@ -17,8 +17,9 @@ function M.hover_info(_, _, on_info)
|
||||
end
|
||||
|
||||
---@param on_symbols function
|
||||
function M.request_symbols(on_symbols)
|
||||
on_symbols(md_parser.handle_markdown())
|
||||
---@param opts table
|
||||
function M.request_symbols(on_symbols, opts)
|
||||
on_symbols(md_parser.handle_markdown(), opts)
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -69,13 +69,14 @@ function M.postprocess_symbols(response)
|
||||
end
|
||||
|
||||
---@param on_symbols function
|
||||
function M.request_symbols(on_symbols)
|
||||
function M.request_symbols(on_symbols, opts)
|
||||
vim.lsp.buf_request_all(
|
||||
0,
|
||||
'textDocument/documentSymbol',
|
||||
getParams(),
|
||||
function (response)
|
||||
on_symbols(M.postprocess_symbols(response))
|
||||
response = M.postprocess_symbols(response)
|
||||
on_symbols(response, opts)
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user