ThePrimeagen / ThePrimeagen/init.lua

How are we jumping around in snippets?

Open
#45 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lua
Stars
4k
Forks
680
PR merge metrics
No merged PRs in 30d

Description

Hello. Thank you for this repo. As a result, I have some really sweet bindings set for the purpose of handling completion. However, I've been unable to setup my Tab and S-Tab bindings so they can be used exclusively to jump around between snippet placeholders. Adding the contents of my after/plugin/lsp.lua here in the hopes someone might shed some light. Thanks in advance.


local lsp = require("lsp-zero")

lsp.preset("recommended")


lsp.ensure_installed({
	'pyright',
	'bashls',
	'yamlls',
	'sumneko_lua',
})

lsp.nvim_workspace()

local cmp = require('cmp')
local luasnip = require("luasnip")
local cmp_select = {behavior = cmp.SelectBehavior.Select}

local cmp_mappings = lsp.defaults.cmp_mappings({
	['<C-k>'] = cmp.mapping.select_prev_item(cmp_select),
	['<C-j>'] = cmp.mapping.select_next_item(cmp_select),
	['<C-y>'] = cmp.config.disable,
	['<C-e>'] = cmp.config.disable,
	-- toggle completion
	['<C-l>'] = cmp.mapping(function()
		if cmp.visible() then
			cmp.abort()
		else
			cmp.complete()
		end
	end),
	-- navigate snippet placeholders
	['<Tab>'] = cmp.mapping(function(fallback)
		if luasnip.jumpable(1) then
			luasnip.jump(1)
		else
			fallback()
		end
	end, { "i", "s" }),
	['<S-Tab>'] = cmp.mapping(function(fallback)
		if luasnip.jumpable(-1) then
			luasnip.jump(-1)
		else
			fallback()
		end
	end, { "i", "s" }),
})

lsp.setup_nvim_cmp({
	mapping = cmp_mappings
})

lsp.set_preferences({
	suggest_lsp_servers = false,
	sign_icons = {
		error = 'E',
		warn = 'W',
		hint = 'H',
		info = 'I'
	}
})

lsp.on_attach(function(client, bufnr)
	local opts = {buffer = bufnr, remap = false, desc = "LSP mapping" }
	-- LSP actions
	vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
	vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts)
	vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
	vim.keymap.set("n", "<leader>la", vim.lsp.buf.code_action, opts)
	vim.keymap.set("n", "<leader>lr", vim.lsp.buf.references, opts)
	vim.keymap.set("n", "<leader>lR", vim.lsp.buf.rename, opts)
	vim.keymap.set("n", "<C-h>", vim.lsp.buf.signature_help, opts)
	vim.keymap.set("i", "<C-h>", vim.lsp.buf.signature_help, opts)
	-- Diagnostics
	vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, opts)
	vim.keymap.set("n", "]d", vim.diagnostic.goto_next, opts)
	vim.keymap.set("n", "gl", vim.diagnostic.open_float, opts)
end)

lsp.setup()

vim.diagnostic.config({
	virtual_text = false
})

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with after/plugin/lsp.lua and trace the cmp mappings for Tab and S-Tab, along with the luasnip jump checks shown in the issue. Reproduce the reported placeholder-navigation behavior in the displayed Neovim configuration; done means the bindings jump between snippet placeholders as requested.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua, neovim
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.