Skip to content

Commit 0436e9e

Browse files
tjdevriesPhilipp Szechenyiszechporiori1703philipp
authored andcommitted
feat: move Telescope config to be contained by plugin (nvim-lua#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 <48057913+oriori1703@users.noreply.github.com> * fix formatting in accordance to stylua so that pipeline passes --------- Co-authored-by: Philipp Szechenyi <philipp.szechenyi@cgm.com> Co-authored-by: Philipp Szechenyi <45265588+szechp@users.noreply.github.com> Co-authored-by: Ori Perry <48057913+oriori1703@users.noreply.github.com> Co-authored-by: philipp <philipp@philipps-MacBook-Pro.local> Signed-off-by: Dejan Ribič <dejan.ribic@gmail.com>
1 parent e8af80a commit 0436e9e

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
@@ -365,6 +365,16 @@ require('lazy').setup({
365365

366366
{ -- Fuzzy Finder (files, lsp, etc)
367367
'nvim-telescope/telescope.nvim',
368+
-- By default, Telescope is included and acts as your picker for everything.
369+
370+
-- If you would like to switch to a different picker (like snacks, or fzf-lua)
371+
-- you can disable the Telescope plugin by setting enabled to false and enable
372+
-- your replacement picker by requiring it explicitly (e.g. 'custom.plugins.snacks')
373+
374+
-- Note: If you customize your config for yourself,
375+
-- it’s best to remove the Telescope plugin config entirely
376+
-- instead of just disabling it here, to keep your config clean.
377+
enabled = true,
368378
event = 'VimEnter',
369379
dependencies = {
370380
'nvim-lua/plenary.nvim',
@@ -443,6 +453,44 @@ require('lazy').setup({
443453
vim.keymap.set('n', '<leader>sc', builtin.commands, { desc = '[S]earch [C]ommands' })
444454
vim.keymap.set('n', '<leader><leader>', builtin.buffers, { desc = '[ ] Find existing buffers' })
445455

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

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

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

0 commit comments

Comments
 (0)