Skip to content

Commit e87b728

Browse files
tjdevriesPhilipp Szechenyiszechporiori1703philipp
authored
feat: move Telescope config to be contained by plugin (#1843)
* move telescope related lsp functions inside the telscope plugin declaration block * explicitly enable telescope plugin, add some comments explainging why * update comments with suggestions from @oriori1703 Co-authored-by: Ori Perry <[email protected]> * fix formatting in accordance to stylua so that pipeline passes --------- Co-authored-by: Philipp Szechenyi <[email protected]> Co-authored-by: Philipp Szechenyi <[email protected]> Co-authored-by: Ori Perry <[email protected]> Co-authored-by: philipp <[email protected]>
1 parent 88c6559 commit e87b728

1 file changed

Lines changed: 48 additions & 25 deletions

File tree

init.lua

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,16 @@ require('lazy').setup({
360360

361361
{ -- Fuzzy Finder (files, lsp, etc)
362362
'nvim-telescope/telescope.nvim',
363+
-- By default, Telescope is included and acts as your picker for everything.
364+
365+
-- If you would like to switch to a different picker (like snacks, or fzf-lua)
366+
-- you can disable the Telescope plugin by setting enabled to false and enable
367+
-- your replacement picker by requiring it explicitly (e.g. 'custom.plugins.snacks')
368+
369+
-- Note: If you customize your config for yourself,
370+
-- it’s best to remove the Telescope plugin config entirely
371+
-- instead of just disabling it here, to keep your config clean.
372+
enabled = true,
363373
event = 'VimEnter',
364374
dependencies = {
365375
'nvim-lua/plenary.nvim',
@@ -438,6 +448,44 @@ require('lazy').setup({
438448
vim.keymap.set('n', '<leader>sc', builtin.commands, { desc = '[S]earch [C]ommands' })
439449
vim.keymap.set('n', '<leader><leader>', builtin.buffers, { desc = '[ ] Find existing buffers' })
440450

451+
-- This runs on LSP attach per buffer (see main LSP attach function in 'neovim/nvim-lspconfig' config for more info,
452+
-- it is better explained there). This is a little bit redundant, but we can switch off telescope for an optional
453+
-- picker like snacks more easily when the keymaps are defined in the plugin itself.
454+
-- It sets up buffer-local keymaps, autocommands, and other LSP-related settings
455+
-- whenever an LSP client attaches to a buffer.
456+
457+
vim.api.nvim_create_autocmd('LspAttach', {
458+
group = vim.api.nvim_create_augroup('telescope-lsp-attach', { clear = true }),
459+
callback = function(event)
460+
local buf = event.buf
461+
462+
-- Find references for the word under your cursor.
463+
vim.keymap.set('n', 'grr', builtin.lsp_references, { buffer = buf, desc = '[G]oto [R]eferences' })
464+
465+
-- Jump to the implementation of the word under your cursor.
466+
-- Useful when your language has ways of declaring types without an actual implementation.
467+
vim.keymap.set('n', 'gri', builtin.lsp_implementations, { buffer = buf, desc = '[G]oto [I]mplementation' })
468+
469+
-- Jump to the definition of the word under your cursor.
470+
-- This is where a variable was first declared, or where a function is defined, etc.
471+
-- To jump back, press <C-t>.
472+
vim.keymap.set('n', 'grd', builtin.lsp_definitions, { buffer = buf, desc = '[G]oto [D]efinition' })
473+
474+
-- Fuzzy find all the symbols in your current document.
475+
-- Symbols are things like variables, functions, types, etc.
476+
vim.keymap.set('n', 'gO', builtin.lsp_document_symbols, { buffer = buf, desc = 'Open Document Symbols' })
477+
478+
-- Fuzzy find all the symbols in your current workspace.
479+
-- Similar to document symbols, except searches over your entire project.
480+
vim.keymap.set('n', 'gW', builtin.lsp_dynamic_workspace_symbols, { buffer = buf, desc = 'Open Workspace Symbols' })
481+
482+
-- Jump to the type of the word under your cursor.
483+
-- Useful when you're not sure what type a variable is and you want to see
484+
-- the definition of its *type*, not where it was *defined*.
485+
vim.keymap.set('n', 'grt', builtin.lsp_type_definitions, { buffer = buf, desc = '[G]oto [T]ype Definition' })
486+
end,
487+
})
488+
441489
-- Slightly advanced example of overriding default behavior and theme
442490
vim.keymap.set('n', '<leader>/', function()
443491
-- You can pass additional configuration to Telescope to change the theme, layout, etc.
@@ -532,35 +580,10 @@ require('lazy').setup({
532580
-- or a suggestion from your LSP for this to activate.
533581
map('gra', vim.lsp.buf.code_action, '[G]oto Code [A]ction', { 'n', 'x' })
534582

535-
-- Find references for the word under your cursor.
536-
map('grr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
537-
538-
-- Jump to the implementation of the word under your cursor.
539-
-- Useful when your language has ways of declaring types without an actual implementation.
540-
map('gri', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation')
541-
542-
-- Jump to the definition of the word under your cursor.
543-
-- This is where a variable was first declared, or where a function is defined, etc.
544-
-- To jump back, press <C-t>.
545-
map('grd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition')
546-
547583
-- WARN: This is not Goto Definition, this is Goto Declaration.
548584
-- For example, in C this would take you to the header.
549585
map('grD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
550586

551-
-- Fuzzy find all the symbols in your current document.
552-
-- Symbols are things like variables, functions, types, etc.
553-
map('gO', require('telescope.builtin').lsp_document_symbols, 'Open Document Symbols')
554-
555-
-- Fuzzy find all the symbols in your current workspace.
556-
-- Similar to document symbols, except searches over your entire project.
557-
map('gW', require('telescope.builtin').lsp_dynamic_workspace_symbols, 'Open Workspace Symbols')
558-
559-
-- Jump to the type of the word under your cursor.
560-
-- Useful when you're not sure what type a variable is and you want to see
561-
-- the definition of its *type*, not where it was *defined*.
562-
map('grt', require('telescope.builtin').lsp_type_definitions, '[G]oto [T]ype Definition')
563-
564587
-- The following two autocommands are used to highlight references of the
565588
-- word under your cursor when your cursor rests there for a little while.
566589
-- See `:help CursorHold` for information about when this is executed

0 commit comments

Comments
 (0)