node: support file:// links with :line:column at the end (WEB-35908)

GitOrigin-RevId: 3afb58e000f3f82baf981f4d77b8c30ca7d66e05
This commit is contained in:
Sergey Simonchik
2019-08-01 21:02:48 +03:00
committed by intellij-monorepo-bot
parent 51dee91235
commit 3b20bd1ee3
@@ -21,6 +21,7 @@ import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.util.io.URLUtil;
import org.jetbrains.annotations.NotNull;
@@ -35,7 +36,6 @@ import java.util.regex.Pattern;
* @author yole
*/
public class UrlFilter implements Filter, DumbAware {
private static final String FILE_URL_PROTOCOL = "file://";
private final Project myProject;
public UrlFilter() {
@@ -52,7 +52,7 @@ public class UrlFilter implements Filter, DumbAware {
if (!URLUtil.canContainUrl(line)) return null;
int textStartOffset = entireLength - line.length();
Pattern pattern = line.contains(URLUtil.FILE_PROTOCOL + URLUtil.SCHEME_SEPARATOR) ? URLUtil.FILE_URL_PATTERN : URLUtil.URL_PATTERN;
Pattern pattern = line.contains(LocalFileSystem.PROTOCOL_PREFIX) ? URLUtil.FILE_URL_PATTERN : URLUtil.URL_PATTERN;
Matcher m = pattern.matcher(line);
ResultItem item = null;
List<ResultItem> items = null;
@@ -80,8 +80,28 @@ public class UrlFilter implements Filter, DumbAware {
@Nullable
private HyperlinkInfo buildFileHyperlinkInfo(@NotNull String url) {
if (myProject != null && url.startsWith(FILE_URL_PROTOCOL)) {
return new LazyFileHyperlinkInfo(myProject, StringUtil.trimStart(url, FILE_URL_PROTOCOL), 0, 0) {
if (myProject != null && url.startsWith(LocalFileSystem.PROTOCOL_PREFIX)) {
int documentLine = 0, documentColumn = 0;
int filePathEndIndex = url.length();
final int lastColonInd = url.lastIndexOf(':');
if (lastColonInd > LocalFileSystem.PROTOCOL_PREFIX.length() && lastColonInd < url.length() - 1) {
int lastValue = StringUtil.parseInt(url.substring(lastColonInd + 1), Integer.MIN_VALUE);
if (lastValue != Integer.MIN_VALUE) {
documentLine = lastValue - 1;
filePathEndIndex = lastColonInd;
int preLastColonInd = url.lastIndexOf(':', lastColonInd - 1);
if (preLastColonInd > LocalFileSystem.PROTOCOL_PREFIX.length()) {
int preLastValue = StringUtil.parseInt(url.substring(preLastColonInd + 1, lastColonInd), Integer.MIN_VALUE);
if (preLastValue != Integer.MIN_VALUE) {
documentLine = preLastValue - 1;
documentColumn = lastValue - 1;
filePathEndIndex = preLastColonInd;
}
}
}
}
String filePath = url.substring(LocalFileSystem.PROTOCOL_PREFIX.length(), filePathEndIndex);
return new LazyFileHyperlinkInfo(myProject, filePath, documentLine, documentColumn) {
@Nullable
@Override
public OpenFileDescriptor getDescriptor() {