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;
}
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);
}
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>" : " ") + "</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);
}
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);
}
}
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());
}
Aggregations