Skip to content

Commit

Permalink
Fix #91: Stack trace detection not working in colored console
Browse files Browse the repository at this point in the history
  • Loading branch information
mihnita committed Dec 15, 2024
1 parent ddf0a0a commit 20321ad
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
15 changes: 13 additions & 2 deletions org.eclipse.jdt.debug.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3503,7 +3503,7 @@ M4 = Platform-specific fourth key
point="org.eclipse.ui.console.consolePatternMatchListeners">
<consolePatternMatchListener
class="org.eclipse.jdt.internal.debug.ui.console.JavaConsoleTracker"
regex="\([\w\.\\/@]*${java_extensions_regex}\S*\)"
regex="\(${ansi_escape_regex}[\w\.\\/@]*${java_extensions_regex}\S*${ansi_escape_regex}\)"
qualifier="${java_extensions_regex}"
flags="UNICODE_CHARACTER_CLASS"
id="org.eclipse.jdt.debug.ui.JavaConsoleTracker">
Expand All @@ -3517,7 +3517,7 @@ M4 = Platform-specific fourth key
</consolePatternMatchListener>
<consolePatternMatchListener
class="org.eclipse.jdt.internal.debug.ui.console.JavaNativeConsoleTracker"
regex="\(Native Method\)"
regex="\(${ansi_escape_regex}Native Method${ansi_escape_regex}\)"
qualifier="Native Method"
id="org.eclipse.jdt.debug.ui.JavaNativeConsoleTracker">
<enablement>
Expand Down Expand Up @@ -3890,4 +3890,15 @@ M4 = Platform-specific fourth key
</enabledWhen>
</handler>
</extension>

<extension
point="org.eclipse.core.variables.valueVariables">
<!-- For convenience, to use when we detect stack-trace links -->
<variable
initialValue="(\033\[[\d;]*[A-HJKSTfimnsu])*"
name="ansi_escape_regex"
readOnly="true">
</variable>
</extension>

</plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,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 final TextConsole fConsole;
private final AtomicReference<String> generatedLink;
private static final String REGEX_FOR_NORMAL = "([a-zA-Z0-9\\$]+)\\.([a-zA-Z0-9]+)\\(([^)]*)\\)"; //$NON-NLS-1$
Expand Down Expand Up @@ -103,6 +103,7 @@ public void linkActivated() {
int lineNumber;
try {
String linkText = getLinkText();
linkText = linkText.replaceAll(ANSI_ESCAPE_REGEX, ""); //$NON-NLS-1$
generatedLink.set(linkText);
typeName = getTypeName(linkText);
lineNumber = getLineNumber(linkText);
Expand Down

0 comments on commit 20321ad

Please sign in to comment.