Listen to code completion events

Answered

Hi all! I’m conducting a user study on code completion behavior in IntelliJ. I’d like to listen to code completion events and collect their information, including:

  • Triggered time
  • Terminated time or duration
  • Termination state (canceled, applied, timeout, etc.)
  • The typed completion prefix
  • The collection of proposals presented to the user
  • The collection of proposals the user interacted with
  • The selected/applied proposal and its index/order in the proposal list
  • The completion contributor that each proposal originates from
  • Other completion context and parameters are nice to have

I’ve looked through the list of listeners at https://plugins.jetbrains.com/docs/intellij/extension-point-list.html, but I couldn't find anything that meets my needs.

I later found `com.intellij.codeInsight.lookup.LookupListener`, which has most of the information I need. I’d love to know if I’m on the right track and how to get the other information.

Many thanks!

0
4 comments

Hi,

Could you please clarify what information is missing after using LookupListener?

0

Of course. I added the `LookupListener` via the `com.intellij.codeInsight.lookup.LookupManagerListener#activeLookupChanged`. As of now, I’ve found the following information from `LookupListener`:

  • Triggered time from when the `LookupListener#lookupShown` is called.
  • Terminated time from when the `LookupListener#lookupCanceled` and `LookupListener#itemSelected` are called.
  • Termination state (only canceled and applied) from `LookupListener#lookupCanceled` and `LookupListener#itemSelected`. I’ve also found that I can check if the completion is canceled explicitly via `LookupEvent#isCanceledExplicitly`.
  • The typed completion prefix from `LookupEvent.getLookup.itemMatcher.getPrefix`
  • The collection of proposals presented to the user from `LookupEvent.getLookup.getItems`
  • The collection of proposals the user interacted with from collecting the `LookupEvent#getItem` each time `LookupListener#currentItemChanged` is called.
  • The selected/applied proposal `LookupEvent#getItem` when `LookupListener#itemSelected` is called. I assume that its order in the proposal list is the index of that item in the `LookupEvent.getLookup.getItems` list.

Since I submitted the question, I've found more things and I think mostly got what I needed. Please let me know if I have done it correctly or if there are better ways to get any of those. That said, I’m still looking for:

  • Any other termination states available apart from canceled and applied. Also, I’m having issue with `LookupListener#lookupCanceled` and `LookupListener#itemSelected` not triggering, while the others (`LookupListener#lookupShown` and `LookupListener#currentItemChanged`) are working fine. I set some breakpoints to check, but the debugger didn't stop at them.
  • The completion contributor that each proposal originates from
  • The completion context and parameters
0

Hi,

Your approach looks good to me, but I also suggest checking classes in this package in the IntelliJ Community sources:
https://github.com/JetBrains/intellij-community/tree/master/plugins/stats-collector/src/com/intellij/stats/completion/tracker

I'm not sure all of your required data is covered or even possible (I had a brief look and could not find anything about contributor information and completion context/params).

Please also remember to not collect and send any data without an explicit user's consent.

0

Of course! Explicit user consent is a must.

Also, thank you for the pointer. I’ll look into it.

0

Please sign in to leave a comment.