Search in sources :

Example 11 with HyperlinkInfo

use of com.intellij.execution.filters.HyperlinkInfo in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoConsoleFilterTest method assertResultAndGetHyperlink.

@NotNull
private static HyperlinkInfo assertResultAndGetHyperlink(@NotNull Filter.Result result, int startOffset, int endOffset) {
    List<Filter.ResultItem> items = result.getResultItems();
    assertSize(1, items);
    Filter.ResultItem item = ContainerUtil.getFirstItem(items);
    assertNotNull(item);
    assertEquals("start", startOffset, item.getHighlightStartOffset());
    assertEquals("end", endOffset, item.getHighlightEndOffset());
    HyperlinkInfo hyperlinkInfo = item.getHyperlinkInfo();
    assertNotNull(hyperlinkInfo);
    return hyperlinkInfo;
}
Also used : Filter(com.intellij.execution.filters.Filter) HyperlinkInfo(com.intellij.execution.filters.HyperlinkInfo) OpenFileHyperlinkInfo(com.intellij.execution.filters.OpenFileHyperlinkInfo) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with HyperlinkInfo

use of com.intellij.execution.filters.HyperlinkInfo in project intellij-elixir by KronicDeth.

the class FileReferenceFilter method applyFilter.

@Nullable
@Override
public Result applyFilter(@NotNull String line, int entireLength) {
    Matcher matcher = myPattern.matcher(line);
    if (!matcher.find()) {
        return null;
    }
    String filePath = matcher.group(myFileMatchGroup);
    int fileLine = matchGroupToNumber(matcher, myLineMatchGroup);
    int fileColumn = matchGroupToNumber(matcher, myColumnMatchGroup);
    int highlightStartOffset = entireLength - line.length() + matcher.start(0) + 1;
    int highlightEndOffset = highlightStartOffset + matcher.end(0) - matcher.start(0) - 1;
    VirtualFile absolutePath = resolveAbsolutePath(filePath);
    HyperlinkInfo hyperlinkInfo = absolutePath != null ? new OpenFileHyperlinkInfo(myProject, absolutePath, fileLine, fileColumn) : null;
    return new Result(highlightStartOffset, highlightEndOffset, hyperlinkInfo);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) OpenFileHyperlinkInfo(com.intellij.execution.filters.OpenFileHyperlinkInfo) Matcher(java.util.regex.Matcher) HyperlinkInfo(com.intellij.execution.filters.HyperlinkInfo) OpenFileHyperlinkInfo(com.intellij.execution.filters.OpenFileHyperlinkInfo) Nullable(org.jetbrains.annotations.Nullable)

Example 13 with HyperlinkInfo

use of com.intellij.execution.filters.HyperlinkInfo in project intellij-community by JetBrains.

the class EventLog method formatForLog.

