Search in sources :

Example 1 with OpenFileHyperlinkInfo

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

the class PythonConsoleView method printHyperlink.

private void printHyperlink(@NotNull String text, @NotNull ConsoleViewContentType contentType) {
    if (!StringUtil.isEmpty(text)) {
        VirtualFile vFile = LocalFileSystem.getInstance().findFileByPath(text.trim());
        if (vFile != null) {
            OpenFileHyperlinkInfo hyperlink = new OpenFileHyperlinkInfo(getProject(), vFile, -1);
            super.printHyperlink(text, hyperlink);
        } else {
            super.print(text, contentType);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) OpenFileHyperlinkInfo(com.intellij.execution.filters.OpenFileHyperlinkInfo)

Example 2 with OpenFileHyperlinkInfo

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

the class CustomRegexpFilter method createOpenFileHyperlink.

protected HyperlinkInfo createOpenFileHyperlink(String fileName, final int line, int column) {
    if ((fileName == null || fileName.length() == 0)) {
        if (myBase != null) {
            fileName = myBase.getPresentableUrl();
        } else {
            return null;
        }
    }
    fileName = fileName.replace(File.separatorChar, '/');
    VirtualFile file;
    // try to interpret the filename as URL
    if (URLUtil.containsScheme(fileName)) {
        try {
            file = VfsUtil.findFileByURL(new URL(fileName));
        } catch (MalformedURLException e) {
            file = VirtualFileManager.getInstance().findFileByUrl(VfsUtil.pathToUrl(fileName));
        }
    } else {
        file = VfsUtil.findRelativeFile(fileName, myBase);
    }
    if (file == null) {
        //noinspection ConstantConditions
        return null;
    }
    final FileType fileType = file.getFileType();
    if (fileType != null && column > 0) {
        final Document document = FileDocumentManager.getInstance().getDocument(file);
        final int start = document.getLineStartOffset(line);
        final int max = document.getLineEndOffset(line);
        final int tabSize = CodeStyleSettingsManager.getInstance(myProject).getCurrentSettings().getTabSize(fileType);
        column = EditorUtil.calcColumnNumber(null, document.getCharsSequence(), start, Math.min(start + column, max), tabSize);
    }
    return new OpenFileHyperlinkInfo(myProject, file, line, column);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MalformedURLException(java.net.MalformedURLException) OpenFileHyperlinkInfo(com.intellij.execution.filters.OpenFileHyperlinkInfo) FileType(com.intellij.openapi.fileTypes.FileType) Document(com.intellij.openapi.editor.Document) URL(java.net.URL)

Example 3 with OpenFileHyperlinkInfo

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

the class PythonTracebackFilter method applyFilter.

@Override
@Nullable
public final Result applyFilter(@NotNull final String line, final int entireLength) {
    for (final TraceBackParser parser : TraceBackParser.PARSERS) {
        final LinkInTrace linkInTrace = parser.findLinkInTrace(line);
        if (linkInTrace == null) {
            continue;
        }
        final int lineNumber = linkInTrace.getLineNumber();
        final VirtualFile vFile = findFileByName(linkInTrace.getFileName());
        if (vFile != null) {
            final OpenFileHyperlinkInfo hyperlink = new OpenFileHyperlinkInfo(myProject, vFile, lineNumber - 1);
            final int textStartOffset = entireLength - line.length();
            final int startPos = linkInTrace.getStartPos();
            final int endPos = linkInTrace.getEndPos();
            return new Result(startPos + textStartOffset, endPos + textStartOffset, hyperlink);
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) OpenFileHyperlinkInfo(com.intellij.execution.filters.OpenFileHyperlinkInfo) TraceBackParser(com.jetbrains.python.traceBackParsers.TraceBackParser) LinkInTrace(com.jetbrains.python.traceBackParsers.LinkInTrace) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with OpenFileHyperlinkInfo

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

the class XDebugSessionImpl method breakpointReached.

private boolean breakpointReached(@NotNull final XBreakpoint<?> breakpoint, @Nullable String evaluatedLogExpression, @NotNull XSuspendContext suspendContext, boolean doProcessing) {
    if (doProcessing) {
        if (breakpoint.isLogMessage()) {
            XSourcePosition position = breakpoint.getSourcePosition();
            OpenFileHyperlinkInfo hyperlinkInfo = position != null ? new OpenFileHyperlinkInfo(myProject, position.getFile(), position.getLine()) : null;
            printMessage(XDebuggerBundle.message("xbreakpoint.reached.text") + " ", XBreakpointUtil.getShortText(breakpoint), hyperlinkInfo);
        }
        if (evaluatedLogExpression != null) {
            printMessage(evaluatedLogExpression, null, null);
        }
        processDependencies(breakpoint);
        if (breakpoint.getSuspendPolicy() == SuspendPolicy.NONE) {
            return false;
        }
    }
    myActiveNonLineBreakpoint = (!(breakpoint instanceof XLineBreakpoint) || ((XLineBreakpoint) breakpoint).getType().canBeHitInOtherPlaces()) ? breakpoint : null;
    // set this session active on breakpoint, update execution position will be called inside positionReached
    myDebuggerManager.setCurrentSession(this);
    positionReachedInternal(suspendContext, true);
    if (doProcessing && breakpoint instanceof XLineBreakpoint<?> && ((XLineBreakpoint) breakpoint).isTemporary()) {
        handleTemporaryBreakpointHit(breakpoint);
    }
    return true;
}
Also used : OpenFileHyperlinkInfo(com.intellij.execution.filters.OpenFileHyperlinkInfo)

Example 5 with OpenFileHyperlinkInfo

use of com.intellij.execution.filters.OpenFileHyperlinkInfo in project intellij-plugins by JetBrains.

the class DartConsoleFilter method applyFilter.

@Nullable
public Result applyFilter(final String line, final int entireLength) {
    if (line.startsWith(OBSERVATORY_LISTENING_ON + "http://")) {
        return getObservatoryUrlResult(line, entireLength - line.length());
    }
    final DartPositionInfo info = DartPositionInfo.parsePositionInfo(line);
    if (info == null)
        return null;
    final VirtualFile file;
    switch(info.type) {
        case FILE:
            String path = URLUtil.unescapePercentSequences(info.path);
            if (SystemInfo.isWindows) {
                path = StringUtil.trimLeading(path, '/');
            }
            file = LocalFileSystem.getInstance().findFileByPath(path);
            break;
        case DART:
            file = DartUrlResolver.findFileInDartSdkLibFolder(myProject, mySdk, DART_PREFIX + info.path);
            break;
        case PACKAGE:
            if (myDartUrlResolver != null) {
                file = myDartUrlResolver.findFileByDartUrl(PACKAGE_PREFIX + info.path);
            } else {
                if (myAllPubspecYamlFiles == null) {
                    myAllPubspecYamlFiles = FilenameIndex.getVirtualFilesByName(myProject, PUBSPEC_YAML, GlobalSearchScope.projectScope(myProject));
                }
                VirtualFile inPackage = null;
                for (VirtualFile yamlFile : myAllPubspecYamlFiles) {
                    inPackage = DartUrlResolver.getInstance(myProject, yamlFile).findFileByDartUrl(PACKAGE_PREFIX + info.path);
                    if (inPackage != null) {
                        break;
                    }
                }
                file = inPackage;
            }
            break;
        default:
            file = null;
    }
    if (file != null && !file.isDirectory()) {
        final int highlightStartOffset = entireLength - line.length() + info.highlightingStartIndex;
        final int highlightEndOffset = entireLength - line.length() + info.highlightingEndIndex;
        return new Result(highlightStartOffset, highlightEndOffset, new OpenFileHyperlinkInfo(myProject, file, info.line, info.column));
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) OpenFileHyperlinkInfo(com.intellij.execution.filters.OpenFileHyperlinkInfo) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

OpenFileHyperlinkInfo (com.intellij.execution.filters.OpenFileHyperlinkInfo)19 VirtualFile (com.intellij.openapi.vfs.VirtualFile)15 Nullable (org.jetbrains.annotations.Nullable)8 HyperlinkInfo (com.intellij.execution.filters.HyperlinkInfo)5 Matcher (java.util.regex.Matcher)5 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)3 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)2 Nullable (javax.annotation.Nullable)2 NotNull (org.jetbrains.annotations.NotNull)2 JsErrorMessage (com.google.jstestdriver.idea.common.JsErrorMessage)1 Filter (com.intellij.execution.filters.Filter)1 GotoFileCellRenderer (com.intellij.ide.util.gotoByName.GotoFileCellRenderer)1 AccessToken (com.intellij.openapi.application.AccessToken)1 Document (com.intellij.openapi.editor.Document)1 FileEditor (com.intellij.openapi.fileEditor.FileEditor)1 FileEditorManagerImpl (com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl)1 FileType (com.intellij.openapi.fileTypes.FileType)1 Project (com.intellij.openapi.project.Project)1 JBPopup (com.intellij.openapi.ui.popup.JBPopup)1 Ref (com.intellij.openapi.util.Ref)1