Search in sources :

Example 1 with HyperlinkInfo

use of com.intellij.execution.filters.HyperlinkInfo in project buck by facebook.

the class BuckBuildManager method showNoTargetMessage.

/**
   * Print "no selected target" error message to console window.
   * Also provide a hyperlink which can directly jump to "Choose Target" GUI window.
   */
public void showNoTargetMessage(Project project) {
    BuckModule buckModule = project.getComponent(BuckModule.class);
    buckModule.getBuckEventsConsumer().consumeConsoleEvent("Please choose a build target!");
    BuckToolWindowFactory.outputConsoleMessage(project, "Please ", ConsoleViewContentType.ERROR_OUTPUT);
    BuckToolWindowFactory.outputConsoleHyperlink(project, "choose a build target!\n", new HyperlinkInfo() {

        @Override
        public void navigate(Project project) {
            JComponent frame = WindowManager.getInstance().getIdeFrame(project).getComponent();
            AnAction action = ActionManager.getInstance().getAction("buck.ChooseTarget");
            action.actionPerformed(new AnActionEvent(null, DataManager.getInstance().getDataContext(frame), ActionPlaces.UNKNOWN, action.getTemplatePresentation(), ActionManager.getInstance(), 0));
        }
    });
}
Also used : Project(com.intellij.openapi.project.Project) BuckModule(com.facebook.buck.intellij.ideabuck.config.BuckModule) JComponent(javax.swing.JComponent) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) HyperlinkInfo(com.intellij.execution.filters.HyperlinkInfo)

Example 2 with HyperlinkInfo

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

the class GoConsoleFilterTest method doFileLineTest.

private void doFileLineTest(@NotNull String line, int startOffset, int endOffset, String targetPath, int targetLine, int targetColumn) {
    Filter.Result result = myFilter.applyFilter(line, line.length());
    assertNotNull(result);
    HyperlinkInfo info = assertResultAndGetHyperlink(result, startOffset, endOffset);
    assertInstanceOf(info, OpenFileHyperlinkInfo.class);
    OpenFileDescriptor fileDescriptor = ((OpenFileHyperlinkInfo) info).getDescriptor();
    assertNotNull(fileDescriptor);
    assertEquals(targetPath, fileDescriptor.getFile().getPath());
    assertEquals("line", targetLine, fileDescriptor.getLine() + 1);
    assertEquals("column", targetColumn, fileDescriptor.getColumn() + 1);
}
Also used : OpenFileHyperlinkInfo(com.intellij.execution.filters.OpenFileHyperlinkInfo) Filter(com.intellij.execution.filters.Filter) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) HyperlinkInfo(com.intellij.execution.filters.HyperlinkInfo) OpenFileHyperlinkInfo(com.intellij.execution.filters.OpenFileHyperlinkInfo)

Example 3 with HyperlinkInfo

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

the class GoConsoleFilter method applyFilter.

