Skip to content
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

Fixes CodeAction (quickfix) support #1226

Merged
merged 3 commits into from Jul 23, 2023

Conversation

eed3si9n
Copy link
Member

Fixes #1225

This adds AnalysisCallback2 interface that's capable of forwarding CodeAction to the Analysis file.

@eed3si9n eed3si9n merged commit f55b5b5 into sbt:develop Jul 23, 2023
7 checks passed
@eed3si9n eed3si9n deleted the wip/code_action_in_analysis branch July 23, 2023 05:03
* @param diagnosticRelatedInformation The possible releated information for the diagnostic being reported.
* @param actions Actions (aka quick fixes) that are able to either fix or address the issue that is causing this problem.
*/
void problem2(String what,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this something that the Scala 3 bridge also needs to call? I thought we had all the pieces in place already /cc @ckipp01
Also couldn't this interface take an xsbti.Problem so we don't need a new one every time there's a new field?

Copy link

Choose a reason for hiding this comment

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

Nope, I don't believe this is necessary for Scala 3. These changes were specific to the Scala 2 implementation. You can actually test the actions already with the nightly version of the compiler and the latest metals release and see that everything is working as expected in Scala 3.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link

Choose a reason for hiding this comment

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

Huh, I guess it would seem so. I guess I don't fully understand how this is all working or when this run is called that you have linked since at least via BSP with sbt current the actions are forwarded as expected.

Copy link

Choose a reason for hiding this comment

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

You can actually test the actions already with the nightly version of the compiler and the latest metals release and see that everything is working as expected in Scala 3.

I confirmed this

Copy link
Member Author

Choose a reason for hiding this comment

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

sbt uses xsbi.Problem in 2 different ways:

  1. via xsbi.Reporter which you get a live callback per compiler warnings
  2. via CompileAnalysis, ReadSourceInfos, SourceInfo, which contains list of xsbti.Problem

This bug fix pertains the second pathway. I think the initial implementation of LSP or BSP use to resend all errors and warnings for all files at the end of compile as a workaround to make sure compiler warnings do not disappear, then in 2022 a few folks realized we're bombarding Metals with unnecessary problems, and we got fixes:

I usually ask @adpi2 to figure out the BSP handling, so I only occasionally jump in so I am not sure if this double dipping is unavoidable, but as a principle, it seems like a good idea that the problems we collect in Analysis contains new problem informations (like CodeAction and DiagnosticRelatedInformation).

Copy link
Member

Choose a reason for hiding this comment

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

it seems like a good idea that the problems we collect in Analysis contains new problem informations (like CodeAction and DiagnosticRelatedInformation).

Agreed. In the BSP reporter, we still use the CompileAnalysis to report the warnings from the files that the incremental compiler skipped. It's good to have the code actions in there.

Comment on lines +21 to +22
* Scala 3 compiler publishes their own compiler bridge against Zinc de jour.
* By having this interface, they can test if `callback` supports AnalysisCallback2.
Copy link
Contributor

Choose a reason for hiding this comment

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

How do you envision this working? If the dotty bridge starts doing isInstanceOf[AnalysisCallback2] we'll get a class not found exception if we're running against an older sbt/zinc, so we'd need to catch the exception I guess?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yea, I guess something like that. I figured it's better than just adding a new method.

Choose a reason for hiding this comment

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

also we have methodhandles

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess we can work with that, but it'd be great if we could coordinate on this sort of things before sbt releases in the future so we can take the time to come up with the best way forward, for example if we had gone with a problem that takes an xsbti.Problem we could have ensured we don't need another interface like this next time we add a field to xsbti.Problem.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yea, I wanted to unblock the development on this, but I guess in the hindsight I should've waited for reviews.

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

Successfully merging this pull request may close these issues.

CodeAction is not forwarded
5 participants