scalameta / mdoc

Typechecked markdown documentation for Scala
https://scalameta.org/mdoc/
Apache License 2.0
394 stars 80 forks source link

Confusing source code position in error message #877

Closed zhongl closed 2 months ago

zhongl commented 2 months ago

Input

```scala mdoc
extension (x: Int)
    def ===(y: Int) = x == y
1 === ""
    1 === 1    

### Command line

coursier launch org.scalameta:mdoc_3:2.5.3


### Output
extension (x: Int)
    def ===(y: Int) = x == y
1 === ""
// error:
// Found:    ("" : String)
// Required: Int
//     1 === 1
//          ^
    1 === 1

Source code position above

// 1 === 1 // ^


suppose to be 

// 1 === "" // ^^

zhongl commented 2 months ago

https://github.com/scalameta/mdoc/blob/06c90343cb66265e818da7fcb3ccd9ff46b9849d/mdoc/src/main/scala/mdoc/internal/markdown/Renderer.scala#L151-L155

I think TokenEditDistance from doc.sections cause confusing source code position.

I'd like to submit a PR to fix it, if it make sense.

tgodzik commented 2 months ago

Go ahead! I haven't had the chance to look at the issue yet.