[performance-tests] Add CallInlineCompletionCommand for inline completion testing

GitOrigin-RevId: fd9d3f3b3b5978606aa212e7f3dfe7fb40748fb8
This commit is contained in:
roman.ivanitskii
2024-09-09 17:08:45 +02:00
committed by intellij-monorepo-bot
parent 4e2f9cbb98
commit bcbbbb0dca
3 changed files with 78 additions and 0 deletions

View File

@@ -715,6 +715,10 @@ fun <T : CommandChain> T.setupInlineCompletionListener(): T = apply {
addCommand("${CMD_PREFIX}setupInlineCompletionListener")
}
fun <T : CommandChain> T.callInlineCompletionCommand(): T = apply {
addCommand("${CMD_PREFIX}callInlineCompletionCommand")
}
fun <T : CommandChain> T.validateMavenGoal(settings: MavenGoalConfigurationDto): T = apply {
val options = objectMapper.writeValueAsString(settings)
addCommand("${CMD_PREFIX}validateMavenGoal $options")

View File

@@ -123,6 +123,7 @@ public final class BaseCommandProvider implements CommandProvider {
Map.entry(MoveFilesCommand.PREFIX, MoveFilesCommand::new),
Map.entry(GCCommand.PREFIX, GCCommand::new),
Map.entry(SetupInlineCompletionListenerCommand.PREFIX, SetupInlineCompletionListenerCommand::new),
Map.entry(CallInlineCompletionCommand.PREFIX, CallInlineCompletionCommand::new),
Map.entry(HandleSpanCommand.PREFIX, HandleSpanCommand::new)
);
}

View File

@@ -0,0 +1,73 @@
package com.jetbrains.performancePlugin.commands
import com.intellij.codeInsight.inline.completion.InlineCompletion
import com.intellij.codeInsight.inline.completion.InlineCompletionEvent
import com.intellij.codeInsight.inline.completion.InlineCompletionEventAdapter
import com.intellij.codeInsight.inline.completion.InlineCompletionEventType
import com.intellij.openapi.application.EDT
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.progress.blockingContext
import com.intellij.openapi.ui.playback.PlaybackContext
import com.intellij.openapi.ui.playback.commands.PlaybackCommandCoroutineAdapter
import com.intellij.openapi.util.ActionCallback
import com.intellij.openapi.util.await
import com.jetbrains.performancePlugin.PerformanceTestSpan
import com.jetbrains.performancePlugin.utils.ActionCallbackProfilerStopper
import io.opentelemetry.api.trace.Span
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.jetbrains.annotations.NonNls
/**
* CallInlineCompletionCommand is responsible for invoking inline completion
* within a text editor. It measures `callInlineCompletionShow` or `callInlineCompletionHide` metrics.
*/
class CallInlineCompletionCommand(text: String, line: Int) : PlaybackCommandCoroutineAdapter(text, line) {
companion object {
const val PREFIX: @NonNls String = CMD_PREFIX + "callInlineCompletionCommand"
const val SPAN_NAME: @NonNls String = "callInlineCompletion"
}
override suspend fun doExecute(context: PlaybackContext) {
val actionCallback: ActionCallback = ActionCallbackProfilerStopper()
val editor = blockingContext { FileEditorManager.getInstance(context.project).selectedTextEditor ?: error("No editor") }
val handler = InlineCompletion.getHandlerOrNull(editor) ?: error("No inline completion handler")
val listener = object : InlineCompletionEventAdapter {
private var spanShow: Span? = null
private var spanHide: Span? = null
override fun onCompletion(event: InlineCompletionEventType.Completion) {
if (event.isActive) {
actionCallback.setDone()
}
}
override fun onShow(event: InlineCompletionEventType.Show) {
spanShow?.end()
spanHide = null
spanShow = null
}
override fun onRequest(event: InlineCompletionEventType.Request) {
spanShow = PerformanceTestSpan.TRACER.spanBuilder(SPAN_NAME + "Show").startSpan()
spanHide = PerformanceTestSpan.TRACER.spanBuilder(SPAN_NAME + "Hide").startSpan()
}
override fun onHide(event: InlineCompletionEventType.Hide) {
spanHide?.end()
spanHide = null
spanShow = null
}
}
try {
handler.addEventListener(listener)
withContext(Dispatchers.EDT) {
handler.invoke(InlineCompletionEvent.DirectCall(editor, editor.caretModel.currentCaret))
}
actionCallback.await()
}
finally {
handler.removeEventListener(listener)
}
}
}