hsnips icon indicating copy to clipboard operation
hsnips copied to clipboard

Expanding snippets inside snippets deletes tabstops

Open Frankwii opened this issue 1 year ago • 77 comments

Possibly very related to #157.

When expanding a snippet inside another snippet, all tabstops of the former snippet are deleted. An example:

snippet OOO "Omega" iA
\Omega
endsnippet

snippet II "\int" i
\\int_{$1}${2:f}~d${3:\\mu}
endsnippet

If I write "OOO" inside tabstop $1 of "\int", the snipet "Omega" is expanded correctly, but the tabstops $2 and $3 of "\int" disappear.

This doesn't happen with "native" vscode snippets.

Frankwii avatar Feb 06 '24 10:02 Frankwii

Additional note, downgrading VS Code to the December 2023 version fixed this bug for me.

XRay71 avatar Feb 07 '24 15:02 XRay71

I am having the same issue, but downgrading did fix it for me.

Alex2134556 avatar Feb 16 '24 07:02 Alex2134556

Anyone find another fix to this? I am using linux (arch) and have a hard time downgrading as I got vscode from the AUR

Oskar-Idland avatar Feb 23 '24 15:02 Oskar-Idland

Any update? I originally downgraded to December 2023 but thought I'd retry and this is still an issue. I haven't been able to figure out what part of the VSCode update affected this to think of a workaround. Any ideas for what it may be?

gwesley96 avatar Mar 07 '24 01:03 gwesley96

Nothing new. Still does not work. Have you @gwesley96 tried any other versions later than the December one? Would be ideal to see which exact version causes issues.

Oskar-Idland avatar Mar 07 '24 09:03 Oskar-Idland

@Oskar-Idland, do you mean the commit or the release? I can try and figure out the latter.

PiotrSokol avatar Mar 07 '24 13:03 PiotrSokol

Yes i meant the latest vscode release where expansions works as intended. Hopefully it helps resolve the issue to narrow it down

Oskar-Idland avatar Mar 07 '24 15:03 Oskar-Idland

Ok, tabstops still work in 1.85.2 but not 1.86.0.

PiotrSokol avatar Mar 07 '24 16:03 PiotrSokol

I tried seeing the difference on the 1.86 commit, but could not see anything that made sense. Anyone able to try and debug this?

Oskar-Idland avatar Mar 08 '24 15:03 Oskar-Idland

Same issue here

oiiiiiiii avatar Mar 12 '24 09:03 oiiiiiiii

