Skip to content

Commit

Permalink
Merge #4996
Browse files Browse the repository at this point in the history
4996: REPL: Replace custom command history implementation with default one r=ortem a=dima74

Default implementation additionally provides action to see list of all commands

Co-authored-by: Dmitry Murzin <diraria@yandex.ru>
  • Loading branch information
bors[bot] and dima74 committed Mar 10, 2020
2 parents 03c8213 + 9a523f0 commit 84c2690
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 142 deletions.
28 changes: 0 additions & 28 deletions src/main/kotlin/org/rust/ide/console/CommandHistory.kt

This file was deleted.

99 changes: 0 additions & 99 deletions src/main/kotlin/org/rust/ide/console/HistoryKeyListener.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,12 @@ import com.intellij.execution.process.ProcessHandler

class RsConsoleExecuteActionHandler(
processHandler: ProcessHandler,
private val consoleRunner: RsConsoleRunner,
private val consoleCommunication: RsConsoleCommunication
) : ProcessBackedConsoleExecuteActionHandler(processHandler, false) {

var isEnabled: Boolean = false

override fun processLine(line: String) {
val entry = CommandHistory.Entry(line)
consoleRunner.commandHistory.addEntry(entry)

val lineEscaped = line.replace("\n", "\u2028")
super.processLine(lineEscaped)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Use of this source code is governed by the MIT license that can be
* found in the LICENSE file.
*/
package org.rust.ide.console

import com.intellij.execution.console.ConsoleHistoryModel
import com.intellij.execution.console.ConsoleHistoryModelProvider
import com.intellij.execution.console.LanguageConsoleView

class RsConsoleHistoryModelProvider : ConsoleHistoryModelProvider {
override fun createModel(persistenceId: String, consoleView: LanguageConsoleView): ConsoleHistoryModel? {
return if (consoleView is RsConsoleView) {
com.intellij.execution.console.createModel(persistenceId, consoleView)
} else {
null
}
}
}
15 changes: 15 additions & 0 deletions src/main/kotlin/org/rust/ide/console/RsConsoleRootType.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Use of this source code is governed by the MIT license that can be
* found in the LICENSE file.
*/
package org.rust.ide.console

import com.intellij.execution.console.ConsoleRootType
import com.intellij.ide.scratch.RootType

class RsConsoleRootType internal constructor() : ConsoleRootType("rs", "Rust Consoles") {
companion object {
val instance: RsConsoleRootType
get() = RootType.findByClass(RsConsoleRootType::class.java)
}
}
15 changes: 5 additions & 10 deletions src/main/kotlin/org/rust/ide/console/RsConsoleRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package org.rust.ide.console

import com.intellij.execution.actions.EOFAction
import com.intellij.execution.configurations.GeneralCommandLine
import com.intellij.execution.console.ConsoleHistoryController
import com.intellij.execution.process.OSProcessHandler
import com.intellij.execution.runners.AbstractConsoleRunnerWithHistory
import com.intellij.execution.ui.RunContentDescriptor
Expand Down Expand Up @@ -46,8 +47,6 @@ class RsConsoleRunner(project: Project) :
private lateinit var commandLine: GeneralCommandLine
private lateinit var consoleCommunication: RsConsoleCommunication

val commandHistory: CommandHistory = CommandHistory()

override fun getConsoleExecuteActionHandler(): RsConsoleExecuteActionHandler {
return super.getConsoleExecuteActionHandler() as RsConsoleExecuteActionHandler
}
Expand All @@ -59,12 +58,6 @@ class RsConsoleRunner(project: Project) :
override fun createConsoleView(): RsConsoleView {
val consoleView = RsConsoleView(project)
consoleCommunication = RsConsoleCommunication(consoleView)

val consoleEditor = consoleView.consoleEditor
val historyKeyListener = HistoryKeyListener(project, consoleEditor, commandHistory)
consoleEditor.contentComponent.addKeyListener(historyKeyListener)
commandHistory.listeners.add(historyKeyListener)

return consoleView
}

Expand Down Expand Up @@ -112,7 +105,8 @@ class RsConsoleRunner(project: Project) :
val outputActions = listOf<AnAction>(
SoftWrapAction(consoleView),
ScrollToTheEndToolbarAction(consoleView.editor),
PrintAction(consoleView)
PrintAction(consoleView),
ConsoleHistoryController.getController(consoleView)!!.browseHistory
)
outputActionGroup.addAll(outputActions)

Expand Down Expand Up @@ -212,8 +206,9 @@ class RsConsoleRunner(project: Project) :

override fun createExecuteActionHandler(): RsConsoleExecuteActionHandler {
val consoleExecuteActionHandler =
RsConsoleExecuteActionHandler(processHandler!!, this, consoleCommunication)
RsConsoleExecuteActionHandler(processHandler!!, consoleCommunication)
consoleExecuteActionHandler.isEnabled = false
ConsoleHistoryController(RsConsoleRootType.instance, "", consoleView).install()
return consoleExecuteActionHandler
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/org/rust/ide/console/RsConsoleView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class RsConsoleView(project: Project) : LanguageConsoleImpl(project, VIRTUAL_FIL
// Mark editor as console one, to prevent autopopup completion
historyViewer.putUserData(ConsoleViewUtil.EDITOR_IS_CONSOLE_HISTORY_VIEW, true)
super.setPrompt(PROMPT)
consolePromptDecorator.indentPrompt = INDENT_PROMPT
setUpdateFoldingsEnabled(false)
}

Expand Down Expand Up @@ -77,6 +78,7 @@ class RsConsoleView(project: Project) : LanguageConsoleImpl(project, VIRTUAL_FIL

companion object {
const val PROMPT: String = ">> "
const val INDENT_PROMPT: String = ".. "
const val VIRTUAL_FILE_NAME: String = "IntellijRustRepl.rs"
private val RUST_CONSOLE_KEY: Key<Boolean> = Key("RS_CONSOLE_KEY")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1322,7 +1322,7 @@ private fun processLexicalDeclarations(
val letDecls = mutableListOf<RsLetDecl>()
val stmts = when (scope) {
is RsBlock -> scope.expandedStmtsAndTailExpr.first
is RsReplCodeFragment -> scope.stmts.toList()
is RsReplCodeFragment -> scope.stmts
else -> emptyList() // unreachable
}
for (stmt in stmts) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/META-INF/rust-core.xml
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,11 @@
<writingAccessProvider implementation="org.rust.lang.core.macros.RsMacroExpansionWritingAccessProvider"/>
<cachesInvalidator implementation="org.rust.lang.core.macros.RsMacroExpansionCachesInvalidator"/>

<!-- REPL Console -->

<consoleHistoryModelProvider implementation="org.rust.ide.console.RsConsoleHistoryModelProvider"/>
<scratch.rootType implementation="org.rust.ide.console.RsConsoleRootType"/>

</extensions>

<extensionPoints>
Expand Down

0 comments on commit 84c2690

Please sign in to comment.