mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
[driver][ui-tests] add inlay hints getter for editor
GitOrigin-RevId: ccc723ed324a19469a48e9fd427936d70017957b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
aa42d9f092
commit
cce8ea060d
@@ -18,7 +18,7 @@ interface Editor {
|
||||
fun getLineHeight(): Int
|
||||
fun offsetToVisualPosition(offset: Int): VisualPosition
|
||||
fun visualPositionToXY(visible: VisualPosition): Point
|
||||
|
||||
fun getInlayModel(): InlayModel
|
||||
}
|
||||
@Remote("com.intellij.openapi.editor.VisualPosition")
|
||||
interface VisualPosition {
|
||||
@@ -38,6 +38,38 @@ interface CaretModel {
|
||||
fun getLogicalPosition(): LogicalPosition
|
||||
}
|
||||
|
||||
@Remote("com.intellij.openapi.editor.InlayModel")
|
||||
interface InlayModel {
|
||||
fun getInlineElementsInRange(startOffset: Int, endOffset: Int): List<Inlay>
|
||||
}
|
||||
|
||||
@Remote("com.intellij.openapi.editor.Inlay")
|
||||
interface Inlay {
|
||||
fun getRenderer(): EditorCustomElementRenderer
|
||||
fun getOffset(): Int
|
||||
}
|
||||
|
||||
@Remote("com.intellij.openapi.editor.EditorCustomElementRenderer")
|
||||
interface EditorCustomElementRenderer{
|
||||
fun getText(): String?
|
||||
}
|
||||
|
||||
@Remote("com.intellij.codeInsight.hints.declarative.impl.DeclarativeInlayRenderer")
|
||||
interface DeclarativeInlayRenderer{
|
||||
fun getPresentationList(): InlayPresentationList
|
||||
}
|
||||
|
||||
@Remote("com.intellij.codeInsight.hints.declarative.impl.InlayPresentationList")
|
||||
interface InlayPresentationList{
|
||||
fun getEntries(): Array<TextInlayPresentationEntry>
|
||||
}
|
||||
|
||||
|
||||
@Remote("com.intellij.codeInsight.hints.declarative.impl.TextInlayPresentationEntry")
|
||||
interface TextInlayPresentationEntry{
|
||||
fun getText(): String
|
||||
}
|
||||
|
||||
@Remote("com.intellij.openapi.editor.LogicalPosition")
|
||||
interface LogicalPosition {
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.intellij.driver.sdk.ui.components
|
||||
|
||||
import com.intellij.driver.client.Remote
|
||||
import com.intellij.driver.client.impl.DriverCallException
|
||||
import com.intellij.driver.model.OnDispatcher
|
||||
import com.intellij.driver.model.RemoteMouseButton
|
||||
import com.intellij.driver.sdk.DeclarativeInlayRenderer
|
||||
import com.intellij.driver.sdk.Document
|
||||
import com.intellij.driver.sdk.Editor
|
||||
import com.intellij.driver.sdk.logicalPosition
|
||||
@@ -30,6 +32,28 @@ fun Finder.editor(@Language("xpath") xpath: String? = null, action: JEditorUiCom
|
||||
class JEditorUiComponent(data: ComponentData) : UiComponent(data) {
|
||||
val editor: Editor by lazy { driver.cast(component, EditorComponentImpl::class).getEditor() }
|
||||
|
||||
fun getInlayHints(): List<InlayHint> {
|
||||
val hints = mutableListOf<InlayHint>()
|
||||
this.editor.getInlayModel().getInlineElementsInRange(0, Int.MAX_VALUE).forEach { element ->
|
||||
val hintText = try {
|
||||
element.getRenderer().getText()
|
||||
}
|
||||
catch (e: DriverCallException) {
|
||||
try {
|
||||
driver.cast(element.getRenderer(), DeclarativeInlayRenderer::class).getPresentationList().getEntries().joinToString { it.getText() }
|
||||
}
|
||||
catch (e: DriverCallException) {
|
||||
element.getRenderer().toString().substring(1, element.getRenderer().toString().length - 1)
|
||||
}
|
||||
}
|
||||
finally {
|
||||
""
|
||||
}
|
||||
hints.add(InlayHint(element.getOffset(), hintText!!))
|
||||
}
|
||||
return hints
|
||||
}
|
||||
|
||||
private val document: Document by lazy { editor.getDocument() }
|
||||
|
||||
private val caretPosition
|
||||
@@ -131,6 +155,33 @@ class GutterUiComponent(data: ComponentData) : UiComponent(data) {
|
||||
}
|
||||
}
|
||||
|
||||
class InlayHint(val offset: Int, val text: String)
|
||||
|
||||
//driver.cast(element.getRenderer(), DeclarativeInlayRenderer::class).getPresentationList().getEntries()[0].getText()
|
||||
|
||||
|
||||
//fun List<InlayHint>.hasHint(text: String): Boolean {
|
||||
// return this.find { it.text.equals(text) } != null
|
||||
//}
|
||||
|
||||
//fun List<InlayHint>.getHint(text: String): InlayHint {
|
||||
// val foundHint = this.find { it.text.equals(text) }
|
||||
// if (foundHint == null) {
|
||||
// throw NoSuchElementException("cannot find hint: $text in ${this.joinToString(separator = "\n") { it.text }}")
|
||||
// }
|
||||
// return foundHint
|
||||
//}
|
||||
|
||||
//driver.cast(element.getRenderer(), DeclarativeInlayRenderer::class).getPresentationList().getEntries()[0].getText()
|
||||
fun List<InlayHint>.getHint(offset: Int): InlayHint {
|
||||
val foundHint = this.find { it.offset.equals(offset) }
|
||||
if (foundHint == null) {
|
||||
throw NoSuchElementException("cannot find hint with offset: $offset")
|
||||
}
|
||||
return foundHint
|
||||
}
|
||||
|
||||
|
||||
@Remote("com.intellij.openapi.editor.impl.EditorGutterComponentImpl")
|
||||
interface EditorGutterComponentImpl : Component {
|
||||
fun getLineGutterMarks(): List<GutterIconWithLocation>
|
||||
|
||||
Reference in New Issue
Block a user