Skip to content

Commit e1b4202

Browse files
authored
Feature/flow graph improvements (#2494)
* Fix: Add/fix some FlowStrings. * New: Show expression matching in flow diagrams. * Cleanup: Extract FlowDiagram styles to DiagramStyles. * New: Add refreshing to flow graph matching. * Improvement: Show attempted matches in flow graph tooltips. * Accessibility: Use different line thicknesses for match colours in flow diagrams. * Improvement: Show expression text in flow graph UI and allow jumping back to its source. * Improvement: Display expression source in tooltips using editor font. * Fix: Fix NPE when searching flow graph without a selection. * Improvement: Add popup when there is a choice between multiple target methods. * Cleanup: Use MVC for FlowDiagram. * Improvement: Go to *first* best flow match. * Build: Bump MixinExtras Expressions
1 parent eaec458 commit e1b4202

File tree

12 files changed

+820
-249
lines changed

12 files changed

+820
-249
lines changed

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ changelog-plugin = { module = "org.jetbrains.changelog:org.jetbrains.changelog.g
3434
coroutines-swing = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-swing", version.ref = "coroutines" }
3535

3636
mappingIo = "net.fabricmc:mapping-io:0.2.1"
37-
mixinExtras-expressions = "io.github.llamalad7:mixinextras-expressions:0.0.5"
37+
mixinExtras-expressions = "io.github.llamalad7:mixinextras-expressions:0.0.6"
3838
jgraphx = "com.github.vlsi.mxgraph:jgraphx:4.2.2"
3939

4040
# GrammarKit

src/main/kotlin/platform/mixin/expression/MEExpressionMatchUtil.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ object MEExpressionMatchUtil {
263263
insns: Iterable<VirtualInsn>,
264264
contextType: ExpressionContext.Type,
265265
forCompletion: Boolean,
266+
crossinline reportMatchStatus: (FlowValue, Expression, Boolean) -> Unit = { _, _, _ -> },
267+
crossinline reportPartialMatch: (FlowValue, Expression) -> Unit = { _, _ -> },
266268
callback: (ExpressionMatch) -> Unit
267269
) {
268270
for (insn in insns) {
@@ -283,6 +285,14 @@ object MEExpressionMatchUtil {
283285
// Our maps are per-injector anyway, so this is just a normal decoration.
284286
decorations.getOrPut(VirtualInsn(insn), ::mutableMapOf)[key] = value
285287
}
288+
289+
override fun reportMatchStatus(node: FlowValue, expr: Expression, matched: Boolean) {
290+
reportMatchStatus.invoke(node, expr, matched)
291+
}
292+
293+
override fun reportPartialMatch(node: FlowValue, expr: Expression) {
294+
reportPartialMatch.invoke(node, expr)
295+
}
286296
}
287297

288298
val flow = flows[insn] ?: continue
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Minecraft Development for IntelliJ
3+
*
4+
* https://mcdev.io/
5+
*
6+
* Copyright (C) 2025 minecraft-dev
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Lesser General Public License as published
10+
* by the Free Software Foundation, version 3.0 only.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public License
18+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
package com.demonwav.mcdev.platform.mixin.expression.gui
22+
23+
import com.intellij.openapi.editor.colors.EditorColorsManager
24+
import com.intellij.openapi.editor.colors.EditorFontType
25+
import com.intellij.ui.JBColor
26+
import com.intellij.util.ui.JBUI
27+
import com.intellij.util.ui.UIUtil
28+
import com.mxgraph.util.mxConstants
29+
import java.awt.Color
30+
31+
object DiagramStyles {
32+
val DEFAULT_NODE
33+
get() = mapOf(
34+
mxConstants.STYLE_FONTFAMILY to CURRENT_EDITOR_FONT.family,
35+
mxConstants.STYLE_ROUNDED to true,
36+
mxConstants.STYLE_FILLCOLOR to JBUI.CurrentTheme.Button.buttonColorStart().hexString,
37+
mxConstants.STYLE_FONTCOLOR to UIUtil.getLabelForeground().hexString,
38+
mxConstants.STYLE_STROKECOLOR to JBUI.CurrentTheme.Button.buttonOutlineColorStart(false).hexString,
39+
mxConstants.STYLE_ALIGN to mxConstants.ALIGN_CENTER,
40+
mxConstants.STYLE_VERTICAL_ALIGN to mxConstants.ALIGN_TOP,
41+
mxConstants.STYLE_SHAPE to mxConstants.SHAPE_LABEL,
42+
mxConstants.STYLE_SPACING to 5,
43+
mxConstants.STYLE_SPACING_TOP to 3,
44+
)
45+
val DEFAULT_EDGE
46+
get() = mapOf(
47+
mxConstants.STYLE_STROKECOLOR to UIUtil.getFocusedBorderColor().hexString,
48+
)
49+
val LINE_NUMBER = mapOf(
50+
mxConstants.STYLE_FONTSIZE to "16",
51+
mxConstants.STYLE_STROKECOLOR to "none",
52+
mxConstants.STYLE_FILLCOLOR to "none",
53+
)
54+
val SEARCH_HIGHLIGHT
55+
get() = mapOf(
56+
mxConstants.STYLE_STROKECOLOR to UIUtil.getFocusedBorderColor().hexString,
57+
mxConstants.STYLE_STROKEWIDTH to "2",
58+
)
59+
val IGNORED = mapOf(
60+
mxConstants.STYLE_OPACITY to 20,
61+
mxConstants.STYLE_TEXT_OPACITY to 20,
62+
mxConstants.STYLE_STROKE_OPACITY to 20,
63+
mxConstants.STYLE_FILL_OPACITY to 20,
64+
)
65+
val FAILED
66+
get() = mapOf(
67+
mxConstants.STYLE_STROKECOLOR to JBColor.red.hexString,
68+
mxConstants.STYLE_STROKEWIDTH to "3.5",
69+
)
70+
val PARTIAL_MATCH
71+
get() = mapOf(
72+
mxConstants.STYLE_STROKECOLOR to JBColor.orange.hexString,
73+
mxConstants.STYLE_STROKEWIDTH to "2.5",
74+
)
75+
val SUCCESS
76+
get() = mapOf(
77+
mxConstants.STYLE_STROKECOLOR to JBColor.green.hexString,
78+
mxConstants.STYLE_STROKEWIDTH to "1.5",
79+
)
80+
val CURRENT_EDITOR_FONT
81+
get() = EditorColorsManager.getInstance().globalScheme.getFont(EditorFontType.PLAIN)
82+
}
83+
84+
private val Color.hexString get() = "#%06X".format(rgb)

0 commit comments

Comments
 (0)