microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
162.43k stars 28.62k forks source link

When characters are typed at a rapid rate, textDocument/onTypeFormatting fails to fire #139968

Open smuccione opened 2 years ago

smuccione commented 2 years ago

Does this issue occur when all extensions are disabled?: Yes/No

Steps to Reproduce:

  1. enable onTypeFormatting in any language server.
  2. quickly type some code that would trigger onTypeFomatting, but rapidly type additional characters after the trigger character
  3. didChange notifications will be gathered together to minimize traffic to the language server.
  4. If the trigger character was present in one of the changes that were subsumed in follow-on messages, then the onTypeFormatting message is never sent to the language server.
jrieken commented 2 years ago

Yeah, typing is synchronous and formatting is async. We check if typing interfered with the result of the async formatting call and ignore it then. Maybe that logic can be tweaked but we problem won't go aways (unless we implement OT logic)

smuccione commented 2 years ago

My compiler supports two different front ends... one that's backwards compatible with a language that I wrote 30 years ago, which was very Pascal-like, but with C++ type classes. The other is a C++ style (with full type inferencing) front end.

It's the Pascal type language that's the issue... normally, closing a brace in C languages takes a fraction of a second longer than the Pascal type front end. As it is now, I trigger on the "d" in "end" for the on-type notification. Normally my body would type the end and a carriage return immediately after in one quick "word". This is where my problem occurs.

I'll try adding in another OT sequence point in the language server at the following location after the CR and any following indentation and see if I can get it to be smoother that way.

If not, I'll just retrain myself to be slower (I wish I could give up the Pascal front-end but it's actually in use commercially by a fairly decent number of clients (a lot of government work)).

Thanks for the quick feedback.