Search in sources :

Example 16 with OpenFileHyperlinkInfo

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

the class StackFrameList method navigateToFrame.

private void navigateToFrame(@NotNull XStackFrame frame, boolean focusOnEditor) {
    XSourcePosition position = frame.getSourcePosition();
    if (position == null)
        return;
    VirtualFile file = position.getFile();
    int line = position.getLine();
    Project project = myDebugProcess.getProject();
    OpenFileHyperlinkInfo info = new OpenFileHyperlinkInfo(project, file, line);
    OpenFileDescriptor descriptor = info.getDescriptor();
    if (descriptor != null) {
        FileEditorManagerImpl manager = (FileEditorManagerImpl) FileEditorManager.getInstance(project);
        VirtualFile lastFile = myEditorState.myLastOpenedFile;
        if (myEditorState.myIsNeedToCloseLastOpenedFile && lastFile != null && manager.isFileOpen(lastFile) && !lastFile.equals(descriptor.getFile())) {
            manager.closeFile(myEditorState.myLastOpenedFile, false, true);
        }
        descriptor.setScrollType(ScrollType.CENTER);
        descriptor.setUseCurrentWindow(true);
        if (lastFile == null || !lastFile.equals(descriptor.getFile())) {
            myEditorState.myIsNeedToCloseLastOpenedFile = !manager.isFileOpen(descriptor.getFile());
        }
        descriptor.navigateInEditor(project, focusOnEditor);
        FileEditor[] editors = manager.getEditors(descriptor.getFile());
        if (editors.length != 0) {
            myEditorState.myLastOpenedFile = descriptor.getFile();
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) OpenFileHyperlinkInfo(com.intellij.execution.filters.OpenFileHyperlinkInfo) FileEditor(com.intellij.openapi.fileEditor.FileEditor) FileEditorManagerImpl(com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) XSourcePosition(com.intellij.xdebugger.XSourcePosition)

Example 17 with OpenFileHyperlinkInfo

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

the class FlutterConsoleFilter method applyFilter.

@Nullable
public Result applyFilter(final String line, final int entireLength) {
    if (line.startsWith("Run \"flutter doctor\" for information about installing additional components.")) {
        return getFlutterDoctorResult(line, entireLength - line.length());
    }
    // Check for "restart" action in debugging output.
    if (line.startsWith("you may need to restart the app")) {
        return getRestartAppResult(line, entireLength - line.length());
    }
    int lineNumber = 0;
    String pathPart = line.trim();
    // * "open ios/Runner.xcworkspace"
    if (line.startsWith("Launching ") || (line.startsWith("open "))) {
        final String[] parts = line.split(" ");
        if (parts.length > 1) {
            pathPart = parts[1];
        }
    }
    // Check for embedded paths, e.g.,
    // * "  • MyApp.xzzzz (lib/main.dart:6)"
    // * "  • _MyHomePageState._incrementCounter (lib/main.dart:49)"
    final String[] parts = pathPart.split(" ");
    for (String part : parts) {
        // "(lib/main.dart:49)"
        if (part.startsWith("(") && pathPart.endsWith(")")) {
            part = part.substring(1, part.length() - 1);
            final String[] split = part.split(":");
            if (split.length == 2) {
                try {
                    // Reconcile line number indexing.
                    lineNumber = Math.max(0, Integer.parseInt(split[1]) - 1);
                } catch (NumberFormatException e) {
                // Ignored.
                }
            }
            pathPart = part;
        }
    }
    final VirtualFile file = fileAtPath(pathPart);
    if (file != null) {
        // "open ios/Runner.xcworkspace"
        final boolean openAsExternalFile = FlutterUtils.isXcodeFileName(pathPart);
        final int lineStart = entireLength - line.length() + line.indexOf(pathPart);
        final HyperlinkInfo hyperlinkInfo = openAsExternalFile ? new OpenExternalFileHyperlink(file) : new OpenFileHyperlinkInfo(module.getProject(), file, lineNumber, 0);
        return new Result(lineStart, lineStart + pathPart.length(), hyperlinkInfo);
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) OpenFileHyperlinkInfo(com.intellij.execution.filters.OpenFileHyperlinkInfo) HyperlinkInfo(com.intellij.execution.filters.HyperlinkInfo) OpenFileHyperlinkInfo(com.intellij.execution.filters.OpenFileHyperlinkInfo) Nullable(org.jetbrains.annotations.Nullable)

Example 18 with OpenFileHyperlinkInfo

use of com.intellij.execution.filters.OpenFileHyperlinkInfo 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);
    Result result = null;
    if (matcher.find()) {
        String filePath = matcher.group(myFileMatchGroup);
        Collection<VirtualFile> virtualFileCollection = resolveVirtualFileCollection(filePath);
        if (virtualFileCollection.size() > 0) {
            List<ResultItem> resultItemList = new ArrayList<>(virtualFileCollection.size());
            int highlightStartOffset = entireLength - line.length() + matcher.start(1);
            int highlightEndOffset = highlightStartOffset + matcher.end(matcher.groupCount()) - matcher.start(1);
            int fileLine = matchGroupToNumber(matcher, myLineMatchGroup);
            int fileColumn = matchGroupToNumber(matcher, myColumnMatchGroup);
            for (VirtualFile virtualFile : virtualFileCollection) {
                resultItemList.add(new ResultItem(highlightStartOffset, highlightEndOffset, new OpenFileHyperlinkInfo(myProject, virtualFile, fileLine, fileColumn)));
            }
            result = new Result(resultItemList);
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) OpenFileHyperlinkInfo(com.intellij.execution.filters.OpenFileHyperlinkInfo) Matcher(java.util.regex.Matcher) Nullable(org.jetbrains.annotations.Nullable)

Example 19 with OpenFileHyperlinkInfo

use of com.intellij.execution.filters.OpenFileHyperlinkInfo in project intellij by bazelbuild.

the class BlazeCppPathConsoleFilter method applyFilter.

@Nullable
@Override
public Result applyFilter(String line, int entireLength) {
    Matcher matcher = PATTERN.matcher(line);
    if (!matcher.find()) {
        return null;
    }
    String filePath = matcher.group(1);
    if (filePath == null) {
        return null;
    }
    VirtualFile file = resolveFile(filePath);
    if (file == null) {
        return null;
    }
    int lineNumber = parseLineNumber(matcher.group(2));
    OpenFileHyperlinkInfo hyperlink = new OpenFileHyperlinkInfo(project, file, lineNumber - 1);
    int offset = entireLength - line.length();
    return new Result(matcher.start() + offset, matcher.end() + offset, hyperlink);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) OpenFileHyperlinkInfo(com.intellij.execution.filters.OpenFileHyperlinkInfo) Matcher(java.util.regex.Matcher) Nullable(javax.annotation.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