public static LogEntry formatForLog(@NotNull final Notification notification, final String indent) {
    DocumentImpl logDoc = new DocumentImpl("", true);
    AtomicBoolean showMore = new AtomicBoolean(false);
    Map<RangeMarker, HyperlinkInfo> links = new LinkedHashMap<>();
    List<RangeMarker> lineSeparators = new ArrayList<>();
    String title = notification.getTitle();
    String subtitle = notification.getSubtitle();
    if (StringUtil.isNotEmpty(title) && StringUtil.isNotEmpty(subtitle)) {
        title += " (" + subtitle + ")";
    }
    title = truncateLongString(showMore, title);
    String content = truncateLongString(showMore, notification.getContent());
    RangeMarker afterTitle = null;
    boolean hasHtml = parseHtmlContent(addIndents(title, indent), notification, logDoc, showMore, links, lineSeparators);
    if (StringUtil.isNotEmpty(title)) {
        if (StringUtil.isNotEmpty(content)) {
            appendText(logDoc, ": ");
            afterTitle = logDoc.createRangeMarker(logDoc.getTextLength() - 2, logDoc.getTextLength());
        }
    }
    int titleLength = logDoc.getTextLength();
    hasHtml |= parseHtmlContent(addIndents(content, indent), notification, logDoc, showMore, links, lineSeparators);
    List<AnAction> actions = notification.getActions();
    if (!actions.isEmpty()) {
        String text = "<p>" + StringUtil.join(actions, new Function<AnAction, String>() {

            private int index;

            @Override
            public String fun(AnAction action) {
                return "<a href=\"" + index++ + "\">" + action.getTemplatePresentation().getText() + "</a>";
            }
        }, isLongLine(actions) ? "<br>" : "&nbsp;") + "</p>";
        Notification n = new Notification("", "", ".", NotificationType.INFORMATION, new NotificationListener() {

            @Override
            public void hyperlinkUpdate(@NotNull Notification n, @NotNull HyperlinkEvent event) {
                Notification.fire(notification, notification.getActions().get(Integer.parseInt(event.getDescription())));
            }
        });
        if (title.length() > 0 || content.length() > 0) {
            lineSeparators.add(logDoc.createRangeMarker(TextRange.from(logDoc.getTextLength(), 0)));
        }
        hasHtml |= parseHtmlContent(text, n, logDoc, showMore, links, lineSeparators);
    }
    String status = getStatusText(logDoc, showMore, lineSeparators, indent, hasHtml);
    indentNewLines(logDoc, lineSeparators, afterTitle, hasHtml, indent);
    ArrayList<Pair<TextRange, HyperlinkInfo>> list = new ArrayList<>();
    for (RangeMarker marker : links.keySet()) {
        if (!marker.isValid()) {
            showMore.set(true);
            continue;
        }
        list.add(Pair.create(new TextRange(marker.getStartOffset(), marker.getEndOffset()), links.get(marker)));
    }
    if (showMore.get()) {
        String sb = "show balloon";
        if (!logDoc.getText().endsWith(" ")) {
            appendText(logDoc, " ");
        }
        appendText(logDoc, "(" + sb + ")");
        list.add(new Pair<>(TextRange.from(logDoc.getTextLength() - 1 - sb.length(), sb.length()), new ShowBalloon(notification)));
    }
    return new LogEntry(logDoc.getText(), status, list, titleLength);
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) RangeMarker(com.intellij.openapi.editor.RangeMarker) DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl) AnAction(com.intellij.openapi.actionSystem.AnAction) RelativePoint(com.intellij.ui.awt.RelativePoint) LinkedHashMap(com.intellij.util.containers.hash.LinkedHashMap) HyperlinkInfo(com.intellij.execution.filters.HyperlinkInfo) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 14 with HyperlinkInfo

use of com.intellij.execution.filters.HyperlinkInfo in project intellij-community by JetBrains.

the class EventLogConsole method doPrintNotification.

void doPrintNotification(final Notification notification) {
    Editor editor = getConsoleEditor();
    if (editor.isDisposed()) {
        return;
    }
    Document document = editor.getDocument();
    boolean scroll = document.getTextLength() == editor.getCaretModel().getOffset() || !editor.getContentComponent().hasFocus();
    if (document.getTextLength() > 0) {
        append(document, "\n");
    }
    String lastDate = DateFormatUtil.formatDate(notification.getTimestamp());
    if (document.getTextLength() == 0 || !lastDate.equals(myLastDate)) {
        myLastDate = lastDate;
        append(document, lastDate + "\n");
    }
    int startDateOffset = document.getTextLength();
    String date = DateFormatUtil.formatTime(notification.getTimestamp()) + "\t";
    append(document, date);
    int tabs = calculateTabs(editor, startDateOffset);
    int titleStartOffset = document.getTextLength();
    int startLine = document.getLineCount() - 1;
    EventLog.LogEntry pair = EventLog.formatForLog(notification, StringUtil.repeatSymbol('\t', tabs));
    final NotificationType type = notification.getType();
    TextAttributesKey key = type == NotificationType.ERROR ? ConsoleViewContentType.LOG_ERROR_OUTPUT_KEY : type == NotificationType.INFORMATION ? ConsoleViewContentType.NORMAL_OUTPUT_KEY : ConsoleViewContentType.LOG_WARNING_OUTPUT_KEY;
    int msgStart = document.getTextLength();
    append(document, pair.message);
    TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(key);
    int layer = HighlighterLayer.CARET_ROW + 1;
    RangeHighlighter highlighter = editor.getMarkupModel().addRangeHighlighter(msgStart, document.getTextLength(), layer, attributes, HighlighterTargetArea.EXACT_RANGE);
    GROUP_ID.set(highlighter, notification.getGroupId());
    NOTIFICATION_ID.set(highlighter, notification.id);
    for (Pair<TextRange, HyperlinkInfo> link : pair.links) {
        final RangeHighlighter rangeHighlighter = myHyperlinkSupport.getValue().createHyperlink(link.first.getStartOffset() + msgStart, link.first.getEndOffset() + msgStart, null, link.second);
        if (link.second instanceof EventLog.ShowBalloon) {
            ((EventLog.ShowBalloon) link.second).setRangeHighlighter(rangeHighlighter);
        }
    }
    append(document, "\n");
    if (scroll) {
        editor.getCaretModel().moveToOffset(document.getTextLength());
        editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
    }
    if (notification.isImportant()) {
        highlightNotification(notification, pair.status, startLine, document.getLineCount() - 1, titleStartOffset, pair.titleLength);
    }
}
Also used : TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey) RelativePoint(com.intellij.ui.awt.RelativePoint) HyperlinkInfo(com.intellij.execution.filters.HyperlinkInfo)

