Skip to content
This repository was archived by the owner on Jun 10, 2020. It is now read-only.

Commit cd33aad

Browse files
committed
xsbti.Position: Also add {start,end}{Line,Column}
Positions in the Language Server Protocol and Build Server Protocol are line/column-based instead of offset-based, so this is more convenient. Computing the line/column from the offset is possible but requires reading the source file.
1 parent 1b2f2cd commit cd33aad

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

internal/util-interface/src/main/java/xsbti/Position.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,8 @@ public interface Position
2222
// Default values to avoid breaking binary compatibility
2323
default Optional<Integer> startOffset() { return Optional.empty(); }
2424
default Optional<Integer> endOffset() { return Optional.empty(); }
25+
default Optional<Integer> startLine() { return Optional.empty(); }
26+
default Optional<Integer> startColumn() { return Optional.empty(); }
27+
default Optional<Integer> endLine() { return Optional.empty(); }
28+
default Optional<Integer> endColumn() { return Optional.empty(); }
2529
}

internal/util-logging/src/main/scala/sbt/util/InterfaceUtil.scala

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ object InterfaceUtil {
4646
sourcePath0: Option[String],
4747
sourceFile0: Option[File]
4848
): Position =
49-
position(line0, content, offset0, pointer0, pointerSpace0, sourcePath0, sourceFile0, None, None)
49+
position(line0, content, offset0, pointer0, pointerSpace0, sourcePath0, sourceFile0, None, None, None, None, None, None)
5050

5151
def position(
5252
line0: Option[Integer],
@@ -57,7 +57,11 @@ object InterfaceUtil {
5757
sourcePath0: Option[String],
5858
sourceFile0: Option[File],
5959
startOffset0: Option[Integer],
60-
endOffset0: Option[Integer]
60+
endOffset0: Option[Integer],
61+
startLine0: Option[Integer],
62+
startColumn0: Option[Integer],
63+
endLine0: Option[Integer],
64+
endColumn0: Option[Integer]
6165
): Position =
6266
new ConcretePosition(line0,
6367
content,
@@ -67,7 +71,11 @@ object InterfaceUtil {
6771
sourcePath0,
6872
sourceFile0,
6973
startOffset0,
70-
endOffset0)
74+
endOffset0,
75+
startLine0,
76+
startColumn0,
77+
endLine0,
78+
endColumn0)
7179

7280
def problem(cat: String, pos: Position, msg: String, sev: Severity): Problem =
7381
new ConcreteProblem(cat, pos, msg, sev)
@@ -99,7 +107,11 @@ object InterfaceUtil {
99107
sourcePath0: Option[String],
100108
sourceFile0: Option[File],
101109
startOffset0: Option[Integer],
102-
endOffset0: Option[Integer]
110+
endOffset0: Option[Integer],
111+
startLine0: Option[Integer],
112+
startColumn0: Option[Integer],
113+
endLine0: Option[Integer],
114+
endColumn0: Option[Integer]
103115
) extends Position {
104116
val line = o2jo(line0)
105117
val lineContent = content
@@ -110,6 +122,10 @@ object InterfaceUtil {
110122
val sourceFile = o2jo(sourceFile0)
111123
override val startOffset = o2jo(startOffset0)
112124
override val endOffset = o2jo(endOffset0)
125+
override val startLine = o2jo(startLine0)
126+
override val startColumn = o2jo(startColumn0)
127+
override val endLine = o2jo(endLine0)
128+
override val endColumn = o2jo(endColumn0)
113129
}
114130

115131
private final class ConcreteProblem(

0 commit comments

Comments
 (0)