From ca0d2bca290c90bc5fa83aa86b3afb733151bc3c Mon Sep 17 00:00:00 2001 From: Konstantin Hudyakov Date: Wed, 3 Dec 2025 11:36:50 +0200 Subject: [PATCH] [terminal] IJPL-220485 Fix exception during terminal popup completion statistics collection When lookup is reused, it can be closed without new last selected item set by `LAST_SELECTED_ITEM_KEY`. So, the `LAST_SELECTED_ITEM_KEY` can point to the `LookupElement` from the previous content of the lookup. While reused lookup will contain new `LookupArranger` instance, that will throw an exception if an unrelated lookup element is passed into `itemPattern` method. Fix it by clearing the `LAST_SELECTED_ITEM_KEY` value when lookup is reused. GitOrigin-RevId: 13c6607d0bf33bce3d08c6b769deec9290f34062 --- .../view/completion/TerminalCommandCompletionHandler.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/terminal/frontend/src/com/intellij/terminal/frontend/view/completion/TerminalCommandCompletionHandler.kt b/plugins/terminal/frontend/src/com/intellij/terminal/frontend/view/completion/TerminalCommandCompletionHandler.kt index 1e04ab113fb2..9d01d913f329 100644 --- a/plugins/terminal/frontend/src/com/intellij/terminal/frontend/view/completion/TerminalCommandCompletionHandler.kt +++ b/plugins/terminal/frontend/src/com/intellij/terminal/frontend/view/completion/TerminalCommandCompletionHandler.kt @@ -15,6 +15,7 @@ import com.intellij.openapi.project.Project import com.intellij.psi.PsiDocumentManager import com.intellij.terminal.frontend.action.TerminalFrontendDataContextUtils.terminalOutputModel import com.intellij.terminal.frontend.view.impl.toRelative +import org.jetbrains.plugins.terminal.block.reworked.TerminalCommandCompletion import org.jetbrains.plugins.terminal.block.util.TerminalDataContextUtils.terminalEditor import org.jetbrains.plugins.terminal.view.TerminalOutputModel @@ -102,6 +103,7 @@ internal class TerminalCommandCompletionHandler( val existing = LookupManager.getActiveLookup(editor) as? LookupImpl if (existing != null && existing.isCompletion) { existing.markReused() + existing.putUserData(TerminalCommandCompletion.LAST_SELECTED_ITEM_KEY, null) if (!autopopup) { existing.setLookupFocusDegree(LookupFocusDegree.FOCUSED) }