Example 15 with HyperlinkInfo

use of com.intellij.execution.filters.HyperlinkInfo in project intellij-community by JetBrains.

the class SMTestProxyTest method testMultipleAssertions.

public void testMultipleAssertions() {
    mySimpleTest.setStarted();
    mySimpleTest.setTestComparisonFailed("a", "stacktrace", "actual1", "expected1");
    mySimpleTest.setTestComparisonFailed("b", "stacktrace", "actual2", "expected2");
    mySimpleTest.setTestFailed("c", "stacktrace", false);
    mySimpleTest.setFinished();
    final MockPrinter printer = new MockPrinter(true) {

        @Override
        public void printHyperlink(String text, HyperlinkInfo info) {
            print(text, ConsoleViewContentType.SYSTEM_OUTPUT);
        }
    };
    mySimpleTest.printOn(printer);
    assertEquals("", printer.getStdOut());
    assertEquals("\n" + "a\n" + "Expected :expected1\n" + "Actual   :actual1\n" + " <Click to see difference>\n" + "\n" + "stacktrace\n" + "\n" + "b\n" + "Expected :expected2\n" + "Actual   :actual2\n" + " <Click to see difference>\n" + "\n" + "stacktrace\n" + "\n" + "c\n" + "stacktrace\n", printer.getAllOut());
}
Also used : MockPrinter(com.intellij.execution.testframework.sm.runner.ui.MockPrinter) HyperlinkInfo(com.intellij.execution.filters.HyperlinkInfo)

Aggregations

HyperlinkInfo (com.intellij.execution.filters.HyperlinkInfo)19 OpenFileHyperlinkInfo (com.intellij.execution.filters.OpenFileHyperlinkInfo)8 Nullable (org.jetbrains.annotations.Nullable)7 Filter (com.intellij.execution.filters.Filter)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 RelativePoint (com.intellij.ui.awt.RelativePoint)3 NotNull (org.jetbrains.annotations.NotNull)3 FileHyperlinkInfo (com.intellij.execution.filters.FileHyperlinkInfo)2 AnAction (com.intellij.openapi.actionSystem.AnAction)2 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)2 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)2 Project (com.intellij.openapi.project.Project)2 Matcher (java.util.regex.Matcher)2 BuckModule (com.facebook.buck.intellij.ideabuck.config.BuckModule)1 JsErrorMessage (com.google.jstestdriver.idea.common.JsErrorMessage)1 JavaValue (com.intellij.debugger.engine.JavaValue)1 EvaluateException (com.intellij.debugger.engine.evaluation.EvaluateException)1 CompositeFilter (com.intellij.execution.filters.CompositeFilter)1 ExceptionFilter (com.intellij.execution.filters.ExceptionFilter)1 RegexpFilter (com.intellij.execution.filters.RegexpFilter)1