*/
package com.intellij.execution.filters;
+import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ProjectFileIndex;
-import com.intellij.openapi.vfs.LocalFileSystem;
+import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import org.jetbrains.io.LocalFileFinder;
-import java.io.File;
import java.util.List;
public abstract class AbstractFileHyperlinkFilter implements Filter {
private final Project myProject;
private final ProjectFileIndex myFileIndex;
- private final String myBaseDir;
+ private final VirtualFile myBaseDir;
public AbstractFileHyperlinkFilter(@NotNull Project project, @Nullable String baseDir) {
myProject = project;
myFileIndex = ProjectFileIndex.SERVICE.getInstance(project);
- myBaseDir = baseDir;
+ myBaseDir = findDir(baseDir);
+ }
+
+ @Nullable
+ private static VirtualFile findDir(@Nullable String baseDir) {
+ if (baseDir == null) {
+ return null;
+ }
+ return ReadAction.compute(() -> {
+ String path = FileUtil.toSystemIndependentName(baseDir);
+ VirtualFile dir = LocalFileFinder.findFile(path);
+ return dir != null && dir.isValid() && dir.isDirectory() ? dir : null;
+ });
}
@Nullable
}
List<Filter.ResultItem> items = ContainerUtil.newArrayList();
for (FileHyperlinkRawData link : links) {
- VirtualFile file = findFile(link.getFilePath());
+ VirtualFile file = findFile(FileUtil.toSystemIndependentName(link.getFilePath()));
if (file != null) {
OpenFileHyperlinkInfo info = new OpenFileHyperlinkInfo(myProject,
file,
link.getDocumentLine(),
link.getDocumentColumn());
boolean grayedHyperLink = isGrayedHyperlink(file);
- items.add(new Filter.ResultItem(link.getHyperlinkStartInd(), link.getHyperlinkEndInd(), info, grayedHyperLink));
+ int offset = entireLength - line.length();
+ items.add(new Filter.ResultItem(offset + link.getHyperlinkStartInd(),
+ offset + link.getHyperlinkEndInd(),
+ info,
+ grayedHyperLink));
}
}
return items.isEmpty() ? null : new Result(items);
@Nullable
public VirtualFile findFile(@NotNull String filePath) {
- File file = findIoFile(filePath);
- if (file != null) {
- return LocalFileSystem.getInstance().findFileByIoFile(file);
- }
- return null;
- }
-
- @Nullable
- private File findIoFile(@NotNull String filePath) {
- File file = new File(filePath);
- if (file.isFile() && file.isAbsolute()) {
- return file;
- }
- if (myBaseDir != null) {
- file = new File(myBaseDir, filePath);
- if (file.isFile()) {
- return file;
- }
+ VirtualFile file = LocalFileFinder.findFile(filePath);
+ if (file == null && myBaseDir != null) {
+ file = myBaseDir.findFileByRelativePath(filePath);
}
- return null;
+ return file;
}
}
boolean hyperlinkFreezed = false;
for (int i = 1; i <= groupCount; i++) {
String value = matcher.group(i);
+ if (value == null) {
+ continue;
+ }
PatternHyperlinkPart part = linkParts[i - 1];
if (part == PatternHyperlinkPart.HYPERLINK) {
hyperlinkStartInd = matcher.start(i);
else if (part == PatternHyperlinkPart.COLUMN) {
value = StringUtil.trimStart(value, ":");
columnNumber = StringUtil.parseInt(value, UNKNOWN);
- hyperlinkEndInd = tryExtendHyperlinkEnd(hyperlinkFreezed, hyperlinkEndInd, matcher.start(i), matcher.end(i));
+ if (columnNumber != UNKNOWN) {
+ hyperlinkEndInd = tryExtendHyperlinkEnd(hyperlinkFreezed, hyperlinkEndInd, matcher.start(i), matcher.end(i));
+ }
}
}
if (path == null || lineNumber == UNKNOWN || hyperlinkStartInd == -1) {