Skip to content

Commit c220bb4

Browse files
committed
fix: Fixed casting unfiltered output class for SSH interpreters
Resolves #252
1 parent 027a041 commit c220bb4

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

77
## [Unreleased]
88

9+
### Fixed
10+
11+
- [[#252]](https://github.com/Roboroads/laravel-tinker/issues/252) Cast exception when running on an SSH interpreter
12+
913
## [2.6.0] - 2023-04-16
1014

1115
### Added

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pluginGroup = nl.deschepers.laraveltinker
44
pluginName = Laravel Tinker
55
pluginRepositoryUrl = https://github.com/JetBrains/intellij-platform-plugin-template
66
# SemVer format -> https://semver.org
7-
pluginVersion = 2.6.0
7+
pluginVersion = 2.6.1
88

99
# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
1010
pluginSinceBuild = 212

src/main/kotlin/nl/deschepers/laraveltinker/util/PhpArtisanTinkerUtil.kt

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import com.intellij.openapi.progress.ProgressManager
1212
import com.intellij.openapi.progress.Task.Backgroundable
1313
import com.intellij.openapi.project.Project
1414
import com.intellij.openapi.wm.ToolWindowManager
15+
import com.intellij.remote.BaseRemoteProcessHandler
1516
import com.jetbrains.php.composer.ComposerUtils
1617
import com.jetbrains.php.config.PhpProjectConfigurationFacade
1718
import com.jetbrains.php.config.commandLine.PhpCommandSettings
@@ -97,8 +98,7 @@ class PhpArtisanTinkerUtil(private val project: Project, private val phpCode: St
9798
val tinkerRunSettings = projectSettings.parseJson()
9899
phpCommandSettings.addArguments(listOf("-r", phpTinkerCodeRunnerCode, phpCode, tinkerRunSettings.toString()))
99100

100-
val osProcessHandler = runConfiguration.createProcessHandler(project, phpCommandSettings, true) as OSProcessHandler
101-
processHandler = KillableProcessHandler(osProcessHandler.process, osProcessHandler.commandLine)
101+
processHandler = getAnsiUnfilteredProcessHandler(runConfiguration.createProcessHandler(project, phpCommandSettings, true))
102102

103103
ProcessTerminatedListener.attach(processHandler, project, "")
104104
} catch (ex: ExecutionException) {
@@ -128,7 +128,7 @@ class PhpArtisanTinkerUtil(private val project: Project, private val phpCode: St
128128
object : Backgroundable(project, Strings.get("lt.running")) {
129129
override fun run(progressIndicator: ProgressIndicator) {
130130
processHandler.startNotify()
131-
processHandler.processInput.writer().write("\u0004")
131+
processHandler.processInput?.writer()?.write("\u0004")
132132
while (!processHandler.isProcessTerminated) {
133133
Thread.sleep(250)
134134
try {
@@ -142,4 +142,21 @@ class PhpArtisanTinkerUtil(private val project: Project, private val phpCode: St
142142
}
143143
)
144144
}
145+
146+
private fun getAnsiUnfilteredProcessHandler(processHandler: ProcessHandler): ProcessHandler {
147+
if (processHandler is KillableProcessHandler) {
148+
return processHandler
149+
}
150+
151+
if (processHandler is OSProcessHandler) {
152+
return KillableProcessHandler(processHandler.process, processHandler.commandLine)
153+
}
154+
155+
if (processHandler is BaseRemoteProcessHandler<*>) {
156+
return BaseRemoteProcessHandler(processHandler.process, processHandler.commandLine, processHandler.charset)
157+
}
158+
159+
// Could not find suitable cast, return original
160+
return processHandler
161+
}
145162
}

0 commit comments

Comments
 (0)