Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accepting without breaking the current snippet. #624

Open
Cih2001 opened this issue Dec 17, 2024 · 3 comments
Open

Accepting without breaking the current snippet. #624

Cih2001 opened this issue Dec 17, 2024 · 3 comments
Labels
feature New feature or request snippets Built-in provider and library for snippets

Comments

@Cih2001
Copy link

Cih2001 commented Dec 17, 2024

Feature Description

I looked at the documentations. There are two commands available to accept the suggested item accept and select_and_accept. However, they both break the snippet, so if I accept a suggestion for the first parameter, then snippet is broken and I cant jump to the next part using snippet_forward or snippet_backward. Is there a way to accept a suggestion without breaking the current snippet?

Screenshot from 2024-12-17 19-51-18

Using "super-tab" preset, here after hitting tab, I can select testString but cannot jump to the next parameter anymore as the snippet is broken.

@Cih2001 Cih2001 added the feature New feature or request label Dec 17, 2024
@Saghen Saghen added the snippets Built-in provider and library for snippets label Dec 17, 2024
@Saghen Saghen closed this as completed in 284dd37 Dec 18, 2024
@Cih2001
Copy link
Author

Cih2001 commented Dec 19, 2024

Hey, Thanks for your fast response. I think I didn't provide a good enough example, and weren't probably clear with my explanations, and the suggested fix isn't exactly what I wished for. So let me try again.

It seems that suggested fix works as long as the first parameter is just a simple string. In my example above, testString is actually a variable name defined 2 lines above where it is used. Consider the following code:

Screenshot from 2024-12-19 23-10-43

Now if I hit tab, I expect the first parameter of the snippet to be set to the variable format defined above, while still being able to jump to the next parameter.

The keymap below is exactly what I want to achieve.

["<Tab>"] = {
	function(cmp)
		if cmp.snippet_active() then
			cmp.accept()
			return cmp.snippet_forward()
		end
		return cmp.select_and_accept()
	end,
	"fallback",
}

Which works just fine as long as the first parameter is a string, not any other type of suggestion.

@Sahas-Ananth
Copy link
Contributor

Sahas-Ananth commented Dec 19, 2024

@Cih2001 Is it possible you have (by default) set completion.accept.auto_brackets.enabled = true? I had this and it broke my snippets. Once I turned it off, functions and stuff started working without snippets breaking.

@Cih2001
Copy link
Author

Cih2001 commented Dec 20, 2024

@Cih2001 Is it possible you have (by default) set completion.accept.auto_brackets.enabled = true? I had this and it broke my snippets. Once I turned it off, functions and stuff started working without snippets breaking.

No, I disabled that, the problem still persist. It's not because of the auto brackets, since like I mentioned in my previous comment, it works fine if the first parameter is a string, so 284dd37 partially worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request snippets Built-in provider and library for snippets
Projects
None yet
Development

No branches or pull requests

3 participants