Experimented more in v.1.87.2 and found the following:

  1. LaTeX Utilities's snippets and the ones built into vscode still works while nested. Only hsnips fails.
  2. I also noticed that you must have the hsnips by OrangeX4 (https://github.com/OrangeX4/hsnips) to be able to open the snippet directory or files or be able to activate any snippets at all. If I only had draivin's (this) version of hsnips I could not even open the snippet file as I got the following error: image

Oskar-Idland avatar Mar 14 '24 17:03 Oskar-Idland

I'm still coming up with nothing. I've looked through all the details and couldn't find anything that on the surface would affect hsnips/tabstops. Has anyone else found anything yet?

gwesley96 avatar Mar 25 '24 01:03 gwesley96

Anyone know the maintainers (@draivin @mfederczuk) of the extension is on it?

Oskar-Idland avatar Apr 01 '24 13:04 Oskar-Idland

Anyone know the maintainers (@draivin @mfederczuk) of the extension is on it?

Just FYI I'm not a maintainer here.
I've only contributed some code once.

mfederczuk avatar Apr 01 '24 13:04 mfederczuk

For any Arch Linux users reading this, just download the tar ball from 1.85 (other distros has their versions there as well), extract to some directory of choice (I chose ~/VSCode_Old), then just make a symlink from /usr/bin/code to the executable at VSCode-linux-x64/bin/code where ever you extracted it. I renamed the newest binary to code_new just to have it somewhere:

[oskar@archlinux] /usr/bin $ lsd -1 | grep ^code
code ⇒ /home/oskar/VSCode_Old/VSCode-linux-x64/bin/code
code_new

Everything else (settings, snippets etc) remained the same.

Oskar-Idland avatar Apr 05 '24 09:04 Oskar-Idland

Is anybody able to make the above solution work for MacOS?

Alex2134556 avatar Apr 17 '24 10:04 Alex2134556

If you press the link I posted above, you will see the download link for Mac as well as Windows and Linux. This is much simpler for you guys

Oskar-Idland avatar Apr 17 '24 11:04 Oskar-Idland

Oh okay, it sounds like you merely downgraded your Visual Studio Code (I guess your point of the comment was to make it work for linux). Yes, that's what I have been doing for the time being.

Alex2134556 avatar Apr 17 '24 11:04 Alex2134556

Hope this gets fixed. Can't use the python extension (and probably many others) on lower than v1.86

Oskar-Idland avatar Apr 17 '24 12:04 Oskar-Idland

Anyone have actual knowledge about the project and it's structure or Typescript? I have neither, but know programming and would love to help sort this out, but it is hard to tell what is wrong, without knowledge of the project

Oskar-Idland avatar May 06 '24 13:05 Oskar-Idland

Could it be possible that this is a vscode issue and raising the issue there would get it fixed or maybe some pointers towards solving the issue?

Alex2134556 avatar Jun 03 '24 11:06 Alex2134556

Testing with the regular user snippets, they preserve tabstops if nested

Oskar-Idland avatar Jun 04 '24 10:06 Oskar-Idland

I found where the problem lies. In VSCode 1.86.0, at line 538 of the file src/vs/workbench/api/browser/mainThreadEditor.ts,

snippetController.insert(template, {
	overwriteBefore: 0, overwriteAfter: 0,
	undoStopBefore: opts.undoStopBefore, undoStopAfter: opts.undoStopAfter,
	clipboardText
});

has been replaced with

const edits: ISnippetEdit[] = ranges.map(range => ({ range: Range.lift(range), template }));
snippetController.apply(edits, {
	overwriteBefore: 0, overwriteAfter: 0,
	undoStopBefore: opts.undoStopBefore, undoStopAfter: opts.undoStopAfter,
	clipboardText
});

Reverting this change should allow the compiled vscode to function properly with hypersnips.

yiktllw avatar Jun 09 '24 13:06 yiktllw

Great job!! How did you find it? There were soooo many files and changes I gave up looking after a while.

I think the next step should be to find what part of hyprsnips interact with this feature, instead of patching vscode. Nested snippets still work with other snippet programs, so it must be possible.

Oskar-Idland avatar Jun 09 '24 13:06 Oskar-Idland

Searching through the files, I see no mention of this "snippetController". Do you know in what context it is used ?

Oskar-Idland avatar Jun 09 '24 14:06 Oskar-Idland

@yiktllw Thank you very much for finding the error. Can you detail the process as to how we can achieve the same? I tried cloning the repository and making the change, but I keep running in errors trying to compile the repository.

Alex2134556 avatar Jun 09 '24 15:06 Alex2134556

@yiktllw Thank you very much for finding the error. Can you detail the process as to how we can achieve the same? I tried cloning the repository and making the change, but I keep running in errors trying to compile the repository.

I tried the latest source code of VSCode(1.90.0). After modifying

const edits: ISnippetEdit[] = ranges.map(range => ({ range: Range.lift(range), template }));
snippetController.apply(edits, {
	overwriteBefore: 0, overwriteAfter: 0,
	undoStopBefore: opts.undoStopBefore, undoStopAfter: opts.undoStopAfter,
	clipboardText
});

to

snippetController.insert(template, {
	overwriteBefore: 0, overwriteAfter: 0,
	undoStopBefore: opts.undoStopBefore, undoStopAfter: opts.undoStopAfter,
	clipboardText
});

I also removed

import { ISnippetEdit } from 'vs/editor/contrib/snippet/browser/snippetSession';

from the beginning of the file. Following these changes, I was able to compile the code successfully.

yiktllw avatar Jun 09 '24 15:06 yiktllw

Searching through the files, I see no mention of this "snippetController". Do you know in what context it is used ?

It was mentioned at line 530 of the file:

// import { SnippetController2 } from 'vs/editor/contrib/snippet/browser/snippetController2';
const snippetController = SnippetController2.get(this._codeEditor);

I'm not sure about the specific usage of snippetController either.

yiktllw avatar Jun 09 '24 16:06 yiktllw

yeah I tried looking through any mentioned of everything mentioned above in both hsnips and in the hscope repo. I found nothing.

Oskar-Idland avatar Jun 09 '24 16:06 Oskar-Idland

@yiktllw Okay, I am able to change the line inside the src folder and I was also able to run the yarn and yarn watch commands on the terminal. However, I am not sure how to actually produce the application of vscode. Can you provide some instructions for that?

Alex2134556 avatar Jun 09 '24 16:06 Alex2134556