Skip to content

sbt.internal.inc.Position: add startOffset and endOffset #571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 22, 2018

Conversation

smarter
Copy link
Contributor

@smarter smarter commented Aug 12, 2018

This is a follow-up to sbt/util#173

@smarter
Copy link
Contributor Author

smarter commented Aug 12, 2018

(Running the validation against sbt/util#173)

@typesafe-tools
Copy link

The validator has checked the following projects against Scala 2.12,
tested using dbuild, projects built on top of each other.

Project Reference Commit
sbt 1.2.x sbt/sbt@549c694
zinc pull/571/head 6bd672b
io 1.2.x sbt/io@fb0acb1
librarymanagement 1.2.x sbt/librarymanagement@f42ec6f
util pull/173/head sbt/util@1b2f2cd
website 1.2.x

✅ The result is: SUCCESS
(restart)

jvican
jvican previously requested changes Aug 12, 2018
Copy link
Member

@jvican jvican left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not upgrade to sbt 1.2.1 here, since it causes build problems (last time I tried). Alternatively, I guess the build also fails here because we have yet to publish a jar with sbt/util#173 (review). Otherwise the patch LGTM!

smarter added a commit to smarter/sbt-util that referenced this pull request Aug 13, 2018
A position now has a start, an end, and a point (the existing `offset`),
just like it does in the Scala compiler. This information is especially
useful for displaying squiggly lines in an IDE.

This commit and the next one are required for sbt/zinc#571
@eed3si9n
Copy link
Member

So should this PR target 1.x branch?

@smarter
Copy link
Contributor Author

smarter commented Aug 14, 2018

Any reason it couldn't get in the next 1.2 release?

@jvican
Copy link
Member

jvican commented Aug 14, 2018

Targeting 1.x is better, we could branch out (or cherry pick) in 1.2.2 from there.

@eed3si9n
Copy link
Member

Any reason it couldn't get in the next 1.2 release?

I think it depends on how critical this change is. For sbt, we don't go through RC cycle for patch releases, so we try to keep them to bug fixes. Considering that 1.3.0 will be a few months away, I'm open to a few enhancements added during 1.2.x but we need to be fairly confident that it won't cause compatibility problems.

@smarter
Copy link
Contributor Author

smarter commented Aug 14, 2018

It's critical to getting any BSP implementation for Scala working. My goal is for us to be able to give the Intro to FP course at EPFL that starts in mid-September using Dotty, which means using the Dotty IDE, which would really benefit from the BSP.

@jvican
Copy link
Member

jvican commented Aug 14, 2018

I second this change, compatibility issues with this patch are close to zero IMO.

@smarter smarter force-pushed the position-range branch 3 times, most recently from 82b57d6 to 9d9741f Compare August 18, 2018 06:19
@smarter smarter changed the base branch from 1.2.x to 1.x August 18, 2018 06:19
@smarter smarter dismissed jvican’s stale review August 18, 2018 07:16

Moved to 1.x as requested, and I'll make a PR for backporting it as soon as it is merged.

@smarter smarter requested review from eed3si9n and jvican August 18, 2018 07:16

// Same logic as Position#line
def lineOf(offset: Int) = src.offsetToLine(offset) + 1
def columnOf(offset: Int) = offset - src.lineToOffset(src.offsetToLine(offset))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's always been this way, but isn't it weird that lines in the zinc Reporter are 1-based and columns are 0-based ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I would welcome a change here, I have no idea of the rationale of the previous change.

Copy link
Member

@jvican jvican left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@eed3si9n eed3si9n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@eed3si9n eed3si9n merged commit 88e0827 into sbt:1.x Aug 22, 2018
smarter added a commit to smarter/zinc that referenced this pull request Aug 22, 2018
smarter added a commit to smarter/zinc that referenced this pull request Aug 22, 2018
eed3si9n pushed a commit to scala/compiler-interface that referenced this pull request Apr 23, 2019
A position now has a start, an end, and a point (the existing `offset`),
just like it does in the Scala compiler. This information is especially
useful for displaying squiggly lines in an IDE.

This commit and the next one are required for sbt/zinc#571
@retronym
Copy link
Member

This change seems to interact poorly with Scaladoc. I think the root bug is in Scaladoc which is spitting out an invalid end position for use cases.

Minimized: https://github.com/retronym/sbt-scaladoc-aioooe

[info] Main Scala API documentation to /Users/jz/code/sbt-scaladoc-aioooe/target/scala-2.13/api...
[error] java.lang.ArrayIndexOutOfBoundsException: 14
[error] 	at scala.reflect.internal.util.BatchSourceFile.findLine$1(SourceFile.scala:200)
[error] 	at scala.reflect.internal.util.BatchSourceFile.offsetToLine(SourceFile.scala:203)
[error] 	at xsbt.DelegatingReporter$.lineOf$1(DelegatingReporter.scala:99)
[error] 	at xsbt.DelegatingReporter$.makePosition$1(DelegatingReporter.scala:112)
[error] 	at xsbt.DelegatingReporter$.convert(DelegatingReporter.scala:134)
[error] 	at xsbt.DelegatingReporter.info0(DelegatingReporter.scala:165)
[error] 	at scala.tools.nsc.reporters.MakeFilteringForwardingReporter.doReport(ForwardingReporter.scala:59)
[error] 	at scala.tools.nsc.reporters.FilteringReporter.info0(Reporter.scala:93)
[error] 	at scala.reflect.internal.Reporter.filteredInfo(Reporting.scala:118)
[error] 	at scala.reflect.internal.Reporter.warning(Reporting.scala:112)
[error] 	at scala.tools.nsc.doc.ScaladocAnalyzer$ScaladocTyper.$anonfun$typedDocDef$1(ScaladocAnalyzer.scala:47)
[error] 	at scala.tools.nsc.doc.ScaladocAnalyzer$ScaladocTyper.typedDocDef(ScaladocAnalyzer.scala:44)
[error] 	at scala.tools.nsc.doc.ScaladocAnalyzer$ScaladocTyper.typedDocDef$(ScaladocAnalyzer.scala:36)

Zinc could guard against the dodgy positions here. I'll see if I can figure out how to fix the positions in Scaladoc itself.

@retronym
Copy link
Member

Submitted a Scala bug for this: scala/bug#11865

@eed3si9n
Copy link
Member

Thanks @retronym. Opened #734 for Zinc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants