# TypedHandlerDelegate not being called on every typed character

**URL:** <https://platform.jetbrains.com/t/typedhandlerdelegate-not-being-called-on-every-typed-character/82>\
**Category:** IntelliJ Platform\
**Created:** [February 5, 2025, 10:34am UTC](https://platform.jetbrains.com/t/typedhandlerdelegate-not-being-called-on-every-typed-character/82 "2025-02-05T10:34:20Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![boni](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/boni/32/71_2.png) [@boni](https://platform.jetbrains.com/u/boni)\
**Post date:** [February 5, 2025, 10:34am UTC](https://platform.jetbrains.com/t/typedhandlerdelegate-not-being-called-on-every-typed-character/82/1 "2025-02-05T10:34:20Z")

</div>

I have implemented a `TypedHandlerDelegate` that is supposed to format my code after each keystroke. I have noticed however, that if I type too quickly, then the delegate’s `charTyped` callback function isn’t being called after the first typed character (according to my observations, this might be related to keydown events happening before the keyup of the previous character). Interestingly, this seems to only happen when starting a new word, if you continue an existing word then everything seems to work as intended no matter how fast you’re typing.

I have already tried adding `order="first"` in plugin.xml and moving the delegate declaration to the top of the file (per [this](https://intellij-support.jetbrains.com/hc/en-us/community/posts/18184654778130-TypedHandlerDelegate-not-called-each-character) similar forum post), to no avail.

Has anyone else experienced this issue? Has anyone found a solution for it?

---

<div class="post-metadata">

**Author:** ![yann.cebron](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/yann.cebron/32/15_2.png) [@yann.cebron](https://platform.jetbrains.com/u/yann.cebron)\
**Post date:** [February 5, 2025, 1:09pm UTC](https://platform.jetbrains.com/t/typedhandlerdelegate-not-being-called-on-every-typed-character/82/2 "2025-02-05T13:09:12Z")

</div>

Please share your code and sample scenario file(type).

---

<div class="post-metadata">

**Author:** ![boni](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/boni/32/71_2.png) [@boni](https://platform.jetbrains.com/u/boni)\
**Post date:** [February 5, 2025, 1:42pm UTC](https://platform.jetbrains.com/t/typedhandlerdelegate-not-being-called-on-every-typed-character/82/4 "2025-02-05T13:42:20Z")

</div>

I tried to send you a minimal reproducible example but couldn’t - the plugin I’m working on is quite big (and proprietary) and it seems like there might be some unwanted interactions between certain parts that stop the delegate’s callback function from being called sometimes. I think it has to do with our inlay hints and/or our completion contributors, and possibly more. I have also noticed that the bigger the file I’m editing is, the more likely it is for this issue to happen (although the file really doesn’t have to be too big for this to become a real annoyance)

What I don’t understand is why `order="first"` didn’t help with this issue as per my understanding, this piece of code is supposed to ensure that my delegate will get called first, before any of the other extensions (I have also tried `order="first, before xy"` but that didn’t help either).

Since I can’t share my code, I would appreciate if you could point me towards some resources that would help me ensure that my extensions don’t potentially block each other from being called, or if there are any ways how I could debug this issue, other than painstakingly trying all possible combinations of my extensions until I find the culprit (for example an easy way to observe what extensions are being called when).

---

<div class="post-metadata">

**Author:** ![jansorg](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/jansorg/32/52_2.png) [@jansorg](https://platform.jetbrains.com/u/jansorg)\
**Post date:** [February 5, 2025, 4:29pm UTC](https://platform.jetbrains.com/t/typedhandlerdelegate-not-being-called-on-every-typed-character/82/5 "2025-02-05T16:29:35Z")

</div>

The order attribute only defines the order of extensions of the same type, i.e. your handler delegate may be first of it’s kind but other extensions of a different type can be called before, of course. Also, if another handler delegate is also „first“, there‘s no guarantee which extensions is actually first.

The find the culprit, I recommend to set a breakpoint in your handler, find the caller and then debug the logic of the caller to find out why your handler is not being called (use logging breakpoints, for example).  
Using a profiler with thread activity monitoring is also useful, I prefer YourKit but AFAIK JetBrains‘s built-in profiler is supporting this, too.

In general, be careful calling a formatter from your handler. iirc it‘s called in a WriteAction and any long-running activity will block the UI. Especially external formatters would slow things down a lot.

---

<div class="post-metadata">

**Author:** ![boni](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/boni/32/71_2.png) [@boni](https://platform.jetbrains.com/u/boni)\
**Post date:** [February 6, 2025, 2:40pm UTC](https://platform.jetbrains.com/t/typedhandlerdelegate-not-being-called-on-every-typed-character/82/6 "2025-02-06T14:40:47Z")

</div>

Thank you for your answer, I have spent a good amount of time trying to debug this today. It seems I was wrong, since after disabling all but the essential extensions, I am still getting this behavior, although less often (so this issue might be performance related).

Right now I just have three extensions enabled in my plugin.xml: A `fileType`, a `lang.parserDefinition`, and my `typedHandler`. These are needed because we have or own custom language with our own lexer and parser (created with ANTLR4). When typing quickly, the `charTyped` callback is not called every time after the first typed character.

The formatting functionality inside `charTyped` is only used on a small part of the entire file, which I would expect to mitigate performance issues. But even if it did slow things down a lot, I would expect the UI to potentially hang, but in theory I should still see the `charTyped` callback being called after each character, which does not seem to be the case here.

Could you please confirm that this is indeed the intended behavior of this callback? Or are there any reasons why this callback might not be called in certain cases (such as for performance reasons)? I could not find anything about this in the documentation.

---

<div class="post-metadata">

**Author:** ![jansorg](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/jansorg/32/52_2.png) [@jansorg](https://platform.jetbrains.com/u/jansorg)\
**Post date:** [February 6, 2025, 4:03pm UTC](https://platform.jetbrains.com/t/typedhandlerdelegate-not-being-called-on-every-typed-character/82/7 "2025-02-06T16:03:05Z")

</div>

It’s best to check the sources.

This is the place where `charTyped` is called:

> <https://github.com/JetBrains/intellij-community/blob/fe77e198498ccc02238f054270498259e4c73d42/platform/lang-impl/src/com/intellij/codeInsight/editorActions/TypedHandler.java#L233-L236>

As you can see, there are many `return` statements before this line is reached. Other handlers can prevent your `charType` from being called.

Is `newTypingStarted` called as you’d expect it?

> <https://github.com/JetBrains/intellij-community/blob/fe77e198498ccc02238f054270498259e4c73d42/platform/lang-impl/src/com/intellij/codeInsight/editorActions/TypedHandler.java#L155-L157>

I can’t tell if `charTyped` is really called for every character or if there’s optimizations to skip it on fast typing. I wouldn’t rely on it.

---

<div class="post-metadata">

**Author:** ![boni](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/boni/32/71_2.png) [@boni](https://platform.jetbrains.com/u/boni)\
**Post date:** [February 6, 2025, 4:31pm UTC](https://platform.jetbrains.com/t/typedhandlerdelegate-not-being-called-on-every-typed-character/82/8 "2025-02-06T16:31:01Z")

</div>

Once again, thank you for your reply - I mistakenly assumed that you’re a JetBrains employee which is why I thought you might know the answer to my question. I have already debugged the file you’ve referenced and found that the `doExecute` method itself isn’t even being called, so something must be preventing it from being called further down in the code, but I am unable to figure out what exactly. `newTypingStarted` also isn’t being called properly.

I really need this function to be called on every typed character, or at least when the user has stopped typing (in the case of really fast consequent keypresses), otherwise the user experience is very incosistent as the user ends up with an unformatted file after typing. If this behavior of `TypedHandlerDelegate` is intended, then it should at least be documented and an alternative solution should be provided in my opinion.

---

<div class="post-metadata">

**Author:** ![yuriy.artamonov](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/yuriy.artamonov/32/48_2.png) [@yuriy.artamonov](https://platform.jetbrains.com/u/yuriy.artamonov)\
**Post date:** [February 7, 2025, 10:08am UTC](https://platform.jetbrains.com/t/typedhandlerdelegate-not-being-called-on-every-typed-character/82/9 "2025-02-07T10:08:50Z")

</div>

> [@boni](#):
>
> Since I can’t share my code

You always can share a minimal reproducible example without your project. We will be able to help then. It is quite easy to create a plugin stub via IDE Plugin wizard and add such an artificial example

---

<div class="post-metadata">

**Author:** ![boni](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/boni/32/71_2.png) [@boni](https://platform.jetbrains.com/u/boni)\
**Post date:** [February 13, 2025, 11:14am UTC](https://platform.jetbrains.com/t/typedhandlerdelegate-not-being-called-on-every-typed-character/82/10 "2025-02-13T11:14:28Z")

</div>

I have created a simple project where this problem can be reproduced: [GitHub](https://github.com/bonifacsolyom/IntelliJTestPlugin). You just need to clone it, run the plugin, create a project and start typing in a file.

There’s not much to this project, I just added a simple class that extends TypedHandlerDelegate and registered it in plugin.xml. All the class does is that it prints the characters that the user types. As you can see on this screenshot, not all characters that I typed are printed in the console (console is on the left):

 ![image](https://us1.discourse-cdn.com/flex001/uploads/jetbrains_platform/original/1X/ea4c397ae9e0ab2a95494339e3818db81ed45739.png)

Please note that this behavior seems to be dependent on performance, ie. the more overloaded my computer is, the slower I need to type for this to happen.

---

<div class="post-metadata">

**Author:** ![boni](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/boni/32/71_2.png) [@boni](https://platform.jetbrains.com/u/boni)\
**Post date:** [March 4, 2025, 12:30pm UTC](https://platform.jetbrains.com/t/typedhandlerdelegate-not-being-called-on-every-typed-character/82/11 "2025-03-04T12:30:59Z")

</div>

Update, if anyone else stumbles upon this thread, I have created a bug report about this: [IntelliJ Plugin Development: TypedHandlerDelegate’s charTyped callback not being called on every typed character : IJSDK-2393](https://youtrack.jetbrains.com/issue/IJSDK-2393/IntelliJ-Plugin-Development-TypedHandlerDelegates-charTyped-callback-not-being-called-on-every-typed-character). Hopefully it will be fixed soon.
