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

coupling the whole code in a document after inserting a snip and formatting it #265

Closed
hemedani opened this issue Jan 17, 2022 · 5 comments

Comments

@hemedani
Copy link

I'm copying and editing a snip from your example and creating this one :

		s(
			"llog",
			fmt(
				[[
            //Parameters: {2}
            console.info({1}, " ------- ");
			]],
				{
					i(1),
					rep(1),
				}
			)
		),

but when I used this snip in any document it's crashed and coupled the whole code after formatting the document.
for example, convert this code

function sum(number1, number2) {
  return number1 + number2;
}

const mySum = sum(2, 5);

console.log(mySum);

const newSum = (num1, num2) => num1 + num2;

const resultNewSum = newSum(2, 7);

to this code :

function sum(number1, number2) {
  return number1 + number2;
}

const mySum = sum(2, 5);

console.log(mySum);

const newSum = (num1, num2) => num1 + num2;

const resultNewSum = newSum(2, 7);

//Parameters: resultNewSum
function sum(number1, number2) {
  return number1 + number2;
}

const mySum = sum(2, 5);

console.log(mySum);

const newSum = (num1, num2) => num1 + num2;

const resultNewSum = newSum(2, 7);

//Parameters: resultNewSum
console.info(resultNewSum, ' ------- ');
@L3MON4D3
Copy link
Owner

Yeah, that's a known limitation :/

Luasnip tracks node-positions via extmarks, these get pushed around when formatting overwrites the entire buffer.
The only solution is to disable formatting or find a way to apply formatting only to changed regions of the buffer.

I'm going to close this as this issue is already tracked in #174 and #218.

@buschco
Copy link

buschco commented Feb 3, 2023

Can I somehow tell LuaSnip to stop tracking anything?

@L3MON4D3
Copy link
Owner

L3MON4D3 commented Feb 3, 2023

Not really, if you want it to work :D
What do you want to achieve? Prevent this issue?

@buschco
Copy link

buschco commented Feb 3, 2023

Maybe I am not understanding this issue. I achieved my desired behavior with this autocmd:

vim.api.nvim_create_autocmd({"InsertLeave"}, {
  pattern = {"*"},
  command = ":LuaSnipUnlinkCurrent"
})

My snippets only have one argument anyway, which will be copied to one or more places.
E.g.:

  s("action", {
    t("function "), 
    i(1),
    t({
      " ():ThunkAction {",
      "return (dispatch, getState) => {",
      "",
      "}",
      "}"
    })
  }),

I type action, select the suggestion from nvim-cmp and my cursor will be pushed to the i(1) position. I type something, leave insert and I am finished with the snippet workflow, able to save and format my buffer.

@L3MON4D3
Copy link
Owner

L3MON4D3 commented Feb 3, 2023

Oh, yeah that might also go some way to prevent these issues👍
They also can't (according to my understanding of the issue) occur in snippets without functionNodes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants