feat: improve inverse search cmd

This commit is contained in:
Barrett Ruth 2026-03-12 15:42:20 -04:00
parent aea9d07ae9
commit f1cc5ca1ba
Signed by: barrett
GPG key ID: A6C96C9349D2FC81
6 changed files with 42 additions and 28 deletions

View file

@ -2,65 +2,66 @@ local M = {}
local Methods = vim.lsp.protocol.Methods 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) function M.on_attach(client, bufnr)
if client:supports_method(Methods.textDocument_hover) then if client:supports_method(Methods.textDocument_hover) then
vim.keymap.set('n', 'K', vim.lsp.buf.hover, { buffer = bufnr }) vim.keymap.set('n', 'K', vim.lsp.buf.hover, { buffer = bufnr })
end end
local ok, _ = pcall(require, 'fzf-lua')
local mappings = { local mappings = {
{ {
Methods.textDocument_codeAction, Methods.textDocument_codeAction,
'gra', 'gra',
ok and '<cmd>FzfLua lsp_code_actions<CR>' fzf_or('lsp_code_actions', vim.lsp.buf.code_action),
or vim.lsp.buf.code_action,
}, },
{ {
Methods.textDocument_declaration, Methods.textDocument_declaration,
'gD', 'gD',
ok and '<cmd>FzfLua lsp_declarations<CR>' fzf_or('lsp_declarations', vim.lsp.buf.declaration),
or vim.lsp.buf.declaration,
}, },
{ {
Methods.textDocument_definition, Methods.textDocument_definition,
'gd', 'gd',
ok and '<cmd>FzfLua lsp_definitions<CR>' or vim.lsp.buf.definition, fzf_or('lsp_definitions', vim.lsp.buf.definition),
}, },
{ {
Methods.textDocument_implementation, Methods.textDocument_implementation,
'gri', 'gri',
ok and '<cmd>FzfLua lsp_implementations<CR>' fzf_or('lsp_implementations', vim.lsp.buf.implementation),
or vim.lsp.buf.implementation,
}, },
{ {
Methods.textDocument_references, Methods.textDocument_references,
'grr', 'grr',
ok and '<cmd>FzfLua lsp_references<CR>' or vim.lsp.buf.references, fzf_or('lsp_references', vim.lsp.buf.references),
}, },
{ {
Methods.textDocument_typeDefinition, Methods.textDocument_typeDefinition,
'grt', 'grt',
ok and '<cmd>FzfLua lsp_typedefs<CR>' fzf_or('lsp_typedefs', vim.lsp.buf.type_definition),
or vim.lsp.buf.type_definition,
}, },
{ {
Methods.textDocument_documentSymbol, Methods.textDocument_documentSymbol,
'gs', 'gs',
ok and '<cmd>FzfLua lsp_document_symbols<CR>' fzf_or('lsp_document_symbols', vim.lsp.buf.document_symbol),
or vim.lsp.buf.document_symbol,
}, },
{ {
Methods.workspace_diagnostic, Methods.workspace_diagnostic,
'gw', 'gw',
ok and '<cmd>FzfLua lsp_workspace_diagnostics<CR>' fzf_or('lsp_workspace_diagnostics', vim.diagnostic.setqflist),
or vim.diagnostic.setqflist,
}, },
{ {
Methods.workspace_symbol, Methods.workspace_symbol,
'gS', 'gS',
ok and '<cmd>FzfLua lsp_workspace_symbols<CR>' fzf_or('lsp_workspace_symbols', vim.lsp.buf.workspace_symbol),
or vim.lsp.buf.workspace_symbol,
}, },
} }

View file

@ -161,10 +161,7 @@ return {
end end
end end
end, end,
group = vim.api.nvim_create_augroup( group = vim.api.nvim_create_augroup('AOil', { clear = true }),
'AOil',
{ clear = true }
),
}) })
end, end,
event = 'DeferredUIEnter', event = 'DeferredUIEnter',
@ -335,7 +332,7 @@ return {
vim.filetype.add({ vim.filetype.add({
extension = { puml = 'plantuml', pu = 'plantuml' }, extension = { puml = 'plantuml', pu = 'plantuml' },
}) })
vim.fn.serverstart('/tmp/nvim-preview.sock')
vim.api.nvim_create_autocmd('User', { vim.api.nvim_create_autocmd('User', {
pattern = 'PreviewCompileSuccess', pattern = 'PreviewCompileSuccess',
callback = function(args) callback = function(args)
@ -369,7 +366,9 @@ return {
debug = false, debug = false,
github = { github = {
output = function(ctx) output = function(ctx)
return '/tmp/' .. vim.fn.fnamemodify(ctx.file, ':t:r') .. '.html' return '/tmp/'
.. vim.fn.fnamemodify(ctx.file, ':t:r')
.. '.html'
end, end,
}, },
typst = { open = { 'sioyek', '--new-instance' } }, typst = { open = { 'sioyek', '--new-instance' } },

View file

@ -1,5 +1,5 @@
return { return {
'barrettruth/fzf-lua', 'ibhagwan/fzf-lua',
after = function() after = function()
local fzf = require('fzf-lua') local fzf = require('fzf-lua')
local has_nonicons = pcall(require, 'nonicons') local has_nonicons = pcall(require, 'nonicons')
@ -94,6 +94,7 @@ return {
fzf_reload.reload() fzf_reload.reload()
end end
end, end,
cmd = 'FzfLua',
keys = { keys = {
{ {
'<c-t>', '<c-t>',

View file

@ -46,8 +46,9 @@ vim.o.number = true
vim.o.relativenumber = true vim.o.relativenumber = true
vim.o.signcolumn = 'no' vim.o.signcolumn = 'no'
vim.o.statuscolumn = '%s%C %=%{v:relnum?v:relnum:v:lnum} ' 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.o.statusline =
" %{len(expand('%'))?expand('%:~').' ':''}%h%m%r%=%c:%l/%L %{&ft!=''?&ft:&bt} "
vim.opt.path:append('**') vim.opt.path:append('**')

View file

@ -161,7 +161,7 @@ in
font_size 18 font_size 18
status_bar_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
View 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