-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: hook up actions in sbt-bridge to start forwarding actionable diagnostics #17561
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
Conversation
Here are some examples using sbt 1.9.0 and Metals showing the BSP trace that you'd expect: For this code: package example
object Hello:
def x: Int = 3
val test = x _ The diagnostic that is forwarded to the editor looks like:
For this code: package example
object Hello:
def foo(): Unit = ()
val x = foo The trace:
For this code: package example
final final class Test The trace:
|
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.
In https://contributors.scala-lang.org/t/roadmap-for-actionable-diagnostics/6172/13 @eed3si9n discussed the semantics of changes, it'd be great to have tests in both Scala 2 and Scala 3 to ensure we agree here. Also IMO we should absolutely match what the LSP specifies if we don't want to end up with incorrect implementations in LSP servers.
ActionPatch(SourcePosition(tree.source, Span(tree.span.start)), "(() => "), | ||
ActionPatch(SourcePosition(tree.source, Span(qual.span.end, tree.span.end)), ")") |
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.
This duplicates the logic with patch(...)
calls at the use-site of OnlyFunctionsCanBeFollowedByUnderscore, I think having the actions in the message like this makes a lot of sense but we need to drop the old patch
mechanism at the same time otherwise we'll be in a weird situation where -rewrite and IDEs each do their own thing.
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.
Good call. So what I did here was that I ended up making the patches inside of the message like I was before, but now instead of putting patch
es together like this outside of the message, we instead create the message and then just grab the patch out of the message. This still isn't idea and something we talked about this morning was completely refactoring the way that patches are applied by waiting until the reporting happens and during that time, check if the message that is being reported has an action, and if so, apply it, which contains the patch. However, thinking about this a bit more this afternoon @smarter, one limitation of that approach is that many places where we do patches, messages don't exist. In fact, the vast majority of the places that we call patch
, there is no Message
for that. So in order for that to work we'd really want to create a unique Message
for it that would hold that actions/patch.
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 guess we could keep patch
around for formatting changes (braces <-> indent) since flooding the console with messages for those changes wouldn't be useful.
Yup, so I just created a comment in here because currently we actually differ. The |
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.
Otherwise LGTM!
Instead of keeping track of the delta, we simply reverse the patches and apply them. This shouldn't be problematic because we do a check beforehand ensuring that there aren't overlapping patches. This greatly simplifies the way these are applied for the tests while keeping the same behavior.
This also has a small change where instead of applying all the actions if we are doing a rewrite, we only actually take the first one
Alright, I made the necessary adjustments so I'm going to go ahead and pull the trigger! Hopefully moving forward this will allow for more and more of these to be integrated. |
There are still a few things I need to add/test fully before this is ready for a full review, but I thought I'd push it up just for others to take a look at or discuss if need be. The background for this is in here, but this uses the POC that @smarter did at the tooling summit with the new structure that we agreed on. Some things I still need to test/work on:
So far this contains actions for:
refs: #17337