use of com.intellij.execution.filters.OpenFileHyperlinkInfo in project intellij-plugins by JetBrains.
the class DartRelativePathsConsoleFilter method applyFilter.
@Nullable
public Result applyFilter(final String text, final int entireLength) {
final String trimmedText = StringUtil.trimLeading(text);
final Trinity<String, Integer, Integer> fileRelPathLineAndColumn = getFileRelPathLineAndColumn(trimmedText);
if (fileRelPathLineAndColumn == null)
return null;
final String fileRelPath = fileRelPathLineAndColumn.first;
final int line = fileRelPathLineAndColumn.second;
final int column = fileRelPathLineAndColumn.third;
final VirtualFile file = LocalFileSystem.getInstance().findFileByPath(myBaseDirPath + "/" + trimmedText.substring(0, fileRelPath.length()));
if (file == null || file.isDirectory())
return null;
return new Result(entireLength - trimmedText.length(), entireLength - trimmedText.length() + fileRelPath.length(), new OpenFileHyperlinkInfo(myProject, file, line, column));
}
use of com.intellij.execution.filters.OpenFileHyperlinkInfo in project intellij-plugins by JetBrains.
the class JsErrorFilter method applyFilter.
@Nullable
@Override
public Result applyFilter(String line, int entireLength) {
JsErrorMessage message;
try {
message = JsErrorMessage.parseFromText(line, myBasePath);
} catch (Exception e) {
LOG.error("Can't parse error message from '" + line + "'", e);
return null;
}
if (message == null) {
return null;
}
VirtualFile virtualFile = VfsUtil.findFileByIoFile(message.getFileWithError(), false);
if (virtualFile == null || !virtualFile.isValid()) {
return null;
}
int column = ObjectUtils.notNull(message.getColumnNumber(), 0);
HyperlinkInfo hyperlinkInfo = new OpenFileHyperlinkInfo(myProject, virtualFile, message.getLineNumber() - 1, column);
return new Filter.Result(message.getHyperlinkStartInclusiveInd(), message.getHyperlinkEndExclusiveInd(), hyperlinkInfo);
}
use of com.intellij.execution.filters.OpenFileHyperlinkInfo in project intellij-community by JetBrains.
the class MultipleFilesHyperlinkInfo method navigate.
@Override
public void navigate(@NotNull final Project project, @Nullable RelativePoint hyperlinkLocationPoint) {
List<PsiFile> currentFiles = new ArrayList<>();
AccessToken accessToken = ReadAction.start();
try {
for (VirtualFile file : myVirtualFiles) {
if (!file.isValid())
continue;
PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
if (psiFile != null) {
// Sources may be downloaded.
PsiElement navigationElement = psiFile.getNavigationElement();
if (navigationElement instanceof PsiFile) {
currentFiles.add((PsiFile) navigationElement);
continue;
}
currentFiles.add(psiFile);
}
}
} finally {
accessToken.finish();
}
if (currentFiles.isEmpty())
return;
if (currentFiles.size() == 1) {
new OpenFileHyperlinkInfo(myProject, currentFiles.get(0).getVirtualFile(), myLineNumber).navigate(project);
} else {
final JBList list = new JBList(currentFiles);
int width = WindowManager.getInstance().getFrame(project).getSize().width;
list.setCellRenderer(new GotoFileCellRenderer(width));
JBPopup popup = JBPopupFactory.getInstance().createListPopupBuilder(list).setTitle("Choose Target File").setItemChoosenCallback(() -> {
VirtualFile file = ((PsiFile) list.getSelectedValue()).getVirtualFile();
new OpenFileHyperlinkInfo(myProject, file, myLineNumber).navigate(project);
}).createPopup();
if (hyperlinkLocationPoint != null) {
popup.show(hyperlinkLocationPoint);
} else {
popup.showInFocusCenter();
}
}
}
use of com.intellij.execution.filters.OpenFileHyperlinkInfo in project intellij-community by JetBrains.
the class AbstractMavenConsoleFilter method applyFilter.
@Nullable
@Override
public Result applyFilter(String line, int entireLength) {
if (!lightCheck(line))
return null;
Matcher matcher = myPattern.matcher(line);
if (!matcher.matches())
return null;
String path = matcher.group(1);
VirtualFile file = LocalFileSystem.getInstance().findFileByPath(path);
if (file == null) {
if (SystemInfo.isWindows && path.matches("/[A-Z]:/.+")) {
file = LocalFileSystem.getInstance().findFileByPath(path.substring(1));
}
if (file == null)
return null;
}
int lineNumber = Integer.parseInt(matcher.group(2)) - 1;
if (lineNumber < 0) {
lineNumber = -1;
}
TextAttributes attr = createCompilationErrorAttr();
return new Result(entireLength - line.length() + matcher.start(1), entireLength - line.length() + matcher.end(1), new OpenFileHyperlinkInfo(myProject, file, lineNumber), attr);
}
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();
}
}
}
Aggregations