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

xsbti.Position: add startOffset and endOffset #173

Merged
merged 3 commits into from
Aug 16, 2018

Conversation

smarter
Copy link
Contributor

@smarter smarter commented Aug 12, 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.

@smarter
Copy link
Contributor Author

smarter commented Aug 12, 2018

One remaining question is whether we should also add startLine/startColumn, endLine/endColumn. If the BSP stays line-column based instead of offset based that would be needed.

@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 sbt/zinc@6bd672b
io 1.2.x sbt/io@fb0acb1
librarymanagement 1.2.x sbt/librarymanagement@f42ec6f
util pull/173/head 1b2f2cd
website 1.2.x

✅ The result is: SUCCESS
(restart)

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.

Thanks for doing this! @smarter

I think startOffset/endOffset is enough (usually you will give this information to an IDE that already knows how to do the conversion from offset to (line, column). In error messages, showing the positions as we do now is good enough.

@smarter
Copy link
Contributor Author

smarter commented Aug 13, 2018

I think startOffset/endOffset is enough (usually you will give this information to an IDE that already knows how to do the conversion from offset to (line, column).

I disagree. If I'm a build tool implementing the BSP, there's no IDE involved, I'm just trying to translate what Zinc gives me to something that works with the BSP, but right now the BSP defines (like the LSP):

@JsonCodec final case class Position(
    line: Int,
    character: Int
)

@JsonCodec final case class Range(
    start: Position,
    end: Position
)

This could be changed in the BSP but it would be inconsistent with the LSP which is probably not going to change: microsoft/language-server-protocol#96

In conclusion things are already complicated enough, let's not make them more complicated for no reason: adding a few fields to Position has an insignificant cost and it means no one has to struggle doing conversions.

@jvican
Copy link
Member

jvican commented Aug 13, 2018

So then let’s add them to this PR too to avoid the extra read that would require in the bsp servers to convert offsets to line and column.

@smarter
Copy link
Contributor Author

smarter commented Aug 13, 2018

Will do!

@smarter
Copy link
Contributor Author

smarter commented Aug 13, 2018

Done, I'll update the zinc PR once this is merged.

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
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.
@smarter
Copy link
Contributor Author

smarter commented Aug 14, 2018

OK with merging? Or should I drop the 1.2.1 upgrade here too, and should I move to the 1.x branch here too?

@jvican
Copy link
Member

jvican commented Aug 14, 2018

I'm ok with targeting 1.2.1 here, but we'll need a release to make the other PR work. 😄

@smarter
Copy link
Contributor Author

smarter commented Aug 16, 2018

Ping @eed3si9n, can I merge this and request a release?

@eed3si9n eed3si9n merged commit 05cecc3 into sbt:1.2.x Aug 16, 2018
smarter added a commit to smarter/zinc that referenced this pull request Aug 17, 2018
smarter added a commit to smarter/zinc that referenced this pull request Aug 18, 2018
smarter added a commit to smarter/zinc that referenced this pull request Aug 18, 2018
smarter added a commit to smarter/zinc that referenced this pull request Aug 18, 2018
smarter added a commit to smarter/sbt-util that referenced this pull request Aug 27, 2018
It turns out that there is more boilerplate to fill that I missed.

Also add deprecation notices.
smarter added a commit to smarter/sbinary that referenced this pull request Aug 28, 2018
After sbt/util#173, Position now has 13 fields
so TextAnalysisFormat in Zinc needs asProduct13. While we're at it we
bump the max to 21 to give us some legroom.
eed3si9n added a commit that referenced this pull request Aug 29, 2018
Follow-up to the fields added in #173, and add Problem#rendered
eed3si9n added a commit to eed3si9n/sbt that referenced this pull request Sep 14, 2018
sbt/util#173 added the ability to carry range position. This exposes it to the sbt server.
eed3si9n added a commit to eed3si9n/sbt that referenced this pull request Sep 14, 2018
sbt/util#173 added the ability to carry range position. This exposes it to the sbt server.
eed3si9n pushed a commit to eed3si9n/scala that referenced this pull request May 14, 2019
lrytz pushed a commit to lrytz/scala that referenced this pull request Nov 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants