Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #91: Stack trace detection not working in colored console #174

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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;

/**
Expand Down Expand Up @@ -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) {
Expand Down