Skip to content

Commit b0ad64f

Browse files
Add tooltip support for Java operators
1 parent ec93898 commit b0ad64f

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

app/src/main/java/com/itsaky/androidide/actions/file/ShowTooltipAction.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import com.itsaky.androidide.R
2323
import com.itsaky.androidide.actions.ActionData
2424
import com.itsaky.androidide.actions.ActionItem
2525
import com.itsaky.androidide.actions.BaseEditorAction
26-
import com.itsaky.androidide.editor.utils.isOperatorToken
26+
import com.itsaky.androidide.editor.utils.isJavaOperatorToken
27+
import com.itsaky.androidide.editor.utils.isKotlinOperatorToken
2728
import com.itsaky.androidide.editor.utils.isXmlAttribute
2829
import com.itsaky.androidide.idetooltips.TooltipCategory
2930
import com.itsaky.androidide.idetooltips.TooltipManager
@@ -106,7 +107,8 @@ internal fun resolveTooltipTag(
106107
return when {
107108
!editorTag.isNullOrEmpty() -> editorTag
108109
category == TooltipCategory.CATEGORY_XML && isXmlAttribute -> textToUse.substringAfterLast(":")
109-
category == TooltipCategory.CATEGORY_KOTLIN && isOperatorToken(textToUse) -> "kotlin.operator.$textToUse"
110+
category == TooltipCategory.CATEGORY_KOTLIN && isKotlinOperatorToken(textToUse) -> "kotlin.operator.$textToUse"
111+
category == TooltipCategory.CATEGORY_JAVA && isJavaOperatorToken(textToUse) -> "java.operator.$textToUse"
110112
else -> textToUse
111113
}
112114
}

editor/src/main/java/com/itsaky/androidide/editor/utils/OperatorSelection.kt

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ import io.github.rosemoe.sora.text.Content
2525
*/
2626
private val OPERATORS: List<String> =
2727
listOf(
28-
// 3-char
28+
// 3-char (=== and !== before 2-char == and !=)
29+
"===",
30+
"!==",
2931
">>>",
3032
"<<=",
3133
">>=",
@@ -86,13 +88,39 @@ private val OPERATORS: List<String> =
8688
private val OPERATOR_SET: Set<String> = OPERATORS.toSet()
8789

8890
/**
89-
* Returns true when [text] is exactly one supported Java/Kotlin operator token.
91+
* Tokens matched for editor selection that exist only in Kotlin, not Java.
92+
* Used so [isJavaOperatorToken] does not emit `java.operator.*` tags for these.
9093
*/
91-
fun isOperatorToken(text: CharSequence): Boolean {
94+
private val KOTLIN_ONLY_OPERATOR_TOKENS: Set<String> =
95+
setOf(
96+
"?.",
97+
"?:",
98+
"..",
99+
"!!",
100+
"===",
101+
"!==",
102+
)
103+
104+
private val JAVA_OPERATOR_SET: Set<String> = OPERATOR_SET - KOTLIN_ONLY_OPERATOR_TOKENS
105+
106+
/**
107+
* Returns true when [text] is exactly one Kotlin operator/punctuation token for tooltip lookup
108+
* (same token set as the long-press operator list).
109+
*/
110+
fun isKotlinOperatorToken(text: CharSequence): Boolean {
92111
if (text.isEmpty()) return false
93112
return OPERATOR_SET.contains(text.toString())
94113
}
95114

115+
/**
116+
* Returns true when [text] is exactly one Java operator/punctuation token for tooltip lookup.
117+
* Excludes Kotlin-only tokens such as `?.`, `..`, `===`, and `!==`.
118+
*/
119+
fun isJavaOperatorToken(text: CharSequence): Boolean {
120+
if (text.isEmpty()) return false
121+
return JAVA_OPERATOR_SET.contains(text.toString())
122+
}
123+
96124
/**
97125
* Returns the column range of the operator at the given position, if any.
98126
* Columns are 0-based; endColumn is exclusive (one past the last character).

0 commit comments

Comments
 (0)