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.
This commit is contained in:
Guillaume Martres 2018-08-14 02:00:41 +09:00
parent 78834527df
commit 5e3a102606
2 changed files with 24 additions and 4 deletions

View File

@ -22,4 +22,8 @@ public interface Position
// Default values to avoid breaking binary compatibility
default Optional<Integer> startOffset() { return Optional.empty(); }
default Optional<Integer> endOffset() { return Optional.empty(); }
default Optional<Integer> startLine() { return Optional.empty(); }
default Optional<Integer> startColumn() { return Optional.empty(); }
default Optional<Integer> endLine() { return Optional.empty(); }
default Optional<Integer> endColumn() { return Optional.empty(); }
}

View File

@ -46,7 +46,7 @@ object InterfaceUtil {
sourcePath0: Option[String],
sourceFile0: Option[File]
): Position =
position(line0, content, offset0, pointer0, pointerSpace0, sourcePath0, sourceFile0, None, None)
position(line0, content, offset0, pointer0, pointerSpace0, sourcePath0, sourceFile0, None, None, None, None, None, None)
def position(
line0: Option[Integer],
@ -57,7 +57,11 @@ object InterfaceUtil {
sourcePath0: Option[String],
sourceFile0: Option[File],
startOffset0: Option[Integer],
endOffset0: Option[Integer]
endOffset0: Option[Integer],
startLine0: Option[Integer],
startColumn0: Option[Integer],
endLine0: Option[Integer],
endColumn0: Option[Integer]
): Position =
new ConcretePosition(line0,
content,
@ -67,7 +71,11 @@ object InterfaceUtil {
sourcePath0,
sourceFile0,
startOffset0,
endOffset0)
endOffset0,
startLine0,
startColumn0,
endLine0,
endColumn0)
def problem(cat: String, pos: Position, msg: String, sev: Severity): Problem =
new ConcreteProblem(cat, pos, msg, sev)
@ -99,7 +107,11 @@ object InterfaceUtil {
sourcePath0: Option[String],
sourceFile0: Option[File],
startOffset0: Option[Integer],
endOffset0: Option[Integer]
endOffset0: Option[Integer],
startLine0: Option[Integer],
startColumn0: Option[Integer],
endLine0: Option[Integer],
endColumn0: Option[Integer]
) extends Position {
val line = o2jo(line0)
val lineContent = content
@ -110,6 +122,10 @@ object InterfaceUtil {
val sourceFile = o2jo(sourceFile0)
override val startOffset = o2jo(startOffset0)
override val endOffset = o2jo(endOffset0)
override val startLine = o2jo(startLine0)
override val startColumn = o2jo(startColumn0)
override val endLine = o2jo(endLine0)
override val endColumn = o2jo(endColumn0)
}
private final class ConcreteProblem(