@mauricio.szabo Maybe you should port parinfer-plus to VS Code? 😉
@seancorfield I'm trying really :rolling_on_the_floor_laughing:. But the API is so limited and sometimes even buggy that my first experiments got me unpredictable results :(
Which maybe goes back to my original thought. Is there some subset of effective parinfer features that is useful and more easily implemented?
parinfer-rust is simply and easily implemented to be honest. You just have to get the state before the change and the state after the change, and then change the document with what parinfer-rust returns
That sounds workable.
Yes, but the problem is that VSCode API does not have
1. A way to capture the state before and after a change
2. A way to change current text
3. The only way to change text is by a FormattingEditProvider
that only allows you to capture some changes - no backspace, for example, nor delete
4. onDidChangeTextDocument
fires before the change is perceived by the TextEditor, so you can't know for example what's the current cursor position. Also, after FormattingEditProvider
fires, if you issue changes to the document it'll fire "didChangeTextDocument" can fire again, so you have to catch this.
5. VSCode does not provide lots of APIs to, for example, by a "changes" object patch a text into another (also, there are at least 2 "changes" object, and they are incompatible between each other)
These maybe are all workable in some way, but it's incredibly fragile. For example, you could hook onDidChange
and run parinfer, accumulate the result, then apply then on edit provider, but there's still the case of multiple backspaces / deletions that will not fire the edit provider (and both smart-mode and paren-mode depends a lot on backspace)