Skip to content

Commit c6f0aca

Browse files
committed
Link references for fields, fixes #431
Previously, scip-java only linked references for method symbols. This commit changes the behavior to additionally include fields so that "find references" for fields shows usages of all implementations of the field (abstract super field and concrete implementations).
1 parent a94daee commit c6f0aca

File tree

6 files changed

+36
-7
lines changed

6 files changed

+36
-7
lines changed

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=1.5.5
1+
sbt.version=1.7.1

scip-java/src/main/scala/com/sourcegraph/scip_java/commands/IndexSemanticdbCommand.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ final case class IndexSemanticdbCommand(
4848
) extends Command {
4949
def sourceroot: Path = AbsolutePath.of(app.env.workingDirectory)
5050
def absoluteTargetroots: List[Path] =
51-
targetroot.map(AbsolutePath.of(_, app.env.workingDirectory))
51+
if (targetroot.isEmpty) List(sourceroot)
52+
else targetroot.map(AbsolutePath.of(_, sourceroot))
53+
5254
def run(): Int = {
5355
val reporter = new ConsoleScipSemanticdbReporter(app)
5456
val outputFilename = output.getFileName.toString
@@ -68,7 +70,7 @@ final case class IndexSemanticdbCommand(
6870
.toList
6971
val options =
7072
new ScipSemanticdbOptions(
71-
targetroot.map(ts => AbsolutePath.of(ts, sourceroot)).asJava,
73+
absoluteTargetroots.asJava,
7274
AbsolutePath.of(output, sourceroot),
7375
sourceroot,
7476
reporter,

scip-semanticdb/src/main/java/com/sourcegraph/scip_semanticdb/ScipSemanticdb.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ private void processTypedDocument(Path path, PackageTable packages) {
131131
Scip.Relationship.newBuilder()
132132
.setSymbol(typedSymbol(overriddenSymbol, overriddenSymbolPkg))
133133
.setIsImplementation(true)
134-
.setIsReference(SemanticdbSymbols.isMethod(info.getSymbol())));
134+
.setIsReference(SemanticdbSymbols.isMethodOrField(info.getSymbol())));
135135
}
136136
if (info.hasSignature()) {
137137
String language =
@@ -284,7 +284,7 @@ private Integer processDocumentUnsafe(
284284

285285
// Overrides
286286
if (symbolInformation.getOverriddenSymbolsCount() > 0
287-
&& SemanticdbSymbols.isMethod(symbolInformation.getSymbol())
287+
&& SemanticdbSymbols.isMethodOrField(symbolInformation.getSymbol())
288288
&& occ.getRole() == Role.DEFINITION) {
289289
List<Integer> overriddenReferenceResultIds =
290290
new ArrayList<>(symbolInformation.getOverriddenSymbolsCount());

semanticdb-java/src/main/java/com/sourcegraph/semanticdb_javac/SemanticdbSymbols.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public static boolean isGlobal(String symbol) {
3535
return !isLocal(symbol);
3636
}
3737

38-
public static boolean isMethod(String symbol) {
39-
return symbol.endsWith(").");
38+
public static boolean isMethodOrField(String symbol) {
39+
return symbol.endsWith(".");
4040
}
4141

4242
/**
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package minimized
2+
3+
trait Issue431 {
4+
val b: Int
5+
}
6+
7+
class Issue431Subclass extends Issue431 {
8+
override val b = 10
9+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package minimized
2+
// ^^^^^^^^^ definition minimized/
3+
4+
trait Issue431 {
5+
// ^^^^^^^^ definition minimized/Issue431# trait Issue431
6+
val b: Int
7+
// ^ definition minimized/Issue431#b. val b: Int
8+
// ^^^ reference scala/Int#
9+
}
10+
11+
class Issue431Subclass extends Issue431 {
12+
// ^^^^^^^^^^^^^^^^ definition minimized/Issue431Subclass# class Issue431Subclass
13+
// definition minimized/Issue431Subclass#`<init>`(). def this()
14+
// ^^^^^^^^ reference minimized/Issue431#
15+
// reference java/lang/Object#`<init>`().
16+
override val b = 10
17+
// ^ definition minimized/Issue431Subclass#b. val b: Int
18+
}

0 commit comments

Comments
 (0)