[terminal] IJPL-215801 Disable terminal command completion action in Unix PowerShell

Make it enabled only for Bash and Zsh.


(cherry picked from commit 0d7baf6a13c5dc4d9b5c72176000155dc9591133)

IJ-CR-180793

GitOrigin-RevId: fe4a78ea7a1cbf99081c3dc4168bea023e13d1c2
This commit is contained in:
Konstantin Hudyakov
2025-11-03 11:45:47 +00:00
committed by intellij-monorepo-bot
parent 0ea1d587eb
commit 4025d5d1d3
5 changed files with 26 additions and 1 deletions
@@ -16,6 +16,7 @@ import org.jetbrains.plugins.terminal.block.reworked.TerminalCommandCompletion
import org.jetbrains.plugins.terminal.block.util.TerminalDataContextUtils.isOutputModelEditor
import org.jetbrains.plugins.terminal.block.util.TerminalDataContextUtils.isSuppressCompletion
import org.jetbrains.plugins.terminal.block.util.TerminalDataContextUtils.terminalEditor
import org.jetbrains.plugins.terminal.session.guessShellName
import org.jetbrains.plugins.terminal.util.getNow
import org.jetbrains.plugins.terminal.view.shellIntegration.TerminalOutputStatus.TypingCommand
@@ -36,9 +37,12 @@ internal class TerminalCommandCompletionActionGen2 : BaseCodeCompletionAction(),
override fun update(e: AnActionEvent) {
super.update(e)
val project = e.project
val isCommandTypingMode = e.terminalView?.shellIntegrationDeferred?.getNow()?.outputStatus?.value == TypingCommand
val terminalView = e.terminalView
val shellName = terminalView?.startupOptionsDeferred?.getNow()?.guessShellName()
val isCommandTypingMode = terminalView?.shellIntegrationDeferred?.getNow()?.outputStatus?.value == TypingCommand
e.presentation.isEnabledAndVisible = e.terminalEditor?.isOutputModelEditor == true
&& project != null && TerminalCommandCompletion.isEnabled(project)
&& shellName != null && TerminalCommandCompletion.isSupportedForShell(shellName)
&& isCommandTypingMode
}
@@ -20,6 +20,8 @@ import org.jetbrains.plugins.terminal.block.reworked.TerminalCommandCompletion
import org.jetbrains.plugins.terminal.block.reworked.TerminalSessionModel
import org.jetbrains.plugins.terminal.block.reworked.TerminalUsageLocalStorage
import org.jetbrains.plugins.terminal.block.util.TerminalDataContextUtils.isOutputModelEditor
import org.jetbrains.plugins.terminal.session.TerminalStartupOptions
import org.jetbrains.plugins.terminal.session.guessShellName
import org.jetbrains.plugins.terminal.session.impl.TerminalState
import org.jetbrains.plugins.terminal.util.getNow
import org.jetbrains.plugins.terminal.view.TerminalOutputModel
@@ -48,6 +50,7 @@ internal open class TerminalEventsHandlerImpl(
private val scrollingModel: TerminalOutputScrollingModel?,
private val outputModel: TerminalOutputModel,
private val shellIntegrationDeferred: Deferred<TerminalShellIntegration>?,
private val startupOptionsDeferred: Deferred<TerminalStartupOptions>?,
private val typeAhead: TerminalTypeAhead?,
) : TerminalEventsHandler {
private var ignoreNextKeyTypedEvent: Boolean = false
@@ -408,9 +411,11 @@ internal open class TerminalEventsHandlerImpl(
private fun scheduleCompletionPopupIfNeeded(charTyped: Char) {
val project = editor.project ?: return
val shellName = startupOptionsDeferred?.getNow()?.guessShellName() ?: return
val shellIntegration = shellIntegrationDeferred?.getNow() ?: return
if (editor.isOutputModelEditor
&& TerminalCommandCompletion.isEnabled(project)
&& TerminalCommandCompletion.isSupportedForShell(shellName)
&& TerminalOptionsProvider.instance.showCompletionPopupAutomatically
&& shellIntegration.outputStatus.value == TerminalOutputStatus.TypingCommand
&& canTriggerCompletion(charTyped)
@@ -170,6 +170,7 @@ class TerminalViewImpl(
scrollingModel = null,
alternateBufferModel,
shellIntegrationDeferred = null,
startupOptionsDeferred = null,
typeAhead = null,
)
configureOutputEditor(
@@ -217,6 +218,7 @@ class TerminalViewImpl(
scrollingModel,
outputModel,
shellIntegrationDeferred,
startupOptionsDeferred,
typeAhead = outputModelController
)
@@ -10,6 +10,7 @@ import com.intellij.platform.eel.provider.getEelDescriptor
import com.intellij.util.system.OS
import org.jetbrains.annotations.ApiStatus
import org.jetbrains.annotations.TestOnly
import org.jetbrains.plugins.terminal.session.ShellName
@ApiStatus.Internal
object TerminalCommandCompletion {
@@ -22,6 +23,10 @@ object TerminalCommandCompletion {
&& project.getEelDescriptor() == LocalEelDescriptor // Disable in non-local projects for now as it requires additional support
}
fun isSupportedForShell(name: ShellName): Boolean {
return name == ShellName.ZSH || name == ShellName.BASH
}
@TestOnly
fun enableForTests(parentDisposable: Disposable) {
Registry.get(REGISTRY_KEY).setValue(true, parentDisposable)
@@ -28,6 +28,7 @@ import org.jetbrains.plugins.terminal.block.completion.spec.ShellCommandSpecConf
import org.jetbrains.plugins.terminal.block.completion.spec.ShellCommandSpecInfo
import org.jetbrains.plugins.terminal.block.completion.spec.ShellCommandSpecsProvider
import org.jetbrains.plugins.terminal.block.reworked.TerminalCommandCompletion
import org.jetbrains.plugins.terminal.session.impl.TerminalStartupOptionsImpl
import org.jetbrains.plugins.terminal.util.terminalProjectScope
import org.jetbrains.plugins.terminal.view.TerminalOffset
import org.jetbrains.plugins.terminal.view.TerminalOutputModel
@@ -56,6 +57,14 @@ class TerminalCompletionFixture(val project: Project, val testRootDisposable: Di
val shellIntegration = TerminalShellIntegrationImpl(outputModel, view.sessionModel, terminalScope.childScope("TerminalShellIntegration"))
view.shellIntegrationDeferred.complete(shellIntegration)
// Need to specify some options to make `TerminalCommandCompletion.isSupportedForShell` pass.
val startupOptions = TerminalStartupOptionsImpl(
shellCommand = listOf("/bin/zsh", "--login", "-i"),
workingDirectory = project.basePath!!,
envVariables = emptyMap(),
)
view.startupOptionsDeferred.complete(startupOptions)
shellIntegration.onPromptFinished(TerminalOffset.ZERO) // To make TerminalOutputStatus = TypingCommand
assertEquals(TerminalOutputStatus.TypingCommand, shellIntegration.outputStatus.value)