-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Implement quickfixes, aka actionable diagnostics (via CodeAction
)
#10406
Conversation
This is looking very good, thank you! I wonder if we can already push a bit harder to the new API, for example,
Why do we need I guess the boilerplate in |
Initially I thought
This was mostly copied from similar code I added in sbt, but I guess I can use normal case classes within scalac.
I'll look into those. |
We're more than happy to help out, let me know. |
Feel free to add commits on top (or a new PR). I am mostly interested in getting code actions out, and I trust your judgement on how implementation can be improved. I'll comment here before working on something to avoid duplication. |
I'll start with the removal of api traits, and converting to case classes. |
ok. Made a few more changes per suggestion. |
I can't wait for |
44e61dd
to
1d11931
Compare
I think this should be about it for now, a
I did a basic sbt test by |
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.
I think we should be good in the projects that we use the compiler directly. Though to be 100% sure I would need to try and compile the affected projects.
@@ -97,11 +93,16 @@ object Reporter { | |||
abstract class FilteringReporter extends Reporter { | |||
def settings: Settings | |||
|
|||
@deprecatedOverriding("override the `doReport` overload instead", "2.13.12") | |||
@deprecated("use the `doReport` overload instead", "2.13.12") | |||
def doReport(pos: Position, msg: String, severity: Severity): Unit = doReport(pos, msg, severity, Nil) |
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.
I see that this is kept, so we should be asafe, I think doReport is used in scalameta/scalameta and scalameta/mdoc. Possibly also scala-cli?
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.
Calling the method is source compatible, but extending FilteringReporter
is not. The abstract method used to be
def doReport(pos: Position, msg: String, severity: Severity): Unit
and now it's
@deprecatedOverriding("override the `doReport` overload instead", "2.13.12")
@deprecated("use the `doReport` overload instead", "2.13.12")
def doReport(pos: Position, msg: String, severity: Severity): Unit = doReport(pos, msg, severity, Nil)
override def doReport(pos: Position, msg: String, severity: Severity, actions: List[CodeAction]): Unit
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.
That will be a problem for mdoc then since we don't publish for each Scala version :/ This of course causes us problems, but on the other hand we can support all the Scala versions without separate publishing
Any idea how we should work around that? I can take a look at it after Scala Days, but I am bit terrified as I don't fully remember why we wrote it this way. I guess some of the classes were not available in the older versions and I had to work around it this way.
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.
OK, so ideally an mdoc release should be binary compatible with all Scala 2.13 versions, i.e.,
- existing ones should continue to work with new Scala releases, and
- new mdoc releases built with a new Scala version should work with older Scala versions?
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.
That's the idea, but it's based on an assumption that the Report API wouldn't change too much 😓 which is clearly a wrong assumption.
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.
I pushed a small change that should restore binary compatibility (both ways) with existing FilteringReporter subclasses. I tested it with the following:
import scala.tools.nsc.Settings
import scala.reflect.internal.util.Position
// import scala.reflect.internal.util.CodeAction
import scala.reflect.internal.Reporter.Severity
import scala.annotation.nowarn
import scala.tools.nsc.reporters.FilteringReporter
trait MyRepT extends FilteringReporter { self: MyRep =>
@nowarn("cat=deprecation")
override def doReport(pos: Position, msg: String, severity: Severity): Unit =
add(pos, msg, severity)
// override def doReport(pos: Position, msg: String, severity: Severity, actions: List[CodeAction]): Unit =
// add(pos, msg, severity)
}
class MyRep(val settings: Settings) extends MyRepT {
def add(pos: Position, msg: String, severity: Severity): Unit =
println(s"[myrep] $msg")
}
Compiling this class with 2.13.10, I can use the reporter with both 2.13.10 and this PR
➜ sandbox java -cp $(cs fetch -p org.scala-lang:scala-compiler:2.13.10):. scala.tools.nsc.Main -usejavacp -Xreporter:MyRep A.scala
[myrep] type mismatch;
found : String("")
required: Int
➜ sandbox qsc -toolcp . -Xreporter:MyRep A.scala
[myrep] type mismatch;
found : String("")
required: Int
I also compiled the class with this PR's compiler and it works with 2.13.10, with or without un-commenting the doReport
overload.
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! I think that should work for us! I can confirm 100% when there is a nightly version released
This is getting ready I think. @ckipp01 could you take a look at
One idea: instead of the |
Yup, just took a look and everything looks good! I did try to get it to work with the changes I made in Metals here, but was having a lot of issues getting it to work since I kept getting issues with Metals not being able to get semanticdb for the self-published version of Scala, even though I kept trying to turn of semanticDB in sbt. Either way, the shape that you have oulined in here seems to match what @eed3si9n made in BSP here and what I am using in Dotty here, so we should be good.
Yup, this is fine. The code action that we made here differs a bit from the LSP one. I added in the
Yup, also fine. These
Actually it started out as a
|
Thanks for taking a look! I don't mean to put the My proposal is to use a The compiler interface (which lives in the zinc repo for Scala 2, not in the compiler repo) would pull out the |
To clarify this discussion I made a diagram:
|
I think this is ready now. @eed3si9n would you take another look? There is still the idea to change the
The next step will be to adapt the compiler bridge. @eed3si9n as far as I can tell, bridge sources in zinc are by compiler major version. The current bridge sources work with the 2.13 compiler after this PR, but with the current model we'd also need to make sure the adapted bridge that forwards code actions works with older compilers. Do you already have ideas how this could be adressed? |
We could potentially:
|
LGTM as far as the PR goes. Like tgodzik said in the comment above, we'd find out if all the pieces snap once nightly comes out. |
Add a new `actions: List[CodeAction]` parameter to reporting methods. The purpose is to pass these along to Zinc and BSP so that the compiler can suggest code edits to the editors in a structural manner. To showcase this feature, CodeActions are added for * Deprecation of procedure syntax * Deprecation of empty-paren method auto-application * Deprecation of val in for-comprehension * Deprecation of paren-less lambda parameter Existing subclasses of FilteringReporter should continue to work, though the compiler is generally not binary compatible between minor versions.
I think I'd prefer that, it needs some work to set up. Would the dispatching be done in How are the bridge sources distributed? We could still consider moving the bridge into scala/scala, but that's beyond scope right now.
If that's easier - I'd need your help
If we're using |
compiler bridge is distributed like a normal artifact on Maven Central (https://repo1.maven.org/maven2/org/scala-sbt/compiler-bridge_2.13/1.9.2/), the downside of approach is that the dispatch is done at the build tool level - https://github.com/sbt/sbt/blob/4b0b929838c7525cbacd790c2111997d80a5c72e/zinc-lm-integration/src/main/scala/sbt/internal/inc/ZincLmUtil.scala#L85-L100. I wouldn't be surprised other build tools assume naming convention.
Given that we need to override a method that takes a class non-existent in 2.13.11, supplying a whole |
Moved the discussion here: sbt/zinc#1214 |
in the community build, over at scala/community-build#1685 , this broke scalameta:
is it remediable here in scala/scala, or do we need to just ask the scalameta folks to adjust? |
it's just test code (note UPDATE: Tomasz says it is that simple, actually 👍 |
specifically, scala/scala#10406
### What changes were proposed in this pull request? The pr aims to upgrade sbt from 1.9.2 to 1.9.3. ### Why are the changes needed? 1.The new version brings some improvment: Actionable diagnostics (aka quickfix) Actionable diagnostics, or quickfix, is an area in Scala tooling that's been getting attention since Chris Kipp presented it in the March 2023 Tooling Summit. Chris has written the [roadmap](https://contributors.scala-lang.org/t/roadmap-for-actionable-diagnostics/6172/1) and sent sbt/sbt#7242 that kickstarted the effort, but now there's been steady progress in build-server-protocol/build-server-protocol#527, scala/scala3#17337, scala/scala#10406, IntelliJ, Zinc, etc. Metals 1.0.0, for example, is now capable of surfacing code actions as a quickfix. sbt 1.9.3 adds a new interface called AnalysisCallback2 to relay code actions from the compiler(s) to Zinc's Analysis file. Future version of Scala 2.13.x (and hopefully Scala 3) will release with proper code actions, but as a demo I've implemented a code action for procedure syntax usages even on current Scala 2.13.11 with -deprecation flag. 2.Full release notes: https://github.com/sbt/sbt/releases/tag/v1.9.3 3.v1.9.2 VS v1.9.3 sbt/sbt@v1.9.2...v1.9.3 ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Pass GA. Closes #42141 from panbingkun/SPARK-44536. Authored-by: panbingkun <pbk1982@gmail.com> Signed-off-by: yangjie01 <yangjie01@baidu.com>
CodeAction
(actionable diagnostic)
CodeAction
(actionable diagnostic)CodeAction
)
CodeAction
)CodeAction
)
### What changes were proposed in this pull request? This pr aims to upgrade Scala from 2.13.11 to 2.13.12. Additionally, this pr adds ``-Wconf:msg=legacy-binding:s`` to suppress similar compiler warnings as below: ``` [ERROR] /Users/yangjie01/SourceCode/git/spark-mine-13/core/src/main/scala/org/apache/spark/deploy/client/StandaloneAppClient.scala:171: reference to stop is ambiguous; it is both defined in the enclosing class StandaloneAppClient and inherited in the enclosing class ClientEndpoint as method stop (defined in trait RpcEndpoint, inherited through parent trait ThreadSafeRpcEndpoint) In Scala 2, symbols inherited from a superclass shadow symbols defined in an outer scope. Such references are ambiguous in Scala 3. To continue using the inherited symbol, write `this.stop`. Or use `-Wconf:msg=legacy-binding:s` to silence this warning. [quickfixable] Applicable -Wconf / nowarn filters for this fatal warning: msg=<part of the message>, cat=other, site=org.apache.spark.deploy.client.StandaloneAppClient.ClientEndpoint.receive ``` ### Why are the changes needed? The new version bring some regression fixes: - scala/scala#10422 - scala/scala#10424 And a new feature: Quickfixes ``` For some errors and warnings, the compiler now suggests an edit that could fix the issue. Tooling such as IDEs can then offer the edits, or the compiler itself will make the change if run again with -quickfix. ``` - scala/scala#10406 - scala/scala#10482 - scala/scala#10484 The release notes as follows: - https://github.com/scala/scala/releases/tag/v2.13.12 ### Does this PR introduce _any_ user-facing change? Yes, Scala version changed. ### How was this patch tested? Pass Github ### Was this patch authored or co-authored using generative AI tooling? NO Closes #43185 from LuciferYang/SPARK-45331. Authored-by: yangjie01 <yangjie01@baidu.com> Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
### What changes were proposed in this pull request? The pr aims to upgrade sbt from 1.9.2 to 1.9.3. ### Why are the changes needed? 1.The new version brings some improvment: Actionable diagnostics (aka quickfix) Actionable diagnostics, or quickfix, is an area in Scala tooling that's been getting attention since Chris Kipp presented it in the March 2023 Tooling Summit. Chris has written the [roadmap](https://contributors.scala-lang.org/t/roadmap-for-actionable-diagnostics/6172/1) and sent sbt/sbt#7242 that kickstarted the effort, but now there's been steady progress in build-server-protocol/build-server-protocol#527, scala/scala3#17337, scala/scala#10406, IntelliJ, Zinc, etc. Metals 1.0.0, for example, is now capable of surfacing code actions as a quickfix. sbt 1.9.3 adds a new interface called AnalysisCallback2 to relay code actions from the compiler(s) to Zinc's Analysis file. Future version of Scala 2.13.x (and hopefully Scala 3) will release with proper code actions, but as a demo I've implemented a code action for procedure syntax usages even on current Scala 2.13.11 with -deprecation flag. 2.Full release notes: https://github.com/sbt/sbt/releases/tag/v1.9.3 3.v1.9.2 VS v1.9.3 sbt/sbt@v1.9.2...v1.9.3 ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Pass GA. Closes apache#42141 from panbingkun/SPARK-44536. Authored-by: panbingkun <pbk1982@gmail.com> Signed-off-by: yangjie01 <yangjie01@baidu.com>
Ref https://contributors.scala-lang.org/t/roadmap-for-actionable-diagnostics/6172
Fixes scala/scala-dev#844
This implements new reporter methods that take code actions as a parameter.
The purpose is to pass these along to Zinc and BSP so that the compiler can suggest code edits to the editors in a structural manner.
To show case this feature, I've added
CodeAction
s to the following deprecations:val
in for-comprehensionNote
Here's the flow of information