Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't interrupt program execution when REPL is started right after upload. #313

Merged
merged 1 commit into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions scripts/microrepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ def main():
"""
The function that actually runs the REPL.
"""
if len(sys.argv) != 2:
print("Usage: microrepl.py /path/to/device")
if len(sys.argv) not in range(2, 3):
print("Usage: microrepl.py /path/to/device [--nointerrupt]")

port = sys.argv[1]
print('Device path', port)
Expand All @@ -97,7 +97,8 @@ def main():
miniterm.set_tx_encoding('utf-8')
miniterm.start()
sleep(0.5)
miniterm.serial.write(b'\x03') # Connecting stops the running program.
if len(sys.argv) != 3 or sys.argv[2] != '--nointerrupt':
miniterm.serial.write(b'\x03') # Connecting stops the running program.
try:
miniterm.join(True)
except KeyboardInterrupt:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.intellij.util.messages.Topic

interface MicroPythonReplControl {
fun stopRepl()
fun startOrRestartRepl()
fun startOrRestartRepl(interrupt: Boolean = true)
}

@Service(Service.Level.PROJECT)
Expand All @@ -16,8 +16,8 @@ class MicroPythonReplManager(private val project: Project) : MicroPythonReplCont
project.messageBus.syncPublisher(MICROPYTHON_REPL_CONTROL).stopRepl()


override fun startOrRestartRepl() =
project.messageBus.syncPublisher(MICROPYTHON_REPL_CONTROL).startOrRestartRepl()
override fun startOrRestartRepl(interrupt: Boolean) =
project.messageBus.syncPublisher(MICROPYTHON_REPL_CONTROL).startOrRestartRepl(interrupt)

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class ToolWindowReplTab(val module: Module, parent: Disposable) : MicroPythonRep
}
}

override fun startOrRestartRepl() {
override fun startOrRestartRepl(interrupt: Boolean) {
interruptBanner()
application.executeOnPooledThread {
synchronized(this) {
Expand All @@ -150,12 +150,12 @@ class ToolWindowReplTab(val module: Module, parent: Disposable) : MicroPythonRep
}
}
application.invokeLater(
{ startRepl() },
{ startRepl(interrupt) },
{ module.project.isDisposed })
}
}

private fun startRepl() {
private fun startRepl(interrupt: Boolean) {
val facet = module.microPythonFacet ?: return
val devicePath = facet.getOrDetectDevicePathSynchronously()

Expand All @@ -173,7 +173,9 @@ class ToolWindowReplTab(val module: Module, parent: Disposable) : MicroPythonRep
facet.pythonPath!!,
"${MicroPythonFacet.scriptsPath}/microrepl.py",
devicePath
)
).apply {
if(!interrupt) add("--nointerrupt")
}

val terminalRunner = LocalTerminalDirectRunner(module.project)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class MicroPythonRunConfiguration(project: Project, factory: ConfigurationFactor
if (runReplOnSuccess && state != null) {
return RunStateWrapper(state) {
ApplicationManager.getApplication().invokeLater {
project.service<MicroPythonReplManager>().startOrRestartRepl()
project.service<MicroPythonReplManager>().startOrRestartRepl(false)
ToolWindowManager.getInstance(project).getToolWindow("MicroPython")?.show()
}
}
Expand Down
Loading