Skip to content

Commit 6d6fd45

Browse files
committed
Indent snapshot source lines with 2 spaces and replace tabs with spaces
- Add 2-space prefix to all source lines in snapshot output, matching the convention used by scip-go snapshots for caret-based indicators - Convert tab indentation to 2-space indentation in test input files: TabIndented.java, AnnotationParameters.java, LombokBuilder.java
1 parent 6868f1c commit 6d6fd45

138 files changed

Lines changed: 83027 additions & 83012 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

scip-java/src/main/scala/com/sourcegraph/scip_java/ScipPrinters.scala

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ import moped.reporters.Position
1212

1313
object ScipPrinters {
1414

15+
/**
16+
* Indent prefix prepended to each source line so that caret-based indicators
17+
* in snapshot comments can point at arbitrary columns.
18+
*/
19+
val sourceIndent = " "
20+
1521
def printTextDocument(
1622
doc: Scip.Document,
1723
text: String,
@@ -55,7 +61,7 @@ object ScipPrinters {
5561
.linesWithSeparators
5662
.zipWithIndex
5763
.foreach { case (line, i) =>
58-
out.append(line.replace("\t", ""))
64+
out.append(sourceIndent).append(line.replace("\t", " "))
5965
val occurrences = occurrencesByLine
6066
.getOrElse(i, Nil)
6167
.toSeq
@@ -133,8 +139,8 @@ object ScipPrinters {
133139
else
134140
"reference"
135141
val indent =
136-
if (pos.startColumn > comment.length)
137-
" " * (pos.startColumn - comment.length)
142+
if (pos.startColumn + sourceIndent.length > comment.length)
143+
" " * (pos.startColumn + sourceIndent.length - comment.length)
138144
else
139145
""
140146
val caretCharacter =

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ private void processTypedDocument(
187187
// Add enclosing_range if it exists
188188
if (occ.hasEnclosingRange()) {
189189
Semanticdb.Range enclosingRange = occ.getEnclosingRange();
190-
boolean isEnclosingSingleLine =
190+
boolean isEnclosingSingleLine =
191191
enclosingRange.getStartLine() == enclosingRange.getEndLine();
192192
Iterable<Integer> enclosingRangeInts =
193193
isEnclosingSingleLine

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ public static Semanticdb.Signature signature(Semanticdb.TypeSignature.Builder si
5252
// SemanticDB Symbols
5353

5454
public static Semanticdb.SymbolOccurrence symbolOccurrence(
55-
String symbol, Semanticdb.Range range, Semanticdb.SymbolOccurrence.Role role,
55+
String symbol,
56+
Semanticdb.Range range,
57+
Semanticdb.SymbolOccurrence.Role role,
5658
java.util.Optional<Semanticdb.Range> enclosingRange) {
57-
Semanticdb.SymbolOccurrence.Builder builder = Semanticdb.SymbolOccurrence.newBuilder()
58-
.setSymbol(symbol)
59-
.setRange(range)
60-
.setRole(role);
59+
Semanticdb.SymbolOccurrence.Builder builder =
60+
Semanticdb.SymbolOccurrence.newBuilder().setSymbol(symbol).setRange(range).setRole(role);
6161
enclosingRange.ifPresent(builder::setEnclosingRange);
6262
return builder.build();
6363
}

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

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,14 @@ private Optional<Semanticdb.Range> emitSymbolOccurrence(
119119
return range;
120120
}
121121

122-
private void emitSymbolOccurrence(Element sym, Optional<Semanticdb.Range> range, Role role, Optional<Semanticdb.Range> enclosingRange) {
122+
private void emitSymbolOccurrence(
123+
Element sym,
124+
Optional<Semanticdb.Range> range,
125+
Role role,
126+
Optional<Semanticdb.Range> enclosingRange) {
123127
if (sym == null) return;
124-
Optional<Semanticdb.SymbolOccurrence> occ = semanticdbOccurrence(sym, range, role, enclosingRange);
128+
Optional<Semanticdb.SymbolOccurrence> occ =
129+
semanticdbOccurrence(sym, range, role, enclosingRange);
125130
occ.ifPresent(occurrences::add);
126131
}
127132

@@ -463,7 +468,10 @@ private Semanticdb.Range correctForTabs(Semanticdb.Range range, LineMap lineMap,
463468
}
464469

465470
private Optional<Semanticdb.SymbolOccurrence> semanticdbOccurrence(
466-
Element sym, Optional<Semanticdb.Range> range, Role role, Optional<Semanticdb.Range> enclosingRange) {
471+
Element sym,
472+
Optional<Semanticdb.Range> range,
473+
Role role,
474+
Optional<Semanticdb.Range> enclosingRange) {
467475
if (range.isPresent()) {
468476
String ssym = semanticdbSymbol(sym);
469477
if (!ssym.equals(SemanticdbSymbols.NONE)) {
@@ -478,10 +486,9 @@ private Optional<Semanticdb.SymbolOccurrence> semanticdbOccurrence(
478486
}
479487

480488
/**
481-
* Computes the enclosing range for the given tree node.
482-
* Returns the range of the nearest non-trivial enclosing AST node.
483-
* For definition occurrences, this includes the entire definition including documentation.
484-
* For reference occurrences, this includes the parent expression bounds.
489+
* Computes the enclosing range for the given tree node. Returns the range of the nearest
490+
* non-trivial enclosing AST node. For definition occurrences, this includes the entire definition
491+
* including documentation. For reference occurrences, this includes the parent expression bounds.
485492
*/
486493
private Optional<Semanticdb.Range> computeEnclosingRange(Tree tree) {
487494
if (tree == null) return Optional.empty();
@@ -492,14 +499,16 @@ private Optional<Semanticdb.Range> computeEnclosingRange(Tree tree) {
492499
// For method, class, and variable definitions, use the tree itself as the enclosing range
493500
// since we're processing the definition node
494501
Tree enclosingTree = tree;
495-
if (!(tree instanceof MethodTree || tree instanceof ClassTree || tree instanceof VariableTree)) {
502+
if (!(tree instanceof MethodTree
503+
|| tree instanceof ClassTree
504+
|| tree instanceof VariableTree)) {
496505
// For non-definition nodes (like references), use the parent
497506
TreePath parentPath = path.getParentPath();
498507
if (parentPath == null) return Optional.empty();
499508
enclosingTree = parentPath.getLeaf();
500509
if (enclosingTree == null || enclosingTree == compUnitTree) return Optional.empty();
501510
}
502-
511+
503512
SourcePositions sourcePositions = trees.getSourcePositions();
504513
int start = (int) sourcePositions.getStartPosition(compUnitTree, enclosingTree);
505514
int end = (int) sourcePositions.getEndPosition(compUnitTree, enclosingTree);
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
package minimized;
22

33
@interface Bar {
4-
double value();
4+
double value();
55
}
66

77
@interface BarB {
8-
boolean value();
8+
boolean value();
99
}
1010

1111
@interface Nullable {
12-
String value() default "";
12+
String value() default "";
1313
}
1414

1515

1616
@interface BarRef{
17-
SuppressWarnings value();
17+
SuppressWarnings value();
1818
}
1919

2020
interface Foo {
21-
@Bar(-1d)
22-
double test();
21+
@Bar(-1d)
22+
double test();
2323

24-
@Bar(~5)
25-
@SuppressWarnings(value = "unchecked")
26-
double test2();
24+
@Bar(~5)
25+
@SuppressWarnings(value = "unchecked")
26+
double test2();
2727

28-
@BarB(!true)
29-
double test3();
28+
@BarB(!true)
29+
double test3();
3030

31-
@Nullable(("what"))
32-
Foo test4();
31+
@Nullable(("what"))
32+
Foo test4();
3333

34-
@Bar((double) -1)
35-
double testCast();
34+
@Bar((double) -1)
35+
double testCast();
3636
}
3737

3838
interface TestRef {
39-
@BarRef(@SuppressWarnings(value = "unchecked"))
40-
abstract double testCase();
39+
@BarRef(@SuppressWarnings(value = "unchecked"))
40+
abstract double testCase();
4141
}

tests/minimized/src/main/java/minimized/LombokBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
@lombok.Builder
44
class Hello {
5-
private String message;
5+
private String message;
66
}
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
package minimized;
22

33
public class TabIndented {
4-
public void app() {
5-
Object o = new Object() {
6-
@Override
7-
public boolean equals(Object other) {
8-
return false;
9-
}
4+
public void app() {
5+
Object o = new Object() {
6+
@Override
7+
public boolean equals(Object other) {
8+
return false;
9+
}
1010

11-
@Override
12-
public int hashCode() {
13-
return System.identityHashCode(this);
14-
}
11+
@Override
12+
public int hashCode() {
13+
return System.identityHashCode(this);
14+
}
1515

16-
@Override
17-
public String toString() {
18-
return "";
19-
}
20-
};
21-
}
16+
@Override
17+
public String toString() {
18+
return "";
19+
}
20+
};
21+
}
2222
}

0 commit comments

Comments
 (0)