From a29c6ead362a7d222f200eaf699240c09264908d Mon Sep 17 00:00:00 2001 From: Daniel Alome Date: Sat, 12 Sep 2026 19:33:31 +0100 Subject: [PATCH 1/4] style: spotless reformat of touched editor files, no functional change These three files are space-indented on stage; the crash-to-code change touches one line in each, which enrolls the whole file in the file-level Spotless ratchet and reindents it to tabs. Commit that reindent on its own so it is not reviewer noise in the behavioral commit that follows. ktlint changes only: space-to-tab reindent, import ordering, parameter list wrapping, and expression-body conversions. --- .../treesitter/TreeSitterSpanFactory.kt | 202 ++++++++--------- .../editor/schemes/IDEColorScheme.kt | 206 ++++++++---------- .../editor/schemes/internal/parser/common.kt | 166 +++++++------- 3 files changed, 283 insertions(+), 291 deletions(-) diff --git a/editor/src/main/java/com/itsaky/androidide/editor/language/treesitter/TreeSitterSpanFactory.kt b/editor/src/main/java/com/itsaky/androidide/editor/language/treesitter/TreeSitterSpanFactory.kt index 65b90e788b..47140fb5e9 100644 --- a/editor/src/main/java/com/itsaky/androidide/editor/language/treesitter/TreeSitterSpanFactory.kt +++ b/editor/src/main/java/com/itsaky/androidide/editor/language/treesitter/TreeSitterSpanFactory.kt @@ -39,102 +39,108 @@ import org.slf4j.LoggerFactory * @author Akash Yadav */ class TreeSitterSpanFactory( - private var content: ContentReference?, - private var query: TSQuery?, - private var styles: Styles?, - private var langScheme: LanguageScheme? + private var content: ContentReference?, + private var query: TSQuery?, + private var styles: Styles?, + private var langScheme: LanguageScheme?, ) : DefaultSpanFactory() { - - companion object { - - private val log = LoggerFactory.getLogger(TreeSitterSpanFactory::class.java) - - @JvmStatic - private val HEX_REGEX = "#\\b([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})\\b".toRegex() - } - - override fun close() { - content = null - query = null - styles = null - langScheme = null - } - - override fun createSpans(capture: TSQueryCapture, column: Int, spanStyle: Long): List { - val content = this.content?.reference ?: return super.createSpans(capture, column, spanStyle) - val query = this.query ?: return super.createSpans(capture, column, spanStyle) - val langScheme = this.langScheme ?: return super.createSpans(capture, column, spanStyle) - - val captureName = query.getCaptureNameForId(capture.index) - val styleDef = langScheme.getStyles()[captureName] - if (styleDef?.maybeHexColor != true) { - return super.createSpans(capture, column, spanStyle) - } - - val (start, end) = content.indexer.run { - getCharPosition(capture.node.startByte / 2) to getCharPosition(capture.node.endByte / 2) - } - - if (start.line != end.line || start.column != column) { - // A HEX color can only be defined on a single line - return super.createSpans(capture, column, spanStyle) - } - - val text = content.subContent(start.line, start.column, end.line, end.column) - val results = HEX_REGEX.findAll(text) - val spans = mutableListOf() - var s = -1 - var e = -1 - results.forEach { result -> - if (e != -1 && e < result.range.first) { - // there is some interval between previous color span - // and this color span - // fill the gap - spans.add(Span.obtain(column + e + 1, spanStyle)) - } - - if (s == -1) { - s = result.range.first - } - e = result.range.last - - val color = try { - parseHexColor(result.groupValues[1]).toInt() - } catch (e: Exception) { - log.error("An error occurred parsing hex color. text={}", text, e) - return@forEach - } - - val textColor = if (ColorUtils.calculateLuminance(color) > 0.5f) { - Color.BLACK - } else { - Color.WHITE - } - - val col = column + result.range.first - val span = SpanFactory.obtain( - col, - styleDef.makeStaticStyle() - ) - - span.setSpanExt(SpanExtAttrs.EXT_COLOR_RESOLVER, SpanConstColorResolver(textColor, color)) - - spans.add(span) - } - - if (spans.isEmpty()) { - return super.createSpans(capture, column, spanStyle) - } - - // make sure that the default style is used for unmatched regions - if (s != 0) { - spans.add(0, SpanFactory.obtain(column, spanStyle)) - } - - if (e != text.lastIndex) { - spans.add(SpanFactory.obtain(column + e + 1, spanStyle)) - } - - return spans - } -} \ No newline at end of file + companion object { + private val log = LoggerFactory.getLogger(TreeSitterSpanFactory::class.java) + + @JvmStatic + private val HEX_REGEX = "#\\b([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})\\b".toRegex() + } + + override fun close() { + content = null + query = null + styles = null + langScheme = null + } + + override fun createSpans( + capture: TSQueryCapture, + column: Int, + spanStyle: Long, + ): List { + val content = this.content?.reference ?: return super.createSpans(capture, column, spanStyle) + val query = this.query ?: return super.createSpans(capture, column, spanStyle) + val langScheme = this.langScheme ?: return super.createSpans(capture, column, spanStyle) + + val captureName = query.getCaptureNameForId(capture.index) + val styleDef = langScheme.getStyles()[captureName] + if (styleDef?.maybeHexColor != true) { + return super.createSpans(capture, column, spanStyle) + } + + val (start, end) = + content.indexer.run { + getCharPosition(capture.node.startByte / 2) to getCharPosition(capture.node.endByte / 2) + } + + if (start.line != end.line || start.column != column) { + // A HEX color can only be defined on a single line + return super.createSpans(capture, column, spanStyle) + } + + val text = content.subContent(start.line, start.column, end.line, end.column) + val results = HEX_REGEX.findAll(text) + val spans = mutableListOf() + var s = -1 + var e = -1 + results.forEach { result -> + if (e != -1 && e < result.range.first) { + // there is some interval between previous color span + // and this color span + // fill the gap + spans.add(Span.obtain(column + e + 1, spanStyle)) + } + + if (s == -1) { + s = result.range.first + } + e = result.range.last + + val color = + try { + parseHexColor(result.groupValues[1]).toInt() + } catch (e: Exception) { + log.error("An error occurred parsing hex color. text={}", text, e) + return@forEach + } + + val textColor = + if (ColorUtils.calculateLuminance(color) > 0.5f) { + Color.BLACK + } else { + Color.WHITE + } + + val col = column + result.range.first + val span = + SpanFactory.obtain( + col, + styleDef.makeStaticStyle(), + ) + + span.setSpanExt(SpanExtAttrs.EXT_COLOR_RESOLVER, SpanConstColorResolver(textColor, color)) + + spans.add(span) + } + + if (spans.isEmpty()) { + return super.createSpans(capture, column, spanStyle) + } + + // make sure that the default style is used for unmatched regions + if (s != 0) { + spans.add(0, SpanFactory.obtain(column, spanStyle)) + } + + if (e != text.lastIndex) { + spans.add(SpanFactory.obtain(column + e + 1, spanStyle)) + } + + return spans + } +} diff --git a/editor/src/main/java/com/itsaky/androidide/editor/schemes/IDEColorScheme.kt b/editor/src/main/java/com/itsaky/androidide/editor/schemes/IDEColorScheme.kt index 7726555d5f..fc7a0c7214 100644 --- a/editor/src/main/java/com/itsaky/androidide/editor/schemes/IDEColorScheme.kt +++ b/editor/src/main/java/com/itsaky/androidide/editor/schemes/IDEColorScheme.kt @@ -26,58 +26,56 @@ import io.github.rosemoe.sora.widget.schemes.EditorColorScheme import java.io.File import java.util.TreeSet -class IDEColorScheme(internal val file: File, val key: String) : DynamicColorScheme() { - - internal val colorIds = MutableIntIntMap() - internal val editorScheme = MutableIntIntMap() - internal val languages = mutableMapOf() - - var name: String = "" - internal set - - var version: Int = 0 - internal set - - var isDarkScheme: Boolean = false - internal set - - var darkVariant: IDEColorScheme? = null - internal set - - var definitions: Map = emptyMap() - internal set - - private var colorId = endColorId - - internal fun load() { - SchemeParser { name -> File(this.file.parentFile, name) }.load(this) - } - - fun getLanguageScheme(type: String): LanguageScheme? { - return this.languages[type] - } - - internal fun putColor(color: Int): Int { - this.colorIds[++colorId] = color - return colorId - } - - @Suppress("UNNECESSARY_SAFE_CALL", "USELESS_ELVIS") - override fun getColor(type: Int): Int { - if (type == SchemeAndroidIDE.SYNTAX_SPAN_NO_BACKGROUND) { - return android.graphics.Color.TRANSPARENT - } - // getColor is called in superclass constructor - // in this case, the below properties will be null - val defaultValue = super.getColor(type) - return editorScheme?.getOrElse(type) { - colorIds?.getOrDefault(type, defaultValue) ?: defaultValue - } ?: defaultValue - } - - override fun isDark(): Boolean { - return this.isDarkScheme - } +class IDEColorScheme( + internal val file: File, + val key: String, +) : DynamicColorScheme() { + internal val colorIds = MutableIntIntMap() + internal val editorScheme = MutableIntIntMap() + internal val languages = mutableMapOf() + + var name: String = "" + internal set + + var version: Int = 0 + internal set + + var isDarkScheme: Boolean = false + internal set + + var darkVariant: IDEColorScheme? = null + internal set + + var definitions: Map = emptyMap() + internal set + + private var colorId = endColorId + + internal fun load() { + SchemeParser { name -> File(this.file.parentFile, name) }.load(this) + } + + fun getLanguageScheme(type: String): LanguageScheme? = this.languages[type] + + internal fun putColor(color: Int): Int { + this.colorIds[++colorId] = color + return colorId + } + + @Suppress("UNNECESSARY_SAFE_CALL", "USELESS_ELVIS") + override fun getColor(type: Int): Int { + if (type == SchemeAndroidIDE.SYNTAX_SPAN_NO_BACKGROUND) { + return android.graphics.Color.TRANSPARENT + } + // getColor is called in superclass constructor + // in this case, the below properties will be null + val defaultValue = super.getColor(type) + return editorScheme?.getOrElse(type) { + colorIds?.getOrDefault(type, defaultValue) ?: defaultValue + } ?: defaultValue + } + + override fun isDark(): Boolean = this.isDarkScheme } /** @@ -88,37 +86,27 @@ class IDEColorScheme(internal val file: File, val key: String) : DynamicColorSch * @author Akash Yadav */ class LanguageScheme { + internal val files = mutableListOf() + internal val styles = mutableMapOf() + internal val localScopes = TreeSet() + internal val localMembersScopes = TreeSet() + internal val localDefs = TreeSet() + internal val localDefVals = TreeSet() + internal val localRefs = TreeSet() - internal val files = mutableListOf() - internal val styles = mutableMapOf() - internal val localScopes = TreeSet() - internal val localMembersScopes = TreeSet() - internal val localDefs = TreeSet() - internal val localDefVals = TreeSet() - internal val localRefs = TreeSet() + fun getFileTypes(): List = files - fun getFileTypes(): List = files - fun getStyles(): Map = styles + fun getStyles(): Map = styles - fun isLocalScope(capture: String): Boolean { - return localScopes.contains(capture) - } + fun isLocalScope(capture: String): Boolean = localScopes.contains(capture) - fun isMembersScope(capture: String): Boolean { - return localMembersScopes.contains(capture) - } + fun isMembersScope(capture: String): Boolean = localMembersScopes.contains(capture) - fun isLocalDef(capture: String): Boolean { - return localDefs.contains(capture) - } + fun isLocalDef(capture: String): Boolean = localDefs.contains(capture) - fun isLocalDefVal(capture: String): Boolean { - return localDefVals.contains(capture) - } + fun isLocalDefVal(capture: String): Boolean = localDefVals.contains(capture) - fun isLocalRef(capture: String): Boolean { - return localRefs.contains(capture) - } + fun isLocalRef(capture: String): Boolean = localRefs.contains(capture) } /** @@ -136,39 +124,37 @@ class LanguageScheme { * will be automatically selected based on the HEX color's brightness. */ data class StyleDef( - var fg: Int = EditorColorScheme.TEXT_NORMAL, - var bg: Int = 0, - var bold: Boolean = false, - var italic: Boolean = false, - var strikeThrough: Boolean = false, - var completion: Boolean = true, - var maybeHexColor: Boolean = false + var fg: Int = EditorColorScheme.TEXT_NORMAL, + var bg: Int = 0, + var bold: Boolean = false, + var italic: Boolean = false, + var strikeThrough: Boolean = false, + var completion: Boolean = true, + var maybeHexColor: Boolean = false, ) { - - /** - * Make the style for the style definition. - * - * @see TextStyle.makeStyle - */ - fun makeStyle(): Long { - val effectiveBg = - if (bg > 0) bg else SchemeAndroidIDE.SYNTAX_SPAN_NO_BACKGROUND - return TextStyle.makeStyle(fg, effectiveBg, bold, italic, strikeThrough, !completion) - } - - /** - * Make the static style for this style definition. The background color ID in the returned style is - * always [EditorColorScheme.STATIC_SPAN_BACKGROUND] and the foreground color ID is always - * [EditorColorScheme.STATIC_SPAN_FOREGROUND]. - */ - fun makeStaticStyle(): Long { - return TextStyle.makeStyle( - EditorColorScheme.STATIC_SPAN_FOREGROUND, - EditorColorScheme.STATIC_SPAN_BACKGROUND, - bold, - italic, - strikeThrough, - !completion - ) - } + /** + * Make the style for the style definition. + * + * @see TextStyle.makeStyle + */ + fun makeStyle(): Long { + val effectiveBg = + if (bg > 0) bg else SchemeAndroidIDE.SYNTAX_SPAN_NO_BACKGROUND + return TextStyle.makeStyle(fg, effectiveBg, bold, italic, strikeThrough, !completion) + } + + /** + * Make the static style for this style definition. The background color ID in the returned style is + * always [EditorColorScheme.STATIC_SPAN_BACKGROUND] and the foreground color ID is always + * [EditorColorScheme.STATIC_SPAN_FOREGROUND]. + */ + fun makeStaticStyle(): Long = + TextStyle.makeStyle( + EditorColorScheme.STATIC_SPAN_FOREGROUND, + EditorColorScheme.STATIC_SPAN_BACKGROUND, + bold, + italic, + strikeThrough, + !completion, + ) } diff --git a/editor/src/main/java/com/itsaky/androidide/editor/schemes/internal/parser/common.kt b/editor/src/main/java/com/itsaky/androidide/editor/schemes/internal/parser/common.kt index 273153f71b..5f3d2c9c8c 100644 --- a/editor/src/main/java/com/itsaky/androidide/editor/schemes/internal/parser/common.kt +++ b/editor/src/main/java/com/itsaky/androidide/editor/schemes/internal/parser/common.kt @@ -27,17 +27,17 @@ import java.io.File /** @author Akash Yadav */ fun IDEColorScheme.parseEditorScheme(reader: JsonReader, resolveFileRef: (String) -> File) { - val newReader = if (reader.peek() == STRING) { - readerForFileRef(reader, "editor", resolveFileRef) - } else reader +val newReader = if (reader.peek() == STRING) { + readerForFileRef(reader, "editor", resolveFileRef) +} else reader - try { - EditorSchemeParser(newReader).parse(this) - } finally { - if (reader !== newReader) { - newReader.close() - } - } +try { + EditorSchemeParser(newReader).parse(this) +} finally { + if (reader !== newReader) { + newReader.close() + } +} } /** @@ -45,97 +45,97 @@ fun IDEColorScheme.parseEditorScheme(reader: JsonReader, resolveFileRef: (String * instead. */ fun IDEColorScheme.parseColorValue(value: String?, colorId: Boolean = true): Int { - require(!value.isNullOrBlank()) { "Color value is not expected to be null or blank" } - if (value[0] == '@') { - val refName = value.substring(1) - val refValue = - definitions[refName] ?: throw ParseException("Referenced color '$value' not found") - return if (colorId) refValue else colorIds.getOrDefault(refValue, 0) - } +require(!value.isNullOrBlank()) { "Color value is not expected to be null or blank" } +if (value[0] == '@') { + val refName = value.substring(1) + val refValue = + definitions[refName] ?: throw ParseException("Referenced color '$value' not found") + return if (colorId) refValue else colorIds.getOrDefault(refValue, 0) +} - if (value[0] == '#') { - val color = - try { - parseHexColor(value).toInt() - } catch (err: Throwable) { - throw ParseException("Invalid hex color code: '$value'", err) - } - return if (colorId) try {putColor(color)}catch (err: Throwable) {color} else color - } +if (value[0] == '#') { + val color = + try { + parseHexColor(value).toInt() + } catch (err: Throwable) { + throw ParseException("Invalid hex color code: '$value'", err) + } + return if (colorId) try {putColor(color)}catch (err: Throwable) {color} else color +} - throw ParseException("Unsupported color value '$value'") +throw ParseException("Unsupported color value '$value'") } fun IDEColorScheme.parseDefinitions(reader: JsonReader): Map { - val result = mutableMapOf() - reader.beginObject() - while (reader.hasNext()) { - val name = reader.nextName() - val value = reader.nextString() - result[name] = parseColorValue(value) - } - reader.endObject() - return result +val result = mutableMapOf() +reader.beginObject() +while (reader.hasNext()) { + val name = reader.nextName() + val value = reader.nextString() + result[name] = parseColorValue(value) +} +reader.endObject() +return result } fun IDEColorScheme.parseLanguages(reader: JsonReader, resolveFileRef: (String) -> File) { - reader.beginArray() - while (reader.hasNext()) { - val lang = parseLanguage(reader, resolveFileRef) - lang.files.forEach { languages[it] = lang } - } - reader.endArray() +reader.beginArray() +while (reader.hasNext()) { + val lang = parseLanguage(reader, resolveFileRef) + lang.files.forEach { languages[it] = lang } +} +reader.endArray() } fun IDEColorScheme.parseLanguage( - reader: JsonReader, - resolveFileRef: (String) -> File +reader: JsonReader, +resolveFileRef: (String) -> File ): LanguageScheme { - val newReader = - if (reader.peek() == STRING) { - readerForFileRef(reader, "language", resolveFileRef) - } else reader +val newReader = + if (reader.peek() == STRING) { + readerForFileRef(reader, "language", resolveFileRef) + } else reader - return try { - LanguageParser(newReader).parseLang(this) - } finally { - if (reader !== newReader) { - newReader.close() - } - } +return try { + LanguageParser(newReader).parseLang(this) +} finally { + if (reader !== newReader) { + newReader.close() + } +} } private fun readerForFileRef(reader: JsonReader, scheme: String, - resolveFileRef: (String) -> File): JsonReader { - val value = reader.nextString() - if (value.length <= 1 || value[0] != '@') { - throw ParseException("Expected a $scheme scheme file reference but was '$value'") - } +resolveFileRef: (String) -> File): JsonReader { +val value = reader.nextString() +if (value.length <= 1 || value[0] != '@') { + throw ParseException("Expected a $scheme scheme file reference but was '$value'") +} - val langFile = resolveFileRef(value.substring(1)) - if (!langFile.exists() || !langFile.isFile) { - throw ParseException("Referenced file does not exist or is not a file '$langFile'") - } - return JsonReader(langFile.reader()) +val langFile = resolveFileRef(value.substring(1)) +if (!langFile.exists() || !langFile.isFile) { + throw ParseException("Referenced file does not exist or is not a file '$langFile'") +} +return JsonReader(langFile.reader()) } fun IDEColorScheme.parseStyleDef(reader: JsonReader): StyleDef { - reader.beginObject() - val def = StyleDef(fg = 0) - while (reader.hasNext()) { - when (reader.nextName()) { - "fg" -> def.fg = parseColorValue(reader.nextString()) - "bg" -> def.bg = parseColorValue(reader.nextString()) - "bold" -> def.bold = reader.nextBoolean() - "italic" -> def.italic = reader.nextBoolean() - "strikethrough" -> def.strikeThrough = reader.nextBoolean() - "completion" -> def.completion = reader.nextBoolean() - "maybeHexColor" -> def.maybeHexColor = reader.nextBoolean() - } - } - if (def.fg == 0) { - throw ParseException("A style definition must specify a valid foreground color") - } - reader.endObject() - return def +reader.beginObject() +val def = StyleDef(fg = 0) +while (reader.hasNext()) { + when (reader.nextName()) { + "fg" -> def.fg = parseColorValue(reader.nextString()) + "bg" -> def.bg = parseColorValue(reader.nextString()) + "bold" -> def.bold = reader.nextBoolean() + "italic" -> def.italic = reader.nextBoolean() + "strikethrough" -> def.strikeThrough = reader.nextBoolean() + "completion" -> def.completion = reader.nextBoolean() + "maybeHexColor" -> def.maybeHexColor = reader.nextBoolean() + } +} +if (def.fg == 0) { + throw ParseException("A style definition must specify a valid foreground color") +} +reader.endObject() +return def } From 34489a8717aaa040c71f222cd8ead66b2cb57903 Mon Sep 17 00:00:00 2001 From: Daniel Alome Date: Sat, 12 Sep 2026 19:35:22 +0100 Subject: [PATCH 2/4] ADFA-3738: Tap a stack frame in App Logs to open its source When a crash in the user's running app streams into the App Logs tab, its stack-trace frames are now actionable: - StackFrameLocator (shared) parses "at pkg.Class.method(File.kt:42)" out of a rendered logcat line and resolves it against the open project's module source directories. - LogViewFragment subscribes to editor click events; tapping a frame opens the file at the line and collapses the bottom sheet, reusing the deep-link open path. A frame with no matching project source (framework or library code) flashes "No project source found for " instead of doing nothing. - The file:line portion of a resolvable-shaped frame is underlined in the log view via a new "underlineSourceLocation" style flag: a tree-sitter highlight clause tags such frames, the scheme parser reads the flag, and TreeSitterSpanFactory draws an underline span over just the file:line span. Scheme versions bumped 13->14 so the new styles re-extract on update. StackFrameLocator has unit tests (:shared:test, 8 passing); :app:assembleV8Debug builds; spotlessCheck clean. Verified on an arm64 emulator with crash frames streamed into App Logs: frames render underlined, tapping a project frame opens MainActivity.kt at the reported line. --- .../fragments/output/LogViewFragment.kt | 43 ++++++++++ .../schemes/default-dark/default-dark.json | 2 + .../editor/schemes/default-dark/log.json | 4 + .../editor/schemes/default-dark/scheme.prop | 2 +- .../editor/schemes/default/default.json | 2 + .../assets/editor/schemes/default/log.json | 4 + .../assets/editor/schemes/default/scheme.prop | 2 +- .../editor/treesitter/log/highlights.scm | 5 ++ .../treesitter/TreeSitterSpanFactory.kt | 30 ++++++- .../editor/schemes/IDEColorScheme.kt | 1 + .../editor/schemes/internal/parser/common.kt | 1 + resources/src/main/res/values/strings.xml | 1 + .../androidide/utils/StackFrameLocator.kt | 35 ++++++++ .../androidide/utils/StackFrameLocatorTest.kt | 81 +++++++++++++++++++ 14 files changed, 210 insertions(+), 3 deletions(-) create mode 100644 shared/src/main/java/com/itsaky/androidide/utils/StackFrameLocator.kt create mode 100644 shared/src/test/java/com/itsaky/androidide/utils/StackFrameLocatorTest.kt diff --git a/app/src/main/java/com/itsaky/androidide/fragments/output/LogViewFragment.kt b/app/src/main/java/com/itsaky/androidide/fragments/output/LogViewFragment.kt index db8aa1c5c5..481e61e158 100644 --- a/app/src/main/java/com/itsaky/androidide/fragments/output/LogViewFragment.kt +++ b/app/src/main/java/com/itsaky/androidide/fragments/output/LogViewFragment.kt @@ -24,6 +24,7 @@ import androidx.annotation.UiThread import androidx.lifecycle.Lifecycle import androidx.lifecycle.repeatOnLifecycle import com.itsaky.androidide.R +import com.itsaky.androidide.activities.editor.BaseEditorActivity import com.itsaky.androidide.databinding.FragmentLogBinding import com.itsaky.androidide.databinding.LayoutLogFilterBarBinding import com.itsaky.androidide.editor.language.treesitter.LogLanguage @@ -36,15 +37,27 @@ import com.itsaky.androidide.eventbus.events.preferences.PreferenceChangeEvent import com.itsaky.androidide.fragments.EmptyStateFragment import com.itsaky.androidide.models.LogFilter import com.itsaky.androidide.models.LogLine +import com.itsaky.androidide.models.Position +import com.itsaky.androidide.models.Range import com.itsaky.androidide.preferences.internal.EditorPreferences +import com.itsaky.androidide.projects.IProjectManager +import com.itsaky.androidide.projects.api.ModuleProject import com.itsaky.androidide.utils.BasicBuildInfo +import com.itsaky.androidide.utils.StackFrame +import com.itsaky.androidide.utils.StackFrameLocator import com.itsaky.androidide.utils.flashInfo import com.itsaky.androidide.utils.isTestMode import com.itsaky.androidide.utils.jetbrainsMono import com.itsaky.androidide.utils.viewLifecycleScope import com.itsaky.androidide.viewmodel.LogViewModel +import io.github.rosemoe.sora.event.ClickEvent +import io.github.rosemoe.sora.util.IntPair +import io.github.rosemoe.sora.widget.REGION_TEXT +import io.github.rosemoe.sora.widget.resolveTouchRegion import io.github.rosemoe.sora.widget.style.CursorAnimator +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext import kotlinx.coroutines.withTimeoutOrNull import org.greenrobot.eventbus.EventBus import org.greenrobot.eventbus.Subscribe @@ -253,6 +266,11 @@ abstract class LogViewFragment : editor.isEnsurePosAnimEnabled = false editor.tag = tooltipTag editor.cursorAnimator = NoOpCursorAnimator + editor.subscribeEvent(ClickEvent::class.java) { event, _ -> + if (IntPair.getFirst(editor.resolveTouchRegion(event.causingEvent)) != REGION_TEXT) return@subscribeEvent + val frame = StackFrameLocator.parse(editor.text.getLineString(event.line)) ?: return@subscribeEvent + openStackFrame(frame) + } // Skip tree-sitter language setup during tests to avoid native library issues if (!isTestMode()) { @@ -273,6 +291,31 @@ abstract class LogViewFragment : } } + private fun openStackFrame(frame: StackFrame) { + viewLifecycleScope.launch { + val file = + withContext(Dispatchers.IO) { + val sourceDirs = + IProjectManager + .getInstance() + .workspace + ?.subProjects + .orEmpty() + .filterIsInstance() + .flatMap { it.getSourceDirectories() } + StackFrameLocator.locate(frame, sourceDirs) + } + if (file == null) { + flashInfo(getString(R.string.msg_stack_frame_source_not_found, frame.fileName)) + return@launch + } + (activity as? BaseEditorActivity)?.apply { + doOpenFile(file, Range.pointRange(Position(frame.line - 1, 0))) + hideBottomSheet() + } + } + } + @UiThread private fun setText(text: String) { val editor = _binding?.editor ?: return diff --git a/editor/src/main/assets/editor/schemes/default-dark/default-dark.json b/editor/src/main/assets/editor/schemes/default-dark/default-dark.json index ea4ae4fc96..2414835acb 100644 --- a/editor/src/main/assets/editor/schemes/default-dark/default-dark.json +++ b/editor/src/main/assets/editor/schemes/default-dark/default-dark.json @@ -60,6 +60,8 @@ "log.verbose.pr.fg" : "#000000", "log.verbose.pr.bg" : "#ffffff", + "log.frame.text": "#82b1ff", + "breakpoint.line.indicator": "#f44336", "breakpoint.line.bg": "#f44336" }, diff --git a/editor/src/main/assets/editor/schemes/default-dark/log.json b/editor/src/main/assets/editor/schemes/default-dark/log.json index fccd820f40..ae8c8acff8 100644 --- a/editor/src/main/assets/editor/schemes/default-dark/log.json +++ b/editor/src/main/assets/editor/schemes/default-dark/log.json @@ -1,6 +1,10 @@ { "types": ["log"], "styles": { + "stack.frame": { + "fg": "@log.frame.text", + "underlineSourceLocation": true + }, "begin_header" : { "fg": "@comment", "italic": true diff --git a/editor/src/main/assets/editor/schemes/default-dark/scheme.prop b/editor/src/main/assets/editor/schemes/default-dark/scheme.prop index dc9122120c..cee9e44e0d 100644 --- a/editor/src/main/assets/editor/schemes/default-dark/scheme.prop +++ b/editor/src/main/assets/editor/schemes/default-dark/scheme.prop @@ -2,7 +2,7 @@ scheme.name=AndroidIDE Default - Dark # The version code of the color scheme -scheme.version=13 +scheme.version=14 # Whether the scheme is dark or light scheme.isDark=true diff --git a/editor/src/main/assets/editor/schemes/default/default.json b/editor/src/main/assets/editor/schemes/default/default.json index e2372f8aa9..703afce508 100644 --- a/editor/src/main/assets/editor/schemes/default/default.json +++ b/editor/src/main/assets/editor/schemes/default/default.json @@ -61,6 +61,8 @@ "log.verbose.pr.fg" : "#000000", "log.verbose.pr.bg" : "#ffffff", + "log.frame.text": "#1565c0", + "breakpoint.line.indicator": "#f77b72", "breakpoint.line.bg": "#f77b72" }, diff --git a/editor/src/main/assets/editor/schemes/default/log.json b/editor/src/main/assets/editor/schemes/default/log.json index fccd820f40..ae8c8acff8 100644 --- a/editor/src/main/assets/editor/schemes/default/log.json +++ b/editor/src/main/assets/editor/schemes/default/log.json @@ -1,6 +1,10 @@ { "types": ["log"], "styles": { + "stack.frame": { + "fg": "@log.frame.text", + "underlineSourceLocation": true + }, "begin_header" : { "fg": "@comment", "italic": true diff --git a/editor/src/main/assets/editor/schemes/default/scheme.prop b/editor/src/main/assets/editor/schemes/default/scheme.prop index 36c6045896..c39635bdc2 100644 --- a/editor/src/main/assets/editor/schemes/default/scheme.prop +++ b/editor/src/main/assets/editor/schemes/default/scheme.prop @@ -2,7 +2,7 @@ scheme.name=AndroidIDE Default # The version code of the color scheme -scheme.version=13 +scheme.version=14 # Whether the scheme is dark or light scheme.isDark=false diff --git a/editor/src/main/assets/editor/treesitter/log/highlights.scm b/editor/src/main/assets/editor/treesitter/log/highlights.scm index 18bd544567..9885001556 100644 --- a/editor/src/main/assets/editor/treesitter/log/highlights.scm +++ b/editor/src/main/assets/editor/treesitter/log/highlights.scm @@ -1,5 +1,10 @@ (begin_header) @header +(log_line + (message) @stack.frame + (#match? @stack.frame "^\\s*at \\S+\\([\\w-]+\\.(java|kt):\\d+\\)$") +) + (log_line (date) @err.date (time) @err.time diff --git a/editor/src/main/java/com/itsaky/androidide/editor/language/treesitter/TreeSitterSpanFactory.kt b/editor/src/main/java/com/itsaky/androidide/editor/language/treesitter/TreeSitterSpanFactory.kt index 47140fb5e9..594b387fe4 100644 --- a/editor/src/main/java/com/itsaky/androidide/editor/language/treesitter/TreeSitterSpanFactory.kt +++ b/editor/src/main/java/com/itsaky/androidide/editor/language/treesitter/TreeSitterSpanFactory.kt @@ -22,12 +22,15 @@ import androidx.core.graphics.ColorUtils import com.itsaky.androidide.editor.schemes.LanguageScheme import com.itsaky.androidide.treesitter.TSQuery import com.itsaky.androidide.treesitter.TSQueryCapture +import com.itsaky.androidide.utils.StackFrameLocator import com.itsaky.androidide.utils.parseHexColor import io.github.rosemoe.sora.editor.ts.spans.DefaultSpanFactory import io.github.rosemoe.sora.editor.ts.spans.TsSpanFactory import io.github.rosemoe.sora.lang.styling.Span import io.github.rosemoe.sora.lang.styling.SpanFactory import io.github.rosemoe.sora.lang.styling.Styles +import io.github.rosemoe.sora.lang.styling.color.EditorColor +import io.github.rosemoe.sora.lang.styling.color.ResolvableColor import io.github.rosemoe.sora.lang.styling.span.SpanConstColorResolver import io.github.rosemoe.sora.lang.styling.span.SpanExtAttrs import io.github.rosemoe.sora.text.ContentReference @@ -69,7 +72,7 @@ class TreeSitterSpanFactory( val captureName = query.getCaptureNameForId(capture.index) val styleDef = langScheme.getStyles()[captureName] - if (styleDef?.maybeHexColor != true) { + if (styleDef == null || (!styleDef.maybeHexColor && !styleDef.underlineSourceLocation)) { return super.createSpans(capture, column, spanStyle) } @@ -84,6 +87,13 @@ class TreeSitterSpanFactory( } val text = content.subContent(start.line, start.column, end.line, end.column) + if (styleDef.underlineSourceLocation) { + val range = + StackFrameLocator.sourceLocationRange(text.toString()) + ?: return super.createSpans(capture, column, spanStyle) + return underlinedSpans(column, spanStyle, range, text.lastIndex, EditorColor(styleDef.fg)) + } + val results = HEX_REGEX.findAll(text) val spans = mutableListOf() var s = -1 @@ -143,4 +153,22 @@ class TreeSitterSpanFactory( return spans } + + private fun underlinedSpans( + column: Int, + spanStyle: Long, + range: IntRange, + lastIndex: Int, + color: ResolvableColor, + ): List { + val spans = mutableListOf() + if (range.first > 0) { + spans.add(SpanFactory.obtain(column, spanStyle)) + } + spans.add(SpanFactory.obtain(column + range.first, spanStyle).also { it.setUnderlineColor(color) }) + if (range.last < lastIndex) { + spans.add(SpanFactory.obtain(column + range.last + 1, spanStyle)) + } + return spans + } } diff --git a/editor/src/main/java/com/itsaky/androidide/editor/schemes/IDEColorScheme.kt b/editor/src/main/java/com/itsaky/androidide/editor/schemes/IDEColorScheme.kt index fc7a0c7214..47442a61b6 100644 --- a/editor/src/main/java/com/itsaky/androidide/editor/schemes/IDEColorScheme.kt +++ b/editor/src/main/java/com/itsaky/androidide/editor/schemes/IDEColorScheme.kt @@ -131,6 +131,7 @@ data class StyleDef( var strikeThrough: Boolean = false, var completion: Boolean = true, var maybeHexColor: Boolean = false, + var underlineSourceLocation: Boolean = false, ) { /** * Make the style for the style definition. diff --git a/editor/src/main/java/com/itsaky/androidide/editor/schemes/internal/parser/common.kt b/editor/src/main/java/com/itsaky/androidide/editor/schemes/internal/parser/common.kt index 5f3d2c9c8c..eda0832617 100644 --- a/editor/src/main/java/com/itsaky/androidide/editor/schemes/internal/parser/common.kt +++ b/editor/src/main/java/com/itsaky/androidide/editor/schemes/internal/parser/common.kt @@ -131,6 +131,7 @@ while (reader.hasNext()) { "strikethrough" -> def.strikeThrough = reader.nextBoolean() "completion" -> def.completion = reader.nextBoolean() "maybeHexColor" -> def.maybeHexColor = reader.nextBoolean() + "underlineSourceLocation" -> def.underlineSourceLocation = reader.nextBoolean() } } if (def.fg == 0) { diff --git a/resources/src/main/res/values/strings.xml b/resources/src/main/res/values/strings.xml index 2420978644..3e0fcd700b 100644 --- a/resources/src/main/res/values/strings.xml +++ b/resources/src/main/res/values/strings.xml @@ -795,6 +795,7 @@ Open a file to show its diagnostic results Filter lines No matching log entries found. + No project source found for %1$s No search matches found. Filter Search diff --git a/shared/src/main/java/com/itsaky/androidide/utils/StackFrameLocator.kt b/shared/src/main/java/com/itsaky/androidide/utils/StackFrameLocator.kt new file mode 100644 index 0000000000..25a0950195 --- /dev/null +++ b/shared/src/main/java/com/itsaky/androidide/utils/StackFrameLocator.kt @@ -0,0 +1,35 @@ +package com.itsaky.androidide.utils + +import java.io.File + +data class StackFrame( + val className: String, + val fileName: String, + val line: Int, +) + +object StackFrameLocator { + private val framePattern = Regex("""\bat\s+([\w.$]+)\.[\w$<>]+\(([\w-]+\.(?:java|kt)):(\d+)\)""") + + fun parse(logLine: String): StackFrame? { + val match = framePattern.find(logLine) ?: return null + val (className, fileName, line) = match.destructured + return StackFrame(className, fileName, line.toInt()) + } + + fun sourceLocationRange(logLine: String): IntRange? { + val groups = framePattern.find(logLine)?.groups ?: return null + return groups[2]!!.range.first..groups[3]!!.range.last + } + + fun locate( + frame: StackFrame, + sourceDirs: Iterable, + ): File? { + val packagePath = frame.className.substringBeforeLast('.', "").replace('.', File.separatorChar) + return sourceDirs + .asSequence() + .map { dir -> File(if (packagePath.isEmpty()) dir else File(dir, packagePath), frame.fileName) } + .firstOrNull { it.isFile } + } +} diff --git a/shared/src/test/java/com/itsaky/androidide/utils/StackFrameLocatorTest.kt b/shared/src/test/java/com/itsaky/androidide/utils/StackFrameLocatorTest.kt new file mode 100644 index 0000000000..bfb46b1ccb --- /dev/null +++ b/shared/src/test/java/com/itsaky/androidide/utils/StackFrameLocatorTest.kt @@ -0,0 +1,81 @@ +package com.itsaky.androidide.utils + +import com.google.common.truth.Truth.assertThat +import org.junit.Test +import java.io.File +import java.nio.file.Files + +class StackFrameLocatorTest { + @Test + fun `parses a Java frame out of a rendered logcat line`() { + val line = + "09-12 10:41:03.123 4242 4242 E AndroidRuntime " + + "\tat com.example.app.MainActivity.onCreate(MainActivity.java:42)" + assertThat(StackFrameLocator.parse(line)) + .isEqualTo(StackFrame("com.example.app.MainActivity", "MainActivity.java", 42)) + } + + @Test + fun `parses a Kotlin lambda frame keeping the synthetic class name`() { + val line = "\tat com.example.app.MainActivity\$onCreate\$1.invoke(MainActivity.kt:50)" + assertThat(StackFrameLocator.parse(line)) + .isEqualTo(StackFrame("com.example.app.MainActivity\$onCreate\$1", "MainActivity.kt", 50)) + } + + @Test + fun `finds the file and line span inside a frame`() { + val line = "\tat com.example.app.MainActivity.onCreate(MainActivity.java:42)" + val range = StackFrameLocator.sourceLocationRange(line) + assertThat(range?.let(line::substring)).isEqualTo("MainActivity.java:42") + assertThat(StackFrameLocator.sourceLocationRange("Caused by: java.lang.IllegalStateException")).isNull() + } + + @Test + fun `ignores lines that are not source frames`() { + assertThat(StackFrameLocator.parse("E AndroidRuntime: Caused by: java.lang.NullPointerException")).isNull() + assertThat(StackFrameLocator.parse("\tat java.lang.reflect.Method.invoke(Native Method)")).isNull() + assertThat(StackFrameLocator.parse("\tat kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(Unknown Source:12)")) + .isNull() + } + + @Test + fun `locates a Java source under its package directory`() { + val root = tempDir() + val expected = sourceFile(root, "com/example/app/MainActivity.java") + val frame = StackFrame("com.example.app.MainActivity", "MainActivity.java", 42) + assertThat(StackFrameLocator.locate(frame, listOf(root))).isEqualTo(expected) + } + + @Test + fun `locates a Kotlin file facade by file name in a later source dir`() { + val javaDir = tempDir() + val kotlinDir = tempDir() + val expected = sourceFile(kotlinDir, "com/example/app/Utils.kt") + val frame = StackFrame("com.example.app.UtilsKt", "Utils.kt", 10) + assertThat(StackFrameLocator.locate(frame, listOf(javaDir, kotlinDir))).isEqualTo(expected) + } + + @Test + fun `locates a default package class at the source root`() { + val root = tempDir() + val expected = sourceFile(root, "Main.java") + assertThat(StackFrameLocator.locate(StackFrame("Main", "Main.java", 3), listOf(root))).isEqualTo(expected) + } + + @Test + fun `returns null for a frame whose file is not in any source dir`() { + val frame = StackFrame("android.app.Activity", "Activity.java", 8000) + assertThat(StackFrameLocator.locate(frame, listOf(tempDir()))).isNull() + } + + private fun tempDir(): File = Files.createTempDirectory("src").toFile() + + private fun sourceFile( + root: File, + relativePath: String, + ): File = + File(root, relativePath).also { + it.parentFile.mkdirs() + it.createNewFile() + } +} From b8353ac89a4a166c18f370bace856aa8dba0b742 Mon Sep 17 00:00:00 2001 From: Daniel Alome Date: Wed, 16 Sep 2026 00:51:33 +0100 Subject: [PATCH 3/4] ADFA-3738: Address CodeRabbit review feedback - openStackFrame wraps its coroutine body: rethrow CancellationException, log and flashError any other throwable, so a throw from IProjectManager or the source scan cannot escape to the view scope handler. - Store and cancel the frame-navigation Job before each tap, so a slow earlier lookup cannot override a later tap's editor selection. - StackFrameLocator.parse uses toIntOrNull()?.takeIf { it > 0 }, so a frame with an out-of-range line (File.kt:999999999999) returns no match instead of throwing on the click path. Added a test. App Logs verified at font scale 1.0 and 2.0: tab strip, action chips and the empty-state text render without clipping; this change adds no views to the screen. --- .../fragments/output/LogViewFragment.kt | 54 ++++++++++++------- resources/src/main/res/values/strings.xml | 1 + .../androidide/utils/StackFrameLocator.kt | 5 +- .../androidide/utils/StackFrameLocatorTest.kt | 5 ++ 4 files changed, 43 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/com/itsaky/androidide/fragments/output/LogViewFragment.kt b/app/src/main/java/com/itsaky/androidide/fragments/output/LogViewFragment.kt index 481e61e158..f6b4aeffb5 100644 --- a/app/src/main/java/com/itsaky/androidide/fragments/output/LogViewFragment.kt +++ b/app/src/main/java/com/itsaky/androidide/fragments/output/LogViewFragment.kt @@ -45,6 +45,7 @@ import com.itsaky.androidide.projects.api.ModuleProject import com.itsaky.androidide.utils.BasicBuildInfo import com.itsaky.androidide.utils.StackFrame import com.itsaky.androidide.utils.StackFrameLocator +import com.itsaky.androidide.utils.flashError import com.itsaky.androidide.utils.flashInfo import com.itsaky.androidide.utils.isTestMode import com.itsaky.androidide.utils.jetbrainsMono @@ -55,7 +56,9 @@ import io.github.rosemoe.sora.util.IntPair import io.github.rosemoe.sora.widget.REGION_TEXT import io.github.rosemoe.sora.widget.resolveTouchRegion import io.github.rosemoe.sora.widget.style.CursorAnimator +import kotlinx.coroutines.CancellationException import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.Job import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import kotlinx.coroutines.withTimeoutOrNull @@ -291,29 +294,40 @@ abstract class LogViewFragment : } } + private var frameNavigationJob: Job? = null + private fun openStackFrame(frame: StackFrame) { - viewLifecycleScope.launch { - val file = - withContext(Dispatchers.IO) { - val sourceDirs = - IProjectManager - .getInstance() - .workspace - ?.subProjects - .orEmpty() - .filterIsInstance() - .flatMap { it.getSourceDirectories() } - StackFrameLocator.locate(frame, sourceDirs) + frameNavigationJob?.cancel() + frameNavigationJob = + viewLifecycleScope.launch { + try { + val file = + withContext(Dispatchers.IO) { + val sourceDirs = + IProjectManager + .getInstance() + .workspace + ?.subProjects + .orEmpty() + .filterIsInstance() + .flatMap { it.getSourceDirectories() } + StackFrameLocator.locate(frame, sourceDirs) + } + if (file == null) { + flashInfo(getString(R.string.msg_stack_frame_source_not_found, frame.fileName)) + return@launch + } + (activity as? BaseEditorActivity)?.apply { + doOpenFile(file, Range.pointRange(Position(frame.line - 1, 0))) + hideBottomSheet() + } + } catch (e: CancellationException) { + throw e + } catch (e: Throwable) { + log.error("Failed to open source for stack frame {}", frame.fileName, e) + flashError(getString(R.string.msg_stack_frame_open_failed, frame.fileName)) } - if (file == null) { - flashInfo(getString(R.string.msg_stack_frame_source_not_found, frame.fileName)) - return@launch - } - (activity as? BaseEditorActivity)?.apply { - doOpenFile(file, Range.pointRange(Position(frame.line - 1, 0))) - hideBottomSheet() } - } } @UiThread diff --git a/resources/src/main/res/values/strings.xml b/resources/src/main/res/values/strings.xml index 3e0fcd700b..4aabecac89 100644 --- a/resources/src/main/res/values/strings.xml +++ b/resources/src/main/res/values/strings.xml @@ -796,6 +796,7 @@ Filter lines No matching log entries found. No project source found for %1$s + Could not open the source for %1$s No search matches found. Filter Search diff --git a/shared/src/main/java/com/itsaky/androidide/utils/StackFrameLocator.kt b/shared/src/main/java/com/itsaky/androidide/utils/StackFrameLocator.kt index 25a0950195..dc59db1325 100644 --- a/shared/src/main/java/com/itsaky/androidide/utils/StackFrameLocator.kt +++ b/shared/src/main/java/com/itsaky/androidide/utils/StackFrameLocator.kt @@ -13,8 +13,9 @@ object StackFrameLocator { fun parse(logLine: String): StackFrame? { val match = framePattern.find(logLine) ?: return null - val (className, fileName, line) = match.destructured - return StackFrame(className, fileName, line.toInt()) + val (className, fileName, lineText) = match.destructured + val line = lineText.toIntOrNull()?.takeIf { it > 0 } ?: return null + return StackFrame(className, fileName, line) } fun sourceLocationRange(logLine: String): IntRange? { diff --git a/shared/src/test/java/com/itsaky/androidide/utils/StackFrameLocatorTest.kt b/shared/src/test/java/com/itsaky/androidide/utils/StackFrameLocatorTest.kt index bfb46b1ccb..2961c81682 100644 --- a/shared/src/test/java/com/itsaky/androidide/utils/StackFrameLocatorTest.kt +++ b/shared/src/test/java/com/itsaky/androidide/utils/StackFrameLocatorTest.kt @@ -38,6 +38,11 @@ class StackFrameLocatorTest { .isNull() } + @Test + fun `ignores a frame whose line number does not fit in an Int`() { + assertThat(StackFrameLocator.parse("\tat com.example.app.MainActivity.onCreate(MainActivity.kt:999999999999)")).isNull() + } + @Test fun `locates a Java source under its package directory`() { val root = tempDir() From 398243e2da69f26d5f0ee755f0cf63a0c9922472 Mon Sep 17 00:00:00 2001 From: Daniel Alome Date: Wed, 16 Sep 2026 19:11:24 +0100 Subject: [PATCH 4/4] ADFA-3738: Address review feedback (dara-abijo-adfa) - Restrict the tap to the underlined file:line span: openStackFrame runs only when the tap column falls within StackFrameLocator.sourceLocationRange, so tapping the timestamp or tag no longer navigates. Applies to App Logs and IDE Logs, which share LogViewFragment. - Align the highlights.scm #match? regex to StackFrameLocator's frame pattern (\bat\s+[\w.$]+\.[\w$<>]+\(...\) rather than \S+), so an underlined frame is exactly a clickable one. Cross-checked both against sample frames including $-synthetic, and nested-class frames: no mismatches. --- .../itsaky/androidide/fragments/output/LogViewFragment.kt | 5 ++++- editor/src/main/assets/editor/treesitter/log/highlights.scm | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/itsaky/androidide/fragments/output/LogViewFragment.kt b/app/src/main/java/com/itsaky/androidide/fragments/output/LogViewFragment.kt index f6b4aeffb5..2f2ddab7f0 100644 --- a/app/src/main/java/com/itsaky/androidide/fragments/output/LogViewFragment.kt +++ b/app/src/main/java/com/itsaky/androidide/fragments/output/LogViewFragment.kt @@ -271,7 +271,10 @@ abstract class LogViewFragment : editor.cursorAnimator = NoOpCursorAnimator editor.subscribeEvent(ClickEvent::class.java) { event, _ -> if (IntPair.getFirst(editor.resolveTouchRegion(event.causingEvent)) != REGION_TEXT) return@subscribeEvent - val frame = StackFrameLocator.parse(editor.text.getLineString(event.line)) ?: return@subscribeEvent + val lineString = editor.text.getLineString(event.line) + val sourceRange = StackFrameLocator.sourceLocationRange(lineString) ?: return@subscribeEvent + if (event.column !in sourceRange) return@subscribeEvent + val frame = StackFrameLocator.parse(lineString) ?: return@subscribeEvent openStackFrame(frame) } diff --git a/editor/src/main/assets/editor/treesitter/log/highlights.scm b/editor/src/main/assets/editor/treesitter/log/highlights.scm index 9885001556..b095579032 100644 --- a/editor/src/main/assets/editor/treesitter/log/highlights.scm +++ b/editor/src/main/assets/editor/treesitter/log/highlights.scm @@ -2,7 +2,7 @@ (log_line (message) @stack.frame - (#match? @stack.frame "^\\s*at \\S+\\([\\w-]+\\.(java|kt):\\d+\\)$") + (#match? @stack.frame "\\bat\\s+[\\w.$]+\\.[\\w$<>]+\\([\\w-]+\\.(java|kt):\\d+\\)") ) (log_line