mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Add command to assert current file name
GitOrigin-RevId: 9c7f128eb50036c0613f6ec212bd534fc0c0bb56
This commit is contained in:
committed by
intellij-monorepo-bot
parent
4ac62e3a82
commit
ab4dce1226
+7
@@ -1033,4 +1033,11 @@ fun <T : CommandChain> T.disableKotlinNotification(): T = apply {
|
||||
*/
|
||||
fun <T : CommandChain> T.assertCaretPosition(line: Int, column: Int): T = apply {
|
||||
addCommand("${CMD_PREFIX}assertCaretPosition $line $column")
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert the current file in editor.
|
||||
*/
|
||||
fun <T : CommandChain> T.assertCurrentFile(name: String): T = apply {
|
||||
addCommand("${CMD_PREFIX}assertCurrentFile $name")
|
||||
}
|
||||
+2
-1
@@ -112,7 +112,8 @@ public final class BaseCommandProvider implements CommandProvider {
|
||||
Map.entry(AddContentRootToModule.PREFIX, AddContentRootToModule::new),
|
||||
Map.entry(DisableKotlinNotificationCommand.PREFIX, DisableKotlinNotificationCommand::new),
|
||||
Map.entry(RequestHeavyScanningOnNextStartCommand.PREFIX, RequestHeavyScanningOnNextStartCommand::new),
|
||||
Map.entry(AssertCaretPositionCommand.PREFIX, AssertCaretPositionCommand::new)
|
||||
Map.entry(AssertCaretPositionCommand.PREFIX, AssertCaretPositionCommand::new),
|
||||
Map.entry(AssertCurrentFileCommand.PREFIX, AssertCurrentFileCommand::new)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package com.jetbrains.performancePlugin.commands
|
||||
|
||||
import com.intellij.openapi.application.readAction
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager
|
||||
import com.intellij.openapi.ui.playback.PlaybackContext
|
||||
import org.jetbrains.annotations.NonNls
|
||||
|
||||
/**
|
||||
* Assert the current file in editor.
|
||||
*
|
||||
* Syntax: `%assertCurrentFile <file name>`
|
||||
*
|
||||
* Example: `%assertCurrentFile AssertCurrentFileCommand.kt`
|
||||
*/
|
||||
class AssertCurrentFileCommand(text: String, line: Int) : PerformanceCommandCoroutineAdapter(text, line) {
|
||||
companion object {
|
||||
const val NAME: @NonNls String = "assertCurrentFile"
|
||||
const val PREFIX: String = CMD_PREFIX + NAME
|
||||
}
|
||||
|
||||
override suspend fun doExecute(context: PlaybackContext) {
|
||||
val fileName = extractCommandArgument(PREFIX).split(" ").filterNot { it.trim() == "" }.singleOrNull()
|
||||
if (fileName == null) {
|
||||
throw IllegalArgumentException("File name is not provided")
|
||||
}
|
||||
|
||||
readAction {
|
||||
val editor = checkNotNull(FileEditorManager.getInstance(context.project).selectedTextEditor)
|
||||
val currentFileName = editor.virtualFile.name
|
||||
if (fileName != currentFileName) {
|
||||
throw Exception("Current file name is $currentFileName, expected $fileName")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getName(): String = NAME
|
||||
}
|
||||
Reference in New Issue
Block a user