LuaSnip icon indicating copy to clipboard operation
LuaSnip copied to clipboard

Weird extmark placement for first placeholder

Open bew opened this issue 2 years ago • 7 comments

(this bug might be linked to #1019 (also with cmp))

With the following snippet:

snip("rbad", {desc = "bad local require"},
 { t"(manually) local ", i(1), t' = require"', i(2), t'"' }
)

Peek 2023-09-28 00-38

Here I try to use the snippet 3 times:

  1. with direct expansion via ls.expand() BUG
  2. by first selecting something in cmp but still using a direct expansion via ls.expand() ok
  3. by first selecting the snippet result then <C-y> ok

Also as you can see clearly on 2nd try, the cmp popup isn't hidden for some reason, it's quite annoying.

And when I try to close cmp's popup in my mappings (using if cmp.visible() then cmp.close() end before luasnip actions) I get a slightly different weird behavior:

Peek 2023-09-28 00-51 Same steps as above, but the 2nd one is also buggy :disappointed:.


I'm really looking for a way to quickly expand snippets without getting weird cmp going in the way or having extmarks bugs.

I don't want to have to select the right result in cmp just to be able to expand without issues my 2 letters trigger ^^

bew avatar Sep 27 '23 22:09 bew

Weird! I tried to reproduce it, and couldn't, at least with my current config.

https://github.com/L3MON4D3/LuaSnip/assets/41961280/d4a28a5f-d8eb-4a36-9c37-88a530720978

Here's my cmp-config, any major differences?

local cmp = require'cmp'
local types = require("cmp.types")
-- local session = require("session")

cmp.setup {
	completion = {
		autocomplete = {cmp.TriggerEvent.TextChanged},
		completeopt = "menu,menuone,select"
	},
	snippet = {
		expand = function(args)
			-- local override_snip = session.lsp_override_snips[args.body]
			-- if override_snip then
			-- 	require("luasnip").snip_expand(override_snip)
			-- else
				require("luasnip").lsp_expand(args.body)
			-- end
		end,
	},
	mapping = {
		['<C-d>'] = cmp.mapping.scroll_docs(-4),
		-- ['<C-f>'] = cmp.mapping.scroll_docs(4),
		['<C-y>'] = cmp.mapping.confirm(),
		['<C-n>'] = cmp.mapping.select_next_item({ behavior = types.cmp.SelectBehavior.Insert }),
		['<C-p>'] = cmp.mapping.select_prev_item({ behavior = types.cmp.SelectBehavior.Insert }),
	},
	sources = cmp.config.sources({
		{name = "path"},
		{name = "luasnip"}
	}),
	window = {
		documentation = false,
	},
	experimental = {
		native_menu = false,
		ghost_text = true
	},
}

Using cmp 5dce1b7, luasnip master.

L3MON4D3 avatar Sep 28 '23 06:09 L3MON4D3

Yeah that's what I thought, I'll try to repro with a minimal config later, probably this weekend.

bew avatar Sep 28 '23 06:09 bew

Oh, one common cause of messed up extmarks are formatters, do you have one enabled?

L3MON4D3 avatar Sep 28 '23 10:09 L3MON4D3

No no formatter at the moment

bew avatar Sep 28 '23 10:09 bew

It might be because I'm still using cmp's native menu.

Here is a reproduction script: https://gist.github.com/bew/63bf7c3b01a32e85836e621a1b220e26 Peek 2023-10-08 06-45

bew avatar Oct 08 '23 04:10 bew

Ah, nice! Seems like others have also run into this issue, #721 for example. I don't know the internals of cmp well, but there are relatively few nvim_buf_set_text/nvim_buf_set_lines IIRC, maybe you could track what text they modify?

L3MON4D3 avatar Oct 08 '23 07:10 L3MON4D3

Note that I'm not using cmp to confirm & expand the snippet: I directly use <C-k> to expand, so cmp's text changes shouldn't be happening

bew avatar Oct 08 '23 07:10 bew