feat: improve inverse search cmd
This commit is contained in:
parent
aea9d07ae9
commit
f1cc5ca1ba
6 changed files with 42 additions and 28 deletions
|
|
@ -2,65 +2,66 @@ local M = {}
|
|||
|
||||
local Methods = vim.lsp.protocol.Methods
|
||||
|
||||
local function fzf_or(fzf_cmd, fallback)
|
||||
return function()
|
||||
if pcall(require, 'fzf-lua') then
|
||||
vim.cmd('FzfLua ' .. fzf_cmd)
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function M.on_attach(client, bufnr)
|
||||
if client:supports_method(Methods.textDocument_hover) then
|
||||
vim.keymap.set('n', 'K', vim.lsp.buf.hover, { buffer = bufnr })
|
||||
end
|
||||
|
||||
local ok, _ = pcall(require, 'fzf-lua')
|
||||
|
||||
local mappings = {
|
||||
{
|
||||
Methods.textDocument_codeAction,
|
||||
'gra',
|
||||
ok and '<cmd>FzfLua lsp_code_actions<CR>'
|
||||
or vim.lsp.buf.code_action,
|
||||
fzf_or('lsp_code_actions', vim.lsp.buf.code_action),
|
||||
},
|
||||
{
|
||||
Methods.textDocument_declaration,
|
||||
'gD',
|
||||
ok and '<cmd>FzfLua lsp_declarations<CR>'
|
||||
or vim.lsp.buf.declaration,
|
||||
fzf_or('lsp_declarations', vim.lsp.buf.declaration),
|
||||
},
|
||||
{
|
||||
Methods.textDocument_definition,
|
||||
'gd',
|
||||
ok and '<cmd>FzfLua lsp_definitions<CR>' or vim.lsp.buf.definition,
|
||||
fzf_or('lsp_definitions', vim.lsp.buf.definition),
|
||||
},
|
||||
{
|
||||
Methods.textDocument_implementation,
|
||||
'gri',
|
||||
ok and '<cmd>FzfLua lsp_implementations<CR>'
|
||||
or vim.lsp.buf.implementation,
|
||||
fzf_or('lsp_implementations', vim.lsp.buf.implementation),
|
||||
},
|
||||
{
|
||||
Methods.textDocument_references,
|
||||
'grr',
|
||||
ok and '<cmd>FzfLua lsp_references<CR>' or vim.lsp.buf.references,
|
||||
fzf_or('lsp_references', vim.lsp.buf.references),
|
||||
},
|
||||
{
|
||||
Methods.textDocument_typeDefinition,
|
||||
'grt',
|
||||
ok and '<cmd>FzfLua lsp_typedefs<CR>'
|
||||
or vim.lsp.buf.type_definition,
|
||||
fzf_or('lsp_typedefs', vim.lsp.buf.type_definition),
|
||||
},
|
||||
{
|
||||
Methods.textDocument_documentSymbol,
|
||||
'gs',
|
||||
ok and '<cmd>FzfLua lsp_document_symbols<CR>'
|
||||
or vim.lsp.buf.document_symbol,
|
||||
fzf_or('lsp_document_symbols', vim.lsp.buf.document_symbol),
|
||||
},
|
||||
{
|
||||
Methods.workspace_diagnostic,
|
||||
'gw',
|
||||
ok and '<cmd>FzfLua lsp_workspace_diagnostics<CR>'
|
||||
or vim.diagnostic.setqflist,
|
||||
fzf_or('lsp_workspace_diagnostics', vim.diagnostic.setqflist),
|
||||
},
|
||||
{
|
||||
Methods.workspace_symbol,
|
||||
'gS',
|
||||
ok and '<cmd>FzfLua lsp_workspace_symbols<CR>'
|
||||
or vim.lsp.buf.workspace_symbol,
|
||||
fzf_or('lsp_workspace_symbols', vim.lsp.buf.workspace_symbol),
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -161,10 +161,7 @@ return {
|
|||
end
|
||||
end
|
||||
end,
|
||||
group = vim.api.nvim_create_augroup(
|
||||
'AOil',
|
||||
{ clear = true }
|
||||
),
|
||||
group = vim.api.nvim_create_augroup('AOil', { clear = true }),
|
||||
})
|
||||
end,
|
||||
event = 'DeferredUIEnter',
|
||||
|
|
@ -335,7 +332,7 @@ return {
|
|||
vim.filetype.add({
|
||||
extension = { puml = 'plantuml', pu = 'plantuml' },
|
||||
})
|
||||
vim.fn.serverstart('/tmp/nvim-preview.sock')
|
||||
|
||||
vim.api.nvim_create_autocmd('User', {
|
||||
pattern = 'PreviewCompileSuccess',
|
||||
callback = function(args)
|
||||
|
|
@ -369,7 +366,9 @@ return {
|
|||
debug = false,
|
||||
github = {
|
||||
output = function(ctx)
|
||||
return '/tmp/' .. vim.fn.fnamemodify(ctx.file, ':t:r') .. '.html'
|
||||
return '/tmp/'
|
||||
.. vim.fn.fnamemodify(ctx.file, ':t:r')
|
||||
.. '.html'
|
||||
end,
|
||||
},
|
||||
typst = { open = { 'sioyek', '--new-instance' } },
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
return {
|
||||
'barrettruth/fzf-lua',
|
||||
'ibhagwan/fzf-lua',
|
||||
after = function()
|
||||
local fzf = require('fzf-lua')
|
||||
local has_nonicons = pcall(require, 'nonicons')
|
||||
|
|
@ -94,6 +94,7 @@ return {
|
|||
fzf_reload.reload()
|
||||
end
|
||||
end,
|
||||
cmd = 'FzfLua',
|
||||
keys = {
|
||||
{
|
||||
'<c-t>',
|
||||
|
|
|
|||
|
|
@ -46,8 +46,9 @@ vim.o.number = true
|
|||
vim.o.relativenumber = true
|
||||
vim.o.signcolumn = 'no'
|
||||
|
||||
vim.o.statuscolumn = '%s%C %=%{v:relnum?v:relnum:v:lnum} '
|
||||
vim.o.statusline = " %{len(expand('%'))?expand('%:~').' ':''}%h%m%r%=%c:%l/%L %{&ft!=''?&ft:&bt} "
|
||||
vim.o.statuscolumn = "%{%v:virtnum?'':'%s%C %=%{v:relnum?v:relnum:v:lnum} '%}"
|
||||
vim.o.statusline =
|
||||
" %{len(expand('%'))?expand('%:~').' ':''}%h%m%r%=%c:%l/%L %{&ft!=''?&ft:&bt} "
|
||||
|
||||
vim.opt.path:append('**')
|
||||
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ in
|
|||
font_size 18
|
||||
status_bar_font_size 18
|
||||
|
||||
inverse_search_command nvim --server /tmp/nvim-preview.sock --remote-expr "execute('b +%2 %1 | normal! zz')"
|
||||
inverse_search_command nvim-inverse-search %1 %2
|
||||
'';
|
||||
};
|
||||
|
||||
|
|
|
|||
12
scripts/nvim-inverse-search
Executable file
12
scripts/nvim-inverse-search
Executable file
|
|
@ -0,0 +1,12 @@
|
|||
#!/bin/sh
|
||||
file="$1"
|
||||
line="$2"
|
||||
|
||||
for sock in /run/user/$(id -u)/nvim.*.0; do
|
||||
[ -S "$sock" ] || continue
|
||||
result=$(nvim --server "$sock" --remote-expr "bufnr('$file')" 2>/dev/null)
|
||||
if [ "$result" != "-1" ] && [ -n "$result" ]; then
|
||||
nvim --server "$sock" --remote-expr "execute('b +$line $file | normal! zz')"
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
Loading…
Add table
Add a link
Reference in a new issue