Skip to content

Commit 9a6c05e

Browse files
authored
Merge pull request #67 from vilunov/bugfix/regex-quote
Quote project root path in replace regex
2 parents 010c8a8 + 4a70314 commit 9a6c05e

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/main/java/lsifjava/DocumentIndexer.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.lang.annotation.Annotation;
1717
import java.nio.file.Paths;
1818
import java.util.*;
19+
import java.util.regex.Pattern;
1920

2021
public class DocumentIndexer {
2122
private String projectRoot;
@@ -380,10 +381,15 @@ public <T> void visitCtConstructorCall(CtConstructorCall<T> el) {
380381
);
381382
}
382383

384+
private final Pattern projectRootPattern = Pattern.compile("^" + Pattern.quote(projectRoot));
385+
383386
private void emitUse(Range use, Range def, String defPath) {
384387
DocumentIndexer indexer = indexers.get(defPath);
385388

386-
String link = pathname.replaceFirst("^"+projectRoot, ".") + ":" + humanRange(use) + " -> " + defPath.replaceFirst("^"+projectRoot, ".") + ":" + humanRange(def);
389+
String link = projectRootPattern.matcher(pathname).replaceFirst(".") +
390+
":" + humanRange(use) +
391+
" -> " + projectRootPattern.matcher(defPath).replaceFirst(".") +
392+
":" + humanRange(def);
387393

388394
if(verbose)
389395
System.out.println("Linking use to definition: " + link);

0 commit comments

Comments
 (0)