hsnips icon indicating copy to clipboard operation
hsnips copied to clipboard

Scope behavoir becomes random after a while

Open hainingpan opened this issue 3 years ago • 10 comments

The snippet which is intended in the context of math can be triggered even when it is in the text mode after using it for a while.

The scope is defined as

global
function math(context) {
    return context.scopes.some(s => s.startsWith("meta.math"));
}
endglobal

Here is an example of such unexpected behavior (note that the scope is always text.tex.latex, yet the snippet is triggered automatically) vscode_hypersnips

The snippet triggered here is (though it does not matter, every snippet can be triggered)

context math(context)
snippet `([\s])([A-Za-z])([\w]) ` "auto subscript" A
``rv=' '+m[2]+'_{'+m[3]+'} '``
endsnippet

It is difficult to reproduce this because once I restart vscode, everything becomes normal. But if I continue to use it for a while, this random behavior starts again.

Any comment for this or can I do something to show more debug info when this happens?

hainingpan avatar Sep 28 '21 19:09 hainingpan

when you input "is", because there is $ before is and $ after is, so hsnip think you are in math mode. try to use\ ( and\) instead of $.

A6669 avatar Oct 13 '21 11:10 A6669

I don't think so @A6669 . Maybe hscopes recognize the environment by getting textmate scopes . I met the same problem recently and I'm looking forward to the solution.

yfzhao20 avatar Oct 13 '21 12:10 yfzhao20

I don't think so @A6669 . Maybe hscopes recognize the environment by getting textmate scopes . I met the same problem recently and I'm looking forward to the solution.

you use \(\ ) or $?

A6669 avatar Oct 13 '21 12:10 A6669

Mostly $$. But you see , that problem emerges randomly. In most cases, it works normally. And after I reload VSCode, the problem disappears in the same position.

yfzhao20 avatar Oct 13 '21 12:10 yfzhao20

Mostly $$. But you see , that problem emerges randomly. In most cases, it works normally. And after I reload VSCode, the problem disappears in the same position.

try https://github.com/OrangeX4/hsnips

A6669 avatar Oct 13 '21 12:10 A6669

It's a good idea but the principles are different. hscope uses textmate scope while hsnips for math uses regex. Anyway I hope that the reason can be found. 👀

yfzhao20 avatar Oct 13 '21 14:10 yfzhao20

I have the same exact behavior as described by @yfzhao20. Both in that, the bug is seemingly random (the same action, the same position will only sometimes work) and that the bug is only fixed by restarting vscode. The only difference is I use \(\) instead of $$ but clearly, this does not make a difference. I have had no other issues with the extension thus far so I hope this can be fixed as it is one of my favorite extensions.

anthonyokc avatar Nov 15 '21 14:11 anthonyokc

I have the same exact behavior as described by @yfzhao20. Both in that, the bug is seemingly random (the same action, the same position will only sometimes work) and that the bug is only fixed by restarting vscode. The only difference is I use () instead of $$ but clearly, this does not make a difference. I have had no other issues with the extension thus far so I hope this can be fixed as it is one of my favorite extensions.

Maybe it is a bug in vscode.

A6669 avatar Nov 15 '21 15:11 A6669

@A6669 Using \(\) doesn't work too. I used \(\) for a long time, and I still ran into this problem. Everything is fine after restarting VSCode though.

sleepymalc avatar Feb 21 '22 00:02 sleepymalc

Is there any progress on this issue? I keep encountering it even with other contexts such as fenced code blocks in quarto markdown, i.e.

global
function r_code(context) {
    return context.scopes.some(s => s.startsWith("meta.embedded.block.r"));
}
endglobal

Sometimes snippet that are defined only in fenced blocks start expanding even in regular text, hence it seems to me that it is more general than simply math environments being broken..

This is really annoying, given that snippet expansion is a big part of my workflow.. If there are no workaround to this bug, I might consider returning to neovim and Ultisnips.

DedZago avatar Oct 24 '22 09:10 DedZago

Should be greatly improved as of latest patch, if there are new issues please open a new issue or reopen this one.

draivin avatar Dec 22 '22 10:12 draivin