intellij icon indicating copy to clipboard operation
intellij copied to clipboard

Override Reload File debugger action

Open brian-mcnamara opened this issue 2 years ago • 9 comments

Checklist

  • [ ] I have filed an issue about this change and discussed potential changes with the maintainers.
  • [ ] I have received the approval from the maintainers to make this change.
  • [ ] This is not a stylistic, refactoring, or cleanup change.

Please note that the maintainers will not be reviewing this change until all checkboxes are ticked. See the Contributions section in the README for more details.

Description of this change

Currently, IJ has a "Compile and Reload file" option available via right clicking the contents of a java file. This is currently broken with Bazel since the action needs to be overridden to delegate to bazel build. This work aims to implement a similar functionality via overriding the action, delegating to bazel build, and finding and extracting the compiled classes to pass hotswap.

brian-mcnamara avatar Jul 25 '23 20:07 brian-mcnamara

I'm not sure if it is possible to reuse the logic of BlazeHotSwapActionManager to reload the certain file of interest in BlazeReloadFileAction.java

mai93 avatar Jul 31 '23 19:07 mai93

I'm not sure if it is possible to reuse the logic of BlazeHotSwapActionManager to reload the certain file of interest in BlazeReloadFileAction.java

I did look at this code initially, unfortunately not without a lot of refactoring (which I could do, just decided it would not be a lot of overlapping code to consider it).

The current manager has a tight coupling to the ClassFileManifest which does not work for our case (where bazel run is run outside the IDE and we are attaching to the instance). Because of this (and other fun our app launcher works), the ClassFileManifest does not work. Because of this, the route I took with this PR is to only compile and hotswap a single file. Since we know the file, we do not need to use the ClassFileManifest.

Let me know if I missed something or if you believe refactoring would still be useful and Ill take a closer look :) .

brian-mcnamara avatar Jul 31 '23 20:07 brian-mcnamara

@mai93 checking back on this. Any thoughts or concerns with this getting merged?

brian-mcnamara avatar Aug 04 '23 17:08 brian-mcnamara

@mai93 checking back on this as Ive not heard back from you.

brian-mcnamara avatar Aug 10 '23 18:08 brian-mcnamara

Sorry for the delay! I do not think I will have the time to review this, @tpasternak offered to take a look next week.

mai93 avatar Aug 10 '23 19:08 mai93

Doesn't work for me.

I tested it on Linux by running the getPendingExternalDeps_followJavaDeps_allBuilt test from this repo. I placed a breakpoint inside it and clicked Compile and reload file.

The building targets progress indicator seems to be stuck forever. Looks like we're deadlocking Bazel.

image

image

Build waits for the test to finish, but it was started because I requested a rebuild from inside the test...

Does it look like https://github.com/bazelbuild/bazel/issues/2337 ?

dkashyn-sfdc avatar Jan 17 '24 15:01 dkashyn-sfdc

Does it look like bazelbuild/bazel#2337 ?

I'm not sure what you mean. I don't run anything in the command line manually. What I did was (I guess?) your expected workflow with this feature.

agluszak avatar Jan 18 '24 11:01 agluszak

Does it look like bazelbuild/bazel#2337 ?

I'm not sure what you mean. I don't run anything in the command line manually. What I did was (I guess?) your expected workflow with this feature.

@agluszak was taking a look at this yesterday, as far as I could tell the original hotswap implementation is also not supported when running tests via bazel. Seems like bazel run does not lock the server, but bazel test does. That said, I did not intend to replace the original hotswap mechanism, simply provide another option when not using launching the bazel target through the debug profile. It was intended for remote debugging. Either way, I'll update the logic to disable this action when the debug session is from a bazel target. In addition ill address the cancelation exception you discovered.

brian-mcnamara avatar Jan 18 '24 16:01 brian-mcnamara

Pushed a commit to add extra handling for the case of unsynced files. Was noticing the action was still available even when the file was unsynced. I also found that there was an exception for slow tasks in the UI thread, I have to override getActionUpdateThread to allow the BGT thread to be used, which the original action was using.

brian-mcnamara avatar Jan 31 '24 23:01 brian-mcnamara