-
-
Notifications
You must be signed in to change notification settings - Fork 364
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
Bump zinc and account for diagnostic code #1912
Conversation
Yea, later this week I should have some time to look back at this, but don't let it block updating to 1.7.0 in the other pr. Plus, this won't really matter until Dotty starts giving this information, and I'm still stuck on that since when testing with the locally published version of dotty that gives those, they are alway As for the failures in the other PR, no idea. |
This relates to the grand plan of scala/scala3#14904 and recently forwarding the `diagnosticCode` has been merged in scala/scala3#15565 and also backported so it should show up in the 3.2.x series. While this pr isn't super exciting, it's just making sure we capture the code and forward it, this should unlock _much_ better ways to determine what code actions are available for a given diagnostic. Meaning we don't have to do lovely things like regex on the diagnostic message for Scala 3 diagnostics. NOTE: that this does need some more changes in the build servers before this is usable. So we can wait for those to be merged in if you'd like. - [ ] sbt - sbt/sbt#6998 - [ ] Bloop - scalacenter/bloop#1750 - [ ] Mill - com-lihaoyi/mill#1912 Now if you look at the trace file for a diagnostic you'll see the addition of the code: ``` "diagnostics": [ { "range": { "start": { "line": 9, "character": 15 }, "end": { "line": 9, "character": 19 } }, "severity": 1, "code": "7", "source": "sbt", "message": "Found: (\u001b[32m\"hi\"\u001b[0m : String)\nRequired: Int\n\nThe following import might make progress towards fixing the problem:\n\n import sourcecode.Text.generate\n\n" } ], ``` Refs: scala/scala3#14904
I honestly have no idea what's going on with this. I was able to get this added to sbt by just mapping the diagnostic code pretty easily in https://github.com/sbt/sbt/pull/6998/files, but when trying to do the same thing here the code is just never there. I'm not sure if I'm misunderstanding something with how the compiler bridge works with Mill, but I can't get this to work. Do you by chance have any insight into what I might be doing wrong here or why this might not be working? You should be able to test this with |
I can't promise anything, but just from looking at the single line change in sbt, one potential difference between sbt and Mill could be the way we feed the source files. I don't know if we do it differently, but zinc has introduced some VirtualFile concept and it could be we use a different implementation which does not meet some assumptions which are fulfilled by sbt. This is just a guess though. It could also be caused by the use of different APIs, as we can't call all the sbt-private zinc API as sbt does. Maybe, we need to enable something before zinc/scalac is producing this info? |
I don't think this should really have anything to do with it since this change touches a very small area, and is only reflected in the |
btw update on this, I need sbt/sbt#7006 merged in first, and then I need to do an update to Zinc https://github.com/sbt/zinc/blob/5804d50afd960330f34af35e4367fdb171204f5a/internal/zinc-compile-core/src/main/scala/sbt/internal/inc/LoggedReporter.scala#L133-L142 and then hopefully this should be working here. |
e4ff173
to
84f81a8
Compare
So Mima is failing, but this is now working as expected. For example given the following code in Scala 3: package other
object Main extends App {
val a = "hi"
def test(a: Int) = if (a < 0) "negative" else "positive"
test(a)
} If you run it with Mill you'll see:
And then when used as a BSP server Mill will be correctly reporting the code:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating this PR. I wonder if there is an easy way to test this?
There is a binary incompatibility in mill.api.Problem
, which needs to be fixed when this PR shall make it into Mill 0.10 series. I think, one possible solution could be to let the new method diagnosticCode
have a default implementation, which could return None
, so that older code inheriting this trait
won't fail to load. We can make that change temporary and remove it once we are in 0.11
development scope. (It would be fine to already open a draft PR with the removal of the default value.)
At the moment this is just testing a bit. I see you already have a test PR to bump zinc in com-lihaoyi#1845 but one of the things that this brings in is the changes to `Problem` I made in sbt/sbt#6874 that expose the diagnostic code of the diagnostic coming from dotc. I have been doing some work on that on the compiler side in scala/scala3#15565 and wanted to try it out with Mill. I tried to mimic the way you currently have it set up, so let me know if it's not the direction you'd want to go. However, the idea here would be that the diagnostic code is forwarded when diagnostics are published via BSP so that Metals could then capture that code and know what code actions to offer. You can see more of the big picture in scala/scala3#14904.
84f81a8
to
08e9b7f
Compare
It depends I guess. Testing it at which phase, during the actual BSP reporting? I looked a bit and didn't see any tests regarding diagnostic reporting, but I may have missed them. Did I?
Ah yea, should have thought of this. I went ahead and added a default and then also added a |
You are right. We currently don't have any thorough BSP workflow testing. I guess, we lack some easy BSP client test toolkit. As we currently don't activate reporting in normal compile runs, there is no existing test into which we can hook easily. I'm fine with the PR without any new test. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Thank you!
This relates to the grand plan of scala/scala3#14904 and recently forwarding the `diagnosticCode` has been merged in scala/scala3#15565 and also backported so it should show up in the 3.2.x series. While this pr isn't super exciting, it's just making sure we capture the code and forward it, this should unlock _much_ better ways to determine what code actions are available for a given diagnostic. Meaning we don't have to do lovely things like regex on the diagnostic message for Scala 3 diagnostics. NOTE: that this does need some more changes in the build servers before this is usable. So we can wait for those to be merged in if you'd like. - [ ] sbt - sbt/sbt#6998 - [ ] Bloop - scalacenter/bloop#1750 - [ ] Mill - com-lihaoyi/mill#1912 Now if you look at the trace file for a diagnostic you'll see the addition of the code: ``` "diagnostics": [ { "range": { "start": { "line": 9, "character": 15 }, "end": { "line": 9, "character": 19 } }, "severity": 1, "code": "7", "source": "sbt", "message": "Found: (\u001b[32m\"hi\"\u001b[0m : String)\nRequired: Int\n\nThe following import might make progress towards fixing the problem:\n\n import sourcecode.Text.generate\n\n" } ], ``` Refs: scala/scala3#14904
This relates to the grand plan of scala/scala3#14904 and recently forwarding the `diagnosticCode` has been merged in scala/scala3#15565 and also backported so it should show up in the 3.2.x series. While this pr isn't super exciting, it's just making sure we capture the code and forward it, this should unlock _much_ better ways to determine what code actions are available for a given diagnostic. Meaning we don't have to do lovely things like regex on the diagnostic message for Scala 3 diagnostics. NOTE: that this does need some more changes in the build servers before this is usable. So we can wait for those to be merged in if you'd like. - [ ] sbt - sbt/sbt#6998 - [ ] Bloop - scalacenter/bloop#1750 - [ ] Mill - com-lihaoyi/mill#1912 Now if you look at the trace file for a diagnostic you'll see the addition of the code: ``` "diagnostics": [ { "range": { "start": { "line": 9, "character": 15 }, "end": { "line": 9, "character": 19 } }, "severity": 1, "code": "7", "source": "sbt", "message": "Found: (\u001b[32m\"hi\"\u001b[0m : String)\nRequired: Int\n\nThe following import might make progress towards fixing the problem:\n\n import sourcecode.Text.generate\n\n" } ], ``` Refs: scala/scala3#14904
At the moment this is just testing a bit. I see you already have a test
PR to bump zinc in #1845 but one
of the things that this brings in is the changes to
Problem
I made insbt/sbt#6874 that expose the diagnostic code of
the diagnostic coming from dotc. I have been doing some work on that on
the compiler side in scala/scala3#15565 and
wanted to try it out with Mill.
I tried to mimic the way you currently have it set up, so let me know if
it's not the direction you'd want to go. However, the idea here would be
that the diagnostic code is forwarded when diagnostics are published via
BSP so that Metals could then capture that code and know what code
actions to offer. You can see more of the big picture in scala/scala3#14904.