Skip to content

Commit 36ace4a

Browse files
committed
Prune dead indexer code; drop ZINC/SBT URI scheme
1 parent 5fb810e commit 36ace4a

17 files changed

Lines changed: 56 additions & 280 deletions

File tree

build.sbt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,10 +555,20 @@ lazy val minimizedSettings = List[Def.Setting[_]](
555555
(run / fork) := true,
556556
(Compile / unmanagedSourceDirectories) += minimizedSourceDirectory,
557557
libraryDependencies ++= List("org.projectlombok" % "lombok" % "1.18.22"),
558+
// Fork javac so it receives real file paths instead of sbt's `vf://` virtual-file URIs
559+
// (see the comment on `semanticdbKotlincMinimized` for the long story).
560+
javaHome := Some(file(System.getProperty("java.home"))),
561+
Compile / javacOptions ++=
562+
Seq(
563+
"-J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
564+
"-J--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
565+
"-J--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED",
566+
"-J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
567+
"-J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED"
568+
),
558569
javacOptions +=
559570
List(
560571
s"-Xplugin:semanticdb",
561-
s"-build-tool:sbt",
562572
s"-text:on",
563573
s"-verbose",
564574
s"-sourceroot:${(ThisBuild / baseDirectory).value}",

semanticdb-javac/src/main/java/com/sourcegraph/semanticdb_javac/CompilerRange.java

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ public enum CompilerRange {
3030
*/
3131
FROM_POINT_TO_SYMBOL_NAME,
3232

33-
/**
34-
* Map the compiler (point + 1) position to SemanticDB start and use (point + symbol name length +
35-
* 1) for the SemanticDB end position.
36-
*/
37-
FROM_POINT_TO_SYMBOL_NAME_PLUS_ONE,
38-
3933
/**
4034
* Use text search to find the start of the symbol name and use (found start + symbol name length)
4135
* for the SemanticDB end position.
@@ -46,18 +40,11 @@ public enum CompilerRange {
4640
* Use text search to find the start of the symbol name, using the point position as the starting
4741
* search offset and using (found start + symbol name length) for the SemanticDB end position.
4842
*/
49-
FROM_POINT_WITH_TEXT_SEARCH,
50-
51-
/**
52-
* Use text search to find the start of the symbol name, searching from the end instead of the
53-
* start.
54-
*/
55-
FROM_END_WITH_TEXT_SEARCH;
43+
FROM_POINT_WITH_TEXT_SEARCH;
5644

5745
public boolean isFromPoint() {
5846
switch (this) {
5947
case FROM_POINT_TO_SYMBOL_NAME:
60-
case FROM_POINT_TO_SYMBOL_NAME_PLUS_ONE:
6148
case FROM_POINT_WITH_TEXT_SEARCH:
6249
return true;
6350
default:
@@ -66,36 +53,16 @@ public boolean isFromPoint() {
6653
}
6754

6855
public boolean isFromEndPoint() {
69-
switch (this) {
70-
case FROM_END_TO_SYMBOL_NAME:
71-
case FROM_END_WITH_TEXT_SEARCH:
72-
return true;
73-
default:
74-
return false;
75-
}
56+
return this == FROM_END_TO_SYMBOL_NAME;
7657
}
7758

7859
public boolean isFromTextSearch() {
7960
switch (this) {
8061
case FROM_TEXT_SEARCH:
81-
case FROM_END_WITH_TEXT_SEARCH:
8262
case FROM_POINT_WITH_TEXT_SEARCH:
8363
return true;
8464
default:
8565
return false;
8666
}
8767
}
88-
89-
public boolean isPlusOne() {
90-
switch (this) {
91-
case FROM_POINT_TO_SYMBOL_NAME_PLUS_ONE:
92-
return true;
93-
default:
94-
return false;
95-
}
96-
}
97-
98-
public boolean isFromEnd() {
99-
return this == CompilerRange.FROM_END_WITH_TEXT_SEARCH;
100-
}
10168
}

semanticdb-javac/src/main/java/com/sourcegraph/semanticdb_javac/GlobalSymbolsCache.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.sourcegraph.semanticdb_javac;
22

33
import javax.lang.model.element.Element;
4-
import javax.lang.model.element.ElementKind;
54
import javax.lang.model.element.ExecutableElement;
65
import javax.lang.model.element.TypeElement;
76
import javax.lang.model.element.PackageElement;
@@ -36,12 +35,8 @@ public String semanticdbSymbol(Element sym, LocalSymbolsCache locals) {
3635
return result;
3736
}
3837

39-
public boolean isNone(Element sym) {
40-
return sym == null;
41-
}
42-
4338
private String uncachedSemanticdbSymbol(Element sym, LocalSymbolsCache locals) {
44-
if (isNone(sym)) return SemanticdbSymbols.ROOT_PACKAGE;
39+
if (sym == null) return SemanticdbSymbols.ROOT_PACKAGE;
4540

4641
if (sym instanceof PackageElement) {
4742
if (((PackageElement) sym).isUnnamed()) return SemanticdbSymbols.ROOT_PACKAGE;

semanticdb-javac/src/main/java/com/sourcegraph/semanticdb_javac/MD5.java

Lines changed: 0 additions & 32 deletions
This file was deleted.

semanticdb-javac/src/main/java/com/sourcegraph/semanticdb_javac/RangeFinder.java

Lines changed: 15 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import javax.tools.Diagnostic;
44

5-
import javax.lang.model.element.Element;
65
import java.util.Optional;
76

87
public class RangeFinder {
@@ -16,81 +15,30 @@ public static class StartEndRange {
1615
}
1716
}
1817

18+
/**
19+
* Searches {@code source} for {@code name} starting at {@code start}. If the name cannot be found
20+
* and {@code fallback} is not {@link Diagnostic#NOPOS}, returns a range anchored at {@code
21+
* fallback}; otherwise returns {@link Optional#empty()}.
22+
*/
1923
public static Optional<StartEndRange> findRange(
20-
Element element,
21-
String name,
22-
int originalStartPos,
23-
int originalEndPos,
24-
String source,
25-
boolean fromEnd) {
26-
int startPos = findNameIn(name, originalStartPos, originalEndPos, element, source, fromEnd);
27-
int endPos = startPos + name.length();
28-
29-
if (endPos == -1 || startPos == -1) {
30-
return Optional.empty();
31-
}
32-
33-
return Optional.of(new StartEndRange(startPos, endPos));
34-
}
35-
36-
private static int findNameFromEnd(
37-
String name,
38-
int originalStartPos,
39-
int originalEndPos,
40-
int end,
41-
Element element,
42-
String source) {
43-
if (end < 0) return -1;
44-
int offset = source.lastIndexOf(name, end);
45-
if (offset == -1 && originalStartPos != Diagnostic.NOPOS && originalEndPos != Diagnostic.NOPOS)
46-
return originalStartPos;
47-
if (offset == -1) {
48-
return -1;
49-
}
50-
int endOfWord = offset + name.length();
51-
// found name in wrong word? e.g. finding `"A"` in `A("A")`
52-
if (offset > 0 && Character.isJavaIdentifierPart(source.charAt(offset - 1)))
53-
return findNameFromEnd(name, originalStartPos, originalEndPos, offset - 1, element, source);
54-
if (endOfWord < source.length() && Character.isJavaIdentifierPart(source.charAt(endOfWord)))
55-
return findNameFromEnd(name, originalStartPos, originalEndPos, offset - 1, element, source);
56-
57-
return offset;
24+
String name, int start, int fallback, String source) {
25+
if (source.length() == 0) return Optional.empty();
26+
int startPos = findNameFromStart(name, start, fallback, source);
27+
if (startPos == -1) return Optional.empty();
28+
return Optional.of(new StartEndRange(startPos, startPos + name.length()));
5829
}
5930

60-
private static int findNameFromStart(
61-
String name,
62-
int start,
63-
int originalStartPos,
64-
int originalEndPos,
65-
Element element,
66-
String source) {
31+
private static int findNameFromStart(String name, int start, int fallback, String source) {
6732
if (start >= source.length()) return -1;
6833
int offset = source.indexOf(name, start);
69-
if (offset == -1 && originalStartPos != Diagnostic.NOPOS && originalEndPos != Diagnostic.NOPOS)
70-
return originalStartPos;
71-
if (offset == -1) {
72-
return -1;
73-
}
34+
if (offset == -1 && fallback != Diagnostic.NOPOS) return fallback;
35+
if (offset == -1) return -1;
7436
int end = offset + name.length();
7537
// found name in wrong word? e.g. finding `"A"` in `A("A")`
7638
if (offset > 0 && Character.isJavaIdentifierPart(source.charAt(offset - 1)))
77-
return findNameFromStart(name, end + 1, originalStartPos, originalEndPos, element, source);
39+
return findNameFromStart(name, end + 1, fallback, source);
7840
if (end < source.length() && Character.isJavaIdentifierPart(source.charAt(end)))
79-
return findNameFromStart(name, end + 1, originalStartPos, originalEndPos, element, source);
80-
41+
return findNameFromStart(name, end + 1, fallback, source);
8142
return offset;
8243
}
83-
84-
private static int findNameIn(
85-
String name, int start, int end, Element element, String source, boolean fromEnd) {
86-
if (source.length() == 0) return -1;
87-
88-
int offset;
89-
if (fromEnd) offset = findNameFromEnd(name, start, start, end, element, source);
90-
else offset = findNameFromStart(name, start, end, end, element, source);
91-
if (offset > -1) {
92-
return offset;
93-
}
94-
return -1;
95-
}
9644
}

semanticdb-javac/src/main/java/com/sourcegraph/semanticdb_javac/Result.java

Lines changed: 3 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.sourcegraph.semanticdb_javac;
22

33
import java.util.NoSuchElementException;
4-
import java.util.Objects;
5-
import java.util.function.Function;
64

75
/**
86
* A Java implementation of Rust's <code>Result[T, E]</code> type, or Scala's <code>Either[A, B]
@@ -17,7 +15,7 @@ private enum Kind {
1715
Error;
1816
}
1917

20-
private Kind kind;
18+
private final Kind kind;
2119
private final T ok;
2220
private final E error;
2321

@@ -31,69 +29,23 @@ private Result(Kind kind, T ok, E error) {
3129
this.ok = ok;
3230
}
3331

34-
@Override
35-
public boolean equals(Object o) {
36-
if (this == o) return true;
37-
if (o == null || getClass() != o.getClass()) return false;
38-
Result<?, ?> result = (Result<?, ?>) o;
39-
return kind == result.kind
40-
&& Objects.equals(error, result.error)
41-
&& Objects.equals(ok, result.ok);
42-
}
43-
44-
@Override
45-
public int hashCode() {
46-
return Objects.hash(kind, error, ok);
47-
}
48-
49-
@Override
50-
public String toString() {
51-
switch (kind) {
52-
case Ok:
53-
return "Error(" + error + ")";
54-
case Error:
55-
return "Ok(" + ok + ")";
56-
default:
57-
return "Result{" + "kind=" + kind + ", error=" + error + ", ok=" + ok + '}';
58-
}
59-
}
60-
61-
public <C> C fold(Function<T, C> onOk, Function<E, C> onError) {
62-
switch (kind) {
63-
case Ok:
64-
return onOk.apply(ok);
65-
case Error:
66-
return onError.apply(error);
67-
default:
68-
throw new IllegalArgumentException(this.toString());
69-
}
70-
}
71-
72-
public <C> Result<C, E> map(Function<T, C> fn) {
73-
return this.fold(left -> Result.ok(fn.apply(left)), Result::error);
74-
}
75-
7632
public boolean isOk() {
7733
return kind == Kind.Ok;
7834
}
7935

80-
public boolean isError() {
81-
return kind == Kind.Error;
82-
}
83-
8436
public T getOrThrow() {
8537
if (kind == Kind.Ok) {
8638
return ok;
8739
} else {
88-
throw new NoSuchElementException("no left value on " + this.toString());
40+
throw new NoSuchElementException("no ok value on Result.Error(" + error + ")");
8941
}
9042
}
9143

9244
public E getErrorOrThrow() {
9345
if (kind == Kind.Error) {
9446
return error;
9547
} else {
96-
throw new NoSuchElementException("no left value on " + this.toString());
48+
throw new NoSuchElementException("no error value on Result.Ok(" + ok + ")");
9749
}
9850
}
9951

semanticdb-javac/src/main/java/com/sourcegraph/semanticdb_javac/ScipShardWriter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import org.scip_code.scip.Document;
44
import org.scip_code.scip.Index;
5-
import org.scip_code.scip.Occurrence;
65
import org.scip_code.scip.Relationship;
76
import org.scip_code.scip.SymbolInformation;
87

semanticdb-javac/src/main/java/com/sourcegraph/semanticdb_javac/ScipVisitor.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ private static SymbolInformation.Kind scipKind(Element sym) {
289289
}
290290

291291
// ===========================================
292-
// Node resolution and traversal (unchanged from SemanticdbVisitor)
292+
// Node resolution and traversal
293293
// ===========================================
294294

295295
void resolveNodes() {
@@ -490,12 +490,11 @@ private Optional<ScipRange> scipRangeOf(Tree tree, CompilerRange kind, Element s
490490
SourcePositions sourcePositions = trees.getSourcePositions();
491491
int start = (int) sourcePositions.getStartPosition(compUnitTree, tree);
492492
int end = (int) sourcePositions.getEndPosition(compUnitTree, tree);
493-
if (kind.isPlusOne()) start++;
494493

495494
if (name != null) {
496495
if (kind.isFromTextSearch() && name.length() > 0) {
497496
Optional<RangeFinder.StartEndRange> startEndRange =
498-
RangeFinder.findRange(sym, name, start, end, this.source, kind.isFromEnd());
497+
RangeFinder.findRange(name, start, end, this.source);
499498
if (startEndRange.isPresent()) {
500499
start = startEndRange.get().start;
501500
end = startEndRange.get().end;

0 commit comments

Comments
 (0)