Closed terrortylor closed 2 years ago
Had some tie to do this quickly: https://github.com/terrortylor/hop.nvim/tree/feature/user-input
Which means we can then do some nice hint_char1 (or whatever) extensions:
local hop = require("hop")
local jump_target = require("hop.jump_target")
local set = vim.keymap.set
local hint_char1_and_then = function(and_then_func)
return function()
local opts = hop.opts
local c = hop.get_input_pattern('Hop 1 char: ', 1)
local generator = jump_target.jump_targets_by_scanning_lines
hop.hint_with_callback(
generator(jump_target.regex_by_case_searching(c, true, opts)),
opts,
function(jt)
hop.move_cursor_to(jt.window, jt.line + 1, jt.column - 1, opts.hint_offset)
and_then_func()
end
)
end
end
set("n", "<leader>jd",hint_char1_and_then(require("telescope.builtin").lsp_definitions), { noremap = true, silent = true })
set("n", "<leader>jD",hint_char1_and_then(vim.lsp.buf.declaration), { noremap = true, silent = true })
set("n", "<leader>ji",hint_char1_and_then(require("telescope.builtin").lsp_implementations), { noremap = true, silent = true })
set("n", "<leader>jr",hint_char1_and_then(require("telescope.builtin").lsp_references), { noremap = true, silent = true })
set("n", "<leader>jk",hint_char1_and_then(vim.lsp.buf.type_definition), { noremap = true })
Yeah, we can probably expose it!
Are you happy for me to raise a PR?
I'd like to extend hint_char1 so that I have a callback. Looking at the API it seems that the preferred way would be to use hint_with_callback, however it's not clear how I'd handle the input capture. The get_input_pattern isn't exposed in the API so would the use be expected to re-write that?
It seems the easiest method would be to expose get_input_pattern as part of the API to let me achieve this. What do you think? If there is another way then please advise.
I'd be more than happy to make the changes and raise a PR based on your feedback. Thanks