Merge pull request #8013 from eed3si9n/wip/position2

This commit is contained in:
eugene yokota 2025-01-21 09:55:26 -05:00 committed by GitHub
commit 1b712d2c6b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 7 deletions

View File

@ -97,8 +97,8 @@ class Eval(
| }
|}
|""".stripMargin
val startLine = header.linesIterator.toList.size
EvalSourceFile(srcName, startLine, contents)
val headerLine = header.linesIterator.toList.size
EvalSourceFile(srcName, headerLine, line - 1, contents)
override def extract(run: Run, unit: CompilationUnit)(using ctx: Context): String =
atPhase(Phases.typerPhase.next) {
@ -159,8 +159,8 @@ class Eval(
|${definitions.map(_._1).mkString("\n")}
|}
|""".stripMargin
val startLine = header.linesIterator.toList.size
EvalSourceFile(srcName, startLine, contents)
val headerLine = header.linesIterator.toList.size
EvalSourceFile(srcName, headerLine, 0, contents)
override def extract(run: Run, unit: CompilationUnit)(using ctx: Context): Seq[String] =
atPhase(Phases.typerPhase.next) {
@ -319,13 +319,15 @@ object Eval:
private[sbt] final val WrapValName = "$sbtdef"
// used to map the position offset
class EvalSourceFile(name: String, startLine: Int, contents: String)
class EvalSourceFile(name: String, headerLine: Int, extraLine: Int, contents: String)
extends SourceFile(
new VirtualFile(name, contents.getBytes(StandardCharsets.UTF_8)),
contents.toArray
):
override def lineToOffset(line: Int): Int = super.lineToOffset((line + startLine) max 0)
override def offsetToLine(offset: Int): Int = super.offsetToLine(offset) - startLine
override def lineToOffset(line: Int): Int =
super.lineToOffset((line + headerLine - extraLine) max 0)
override def offsetToLine(offset: Int): Int =
super.offsetToLine(offset) - headerLine + extraLine
end EvalSourceFile
trait EvalType[A]: