Skip to content

Commit cf77817

Browse files
committed
Link references for fields, fixes #413
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 cf77817

File tree

6 files changed

+38
-7
lines changed

6 files changed

+38
-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: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ 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)
52+
List(sourceroot)
53+
else
54+
targetroot.map(AbsolutePath.of(_, sourceroot))
55+
5256
def run(): Int = {
5357
val reporter = new ConsoleScipSemanticdbReporter(app)
5458
val outputFilename = output.getFileName.toString
@@ -68,7 +72,7 @@ final case class IndexSemanticdbCommand(
6872
.toList
6973
val options =
7074
new ScipSemanticdbOptions(
71-
targetroot.map(ts => AbsolutePath.of(ts, sourceroot)).asJava,
75+
absoluteTargetroots.asJava,
7276
AbsolutePath.of(output, sourceroot),
7377
sourceroot,
7478
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 Issue413 {
4+
val b: Int
5+
}
6+
7+
class Issue413Subclass extends Issue413 {
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 Issue413 {
5+
// ^^^^^^^^ definition minimized/Issue413# trait Issue413
6+
val b: Int
7+
// ^ definition minimized/Issue413#b. val b: Int
8+
// ^^^ reference scala/Int#
9+
}
10+
11+
class Issue413Subclass extends Issue413 {
12+
// ^^^^^^^^^^^^^^^^ definition minimized/Issue413Subclass# class Issue413Subclass
13+
// definition minimized/Issue413Subclass#`<init>`(). def this()
14+
// ^^^^^^^^ reference minimized/Issue413#
15+
// reference java/lang/Object#`<init>`().
16+
override val b = 10
17+
// ^ definition minimized/Issue413Subclass#b. val b: Int
18+
}

0 commit comments

Comments
 (0)