draivin / hsnips

HyperSnips: a powerful snippet engine for VS Code, inspired by vim's UltiSnips
MIT License
154 stars 25 forks source link

Scope behavoir becomes random after a while #79

Closed hainingpan closed 1 year ago

hainingpan commented 3 years ago

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?

A6669 commented 2 years ago

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 $.

yfzhao20 commented 2 years ago

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.

A6669 commented 2 years ago

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 $?

yfzhao20 commented 2 years ago

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.

A6669 commented 2 years ago

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

yfzhao20 commented 2 years ago

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. 👀

anthonyokc commented 2 years ago

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.

A6669 commented 2 years ago

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.

sleepymalc commented 2 years ago

@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.

DedZago commented 1 year ago

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.

draivin commented 1 year ago

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

DiegoRodriguezT commented 1 month ago

I keep having the same problem, any update? :(