From 0700b09c1b87fb926daf5520d4e6fd76e7d37bba Mon Sep 17 00:00:00 2001 From: Mihai Nita Date: Sun, 15 Jan 2023 18:48:15 -0800 Subject: [PATCH] Fix #91: Stack trace detection not working in colored console --- org.eclipse.jdt.debug.ui/plugin.xml | 15 +++++++++++++-- .../debug/ui/console/JavaConsoleTracker.java | 18 ++++++++++++++---- .../ui/console/JavaStackTraceHyperlink.java | 3 ++- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/org.eclipse.jdt.debug.ui/plugin.xml b/org.eclipse.jdt.debug.ui/plugin.xml index 6a4cbe0fc8..718a2c9a99 100644 --- a/org.eclipse.jdt.debug.ui/plugin.xml +++ b/org.eclipse.jdt.debug.ui/plugin.xml @@ -3503,7 +3503,7 @@ M4 = Platform-specific fourth key point="org.eclipse.ui.console.consolePatternMatchListeners"> @@ -3517,7 +3517,7 @@ M4 = Platform-specific fourth key @@ -3890,4 +3890,15 @@ M4 = Platform-specific fourth key + + + + + + + diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/console/JavaConsoleTracker.java b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/console/JavaConsoleTracker.java index 548c217b98..fbe6f559f5 100644 --- a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/console/JavaConsoleTracker.java +++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/console/JavaConsoleTracker.java @@ -54,12 +54,22 @@ protected TextConsole getConsole() { * @see org.eclipse.ui.console.IPatternMatchListenerDelegate#matchFound(org.eclipse.ui.console.PatternMatchEvent) */ @Override - public void matchFound(PatternMatchEvent event) { + public void matchFound(PatternMatchEvent event) { try { - int offset = event.getOffset(); - int length = event.getLength(); + int offset = event.getOffset() + 1; // skip the leading ( + int length = event.getLength() - 2; // don't count the leading ( and trailing ) + + String text = fConsole.getDocument().get(offset, length); + // Remove the ANSI escape sequences + String textNew = text.replaceAll(JavaStackTraceHyperlink.ANSI_ESCAPE_REGEX, ""); //$NON-NLS-1$ + int delta = text.indexOf(textNew); + if (delta != -1) { + offset += delta; + length = textNew.length(); + } + IHyperlink link = new JavaStackTraceHyperlink(fConsole); - fConsole.addHyperlink(link, offset+1, length-2); + fConsole.addHyperlink(link, offset, length); } catch (BadLocationException e) { } } diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/console/JavaStackTraceHyperlink.java b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/console/JavaStackTraceHyperlink.java index 05c299ace9..cb0a74bc34 100644 --- a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/console/JavaStackTraceHyperlink.java +++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/console/JavaStackTraceHyperlink.java @@ -55,7 +55,7 @@ * A hyper-link from a stack trace line of the form "*(*.java:*)" */ public class JavaStackTraceHyperlink implements IHyperlink { - + final static String ANSI_ESCAPE_REGEX = "\033\\[[\\d;]*[A-HJKSTfimnsu]"; //$NON-NLS-1$ private TextConsole fConsole; /** @@ -89,6 +89,7 @@ public void linkActivated() { int lineNumber; try { String linkText = getLinkText(); + linkText = linkText.replaceAll(ANSI_ESCAPE_REGEX, ""); //$NON-NLS-1$ typeName = getTypeName(linkText); lineNumber = getLineNumber(linkText); } catch (CoreException e1) {