override fun actionPerformed()

in src/main/kotlin/com/jetbrains/micropython/actions/RunMicroReplAction.kt [34:53]


  override fun actionPerformed(e: AnActionEvent) {
    val project = e.project ?: return
    val editor = FileEditorManagerEx.getInstanceEx(project).selectedTextEditor ?: return

    /*
    Here we make our best to find out module which is relevant to the current event.
    There are two cases to consider:
    1) There is an open file present.
    2) No files are opened.
    */

    val virtualFile: VirtualFile? = FileDocumentManager.getInstance().getFile(editor.document)
    val module: Module? = if (virtualFile != null) {
      ModuleUtil.findModuleForFile(virtualFile, project)
    } else {
      project.firstMicroPythonFacet?.module
    }

    project.service<MicroPythonReplManager>().startOrRestartRepl()
  }