-
Notifications
You must be signed in to change notification settings - Fork 408
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
"Surround with try/catch" Code Action #2727
Conversation
Can one of the admins verify this patch? |
bdc50a9
to
345bffa
Compare
Will be following the steps in https://github.com/eclipse/eclipse.jdt.ls/blob/master/CONTRIBUTING.md#pull-requests soon. |
345bffa
to
8b1cc80
Compare
Would be good to compare to https://github.com/eclipse/eclipse.jdt.ls/blob/230d39431588d500f3a87162f0e50a486879b770/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/corrections/proposals/LocalCorrectionsSubProcessor.java#L122 as that might be similar functionality but for the case of proposing the fix only where a thrown exception is not being caught. @gayanper how would this PR affect redhat-developer/vscode-java#3104 (technically even that one could live server-side because a lot of snippet syntax is part of the LSP spec) ? I imagine we might be able to get rid of it ? It seems to me like code that uses the JDT model/ast would |
@rgrunber agree and we can remove the snippet from vscode-java |
Taking a look at this |
LGTM. The snippet has already been removed from vscode-java with redhat-developer/vscode-java#3253 and moved to JDT-LS with #2811. This made the "Surround with" feature much easier to use, as the user could simply highlight the text and prompt the try_catch snippet to surround with a try/catch block, rather than select it from the command palette. I think it's best to leave the snippet alongside this addition, as they are two different workflows but both equally convenient and useful. |
8b1cc80
to
d3508f2
Compare
Signed-off-by: lbrayner <lbrayner@users.noreply.github.com>
d3508f2
to
b1774c6
Compare
This PR adds a "Surround with try/catch" proposal to the
RefactorProcessor
. That way, one can surround a block of code (selection range) with a try/catch block. This is especially useful when one is guarding againstRuntimeException
s.The code in RefactorProcessor.getSurroundWithTryCatchProposal was based on
LocalCorrectionsSubProcessor.addUncaughtExceptionProposals
.