Possible to use vim.lsp.buf.references() with an ignore pattern?

I often use vim.lsp.buf.references(), but rarely do I need the references in test files (e.g. *_test.go for Go).

Is there a way to use this command with an ignore pattern so I could have something like this in my on_attach method:

  buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references(<ignore *_test.go>)<CR>', opts)
  buf_set_keymap('n', 'gR, '<cmd>lua vim.lsp.buf.references()<CR>', opts)

Managed to do this with Telescope

" Find references, excluding test files
nnoremap gr <cmd>lua require('telescope.builtin').lsp_references({file_ignore_patterns = { "%_test.go" } })<cr>
" Find references, including test files
nnoremap <leader>gr <cmd>lua require('telescope.builtin').lsp_references()<cr>
1 Like