@Override
public Result applyFilter(@NotNull String line, int entireLength) {
    Matcher goGetMatcher = GO_GET_MESSAGE_PATTERN.matcher(line);
    if (goGetMatcher.find() && myModule != null) {
        String packageName = goGetMatcher.group(2).trim();
        HyperlinkInfo hyperlinkInfo = new GoGetHyperlinkInfo(packageName, myModule);
        int lineStart = entireLength - line.length();
        return new Result(lineStart + goGetMatcher.start(1), lineStart + goGetMatcher.end(2), hyperlinkInfo);
    }
    Matcher matcher = MESSAGE_PATTERN.matcher(line);
    if (!matcher.find()) {
        Matcher fileMatcher = GO_FILE_PATTERN.matcher(line);
        List<ResultItem> resultItems = ContainerUtil.newArrayList();
        while (fileMatcher.find()) {
            VirtualFile file = findSingleFile(fileMatcher.group(1));
            if (file != null) {
                resultItems.add(createResult(line, entireLength, fileMatcher.start(1), fileMatcher.end(1), 0, 0, file));
            }
        }
        return !resultItems.isEmpty() ? new Result(resultItems) : null;
    }
    int startOffset = matcher.start(1);
    int endOffset = matcher.end(2);
    String fileName = matcher.group(1);
    int lineNumber = StringUtil.parseInt(matcher.group(2), 1) - 1;
    if (lineNumber < 0) {
        return null;
    }
    int columnNumber = -1;
    if (matcher.groupCount() > 3) {
        columnNumber = StringUtil.parseInt(matcher.group(4), 1) - 1;
        endOffset = Math.max(endOffset, matcher.end(4));
    }
    Matcher appEnginePathMatcher = APP_ENGINE_PATH_PATTERN.matcher(fileName);
    if (appEnginePathMatcher.find()) {
        fileName = fileName.substring(appEnginePathMatcher.end());
    }
    VirtualFile virtualFile = null;
    if (FileUtil.isAbsolutePlatformIndependent(fileName)) {
        virtualFile = ApplicationManager.getApplication().isUnitTestMode() ? TempFileSystem.getInstance().refreshAndFindFileByPath(fileName) : VirtualFileManager.getInstance().refreshAndFindFileByUrl(VfsUtilCore.pathToUrl(fileName));
    } else {
        if (myWorkingDirectoryUrl != null) {
            virtualFile = VirtualFileManager.getInstance().refreshAndFindFileByUrl(myWorkingDirectoryUrl + "/" + fileName);
        }
        if (virtualFile == null && myModule != null) {
            virtualFile = findInGoPath(fileName);
            if (virtualFile == null && fileName.startsWith("src/")) {
                virtualFile = findInGoPath(StringUtil.trimStart(fileName, "src/"));
            }
        }
        if (virtualFile == null) {
            VirtualFile baseDir = myProject.getBaseDir();
            if (baseDir != null) {
                virtualFile = baseDir.findFileByRelativePath(fileName);
                if (virtualFile == null && fileName.startsWith("src/")) {
                    // exclude src
                    virtualFile = baseDir.findFileByRelativePath(StringUtil.trimStart(fileName, "src/"));
                }
            }
        }
    }
    if (virtualFile == null) {
        virtualFile = findSingleFile(fileName);
    }
    if (virtualFile == null) {
        return null;
    }
    return createResult(line, entireLength, startOffset, endOffset, lineNumber, columnNumber, virtualFile);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Matcher(java.util.regex.Matcher) OpenFileHyperlinkInfo(com.intellij.execution.filters.OpenFileHyperlinkInfo) HyperlinkInfo(com.intellij.execution.filters.HyperlinkInfo)

Example 4 with HyperlinkInfo

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

the class GoConsoleFilter method createResult.

@NotNull
private Result createResult(@NotNull String line, int entireLength, int startOffset, int endOffset, int lineNumber, int columnNumber, @NotNull VirtualFile virtualFile) {
    HyperlinkInfo hyperlinkInfo = new OpenFileHyperlinkInfo(myProject, virtualFile, lineNumber, columnNumber);
    int lineStart = entireLength - line.length();
    return new Result(lineStart + startOffset, lineStart + endOffset, hyperlinkInfo);
}
Also used : OpenFileHyperlinkInfo(com.intellij.execution.filters.OpenFileHyperlinkInfo) OpenFileHyperlinkInfo(com.intellij.execution.filters.OpenFileHyperlinkInfo) HyperlinkInfo(com.intellij.execution.filters.HyperlinkInfo) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with HyperlinkInfo

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

the class AnnotateStackTraceAction method getHyperlinkVirtualFile.

@Nullable
@CalledWithReadLock
private static VirtualFile getHyperlinkVirtualFile(@NotNull List<RangeHighlighter> links) {
    RangeHighlighter key = ContainerUtil.getLastItem(links);
    if (key == null)
        return null;
    HyperlinkInfo info = EditorHyperlinkSupport.getHyperlinkInfo(key);
    if (!(info instanceof FileHyperlinkInfo))
        return null;
    OpenFileDescriptor descriptor = ((FileHyperlinkInfo) info).getDescriptor();
    return descriptor != null ? descriptor.getFile() : null;
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) FileHyperlinkInfo(com.intellij.execution.filters.FileHyperlinkInfo) FileHyperlinkInfo(com.intellij.execution.filters.FileHyperlinkInfo) HyperlinkInfo(com.intellij.execution.filters.HyperlinkInfo) CalledWithReadLock(org.jetbrains.annotations.CalledWithReadLock) Nullable(org.jetbrains.annotations.Nullable)

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