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

Improve code actions #3322

Merged
merged 1 commit into from
Nov 19, 2024
Merged

Improve code actions #3322

merged 1 commit into from
Nov 19, 2024

Conversation

snjeza
Copy link
Contributor

@snjeza snjeza commented Nov 6, 2024

Fixes #3321
Requires redhat-developer/vscode-java#3845

I have configured code actions in a similar way Eclipse does it.
Test vsix: https://github.com/snjeza/vscode-test/raw/refs/heads/master/java-1.38.5.vsix

@snjeza snjeza force-pushed the issue-3321 branch 2 times, most recently from 8606a1d to b5e88fe Compare November 7, 2024 00:07
@snjeza
Copy link
Contributor Author

snjeza commented Nov 7, 2024

@rgrunber @fbricon @mickaelistria @testforstephen @jdneo @robstryker Please see b5e88fe#diff-56e3932686a1ea3ebee6857099f5fe41a37cb3ef5f85ebceac12df645c0b053aR435
Eclipse shows the Inline Local Constantrefactoring at

public class E {
    public void foo(String[] parameters, int j) {
        int temp = parameters.length + j;
        int |temp1 = temp;
        System.out.println(temp);
    }
}

and the following dialog
3322

@snjeza
Copy link
Contributor Author

snjeza commented Nov 7, 2024

Test this please

@@ -334,15 +398,27 @@ private boolean getInlineProposal(IInvocationContext context, ASTNode node, Coll
// Inline Constant (static final field)
if (RefactoringAvailabilityTesterCore.isInlineConstantAvailable((IField) varBinding.getJavaElement())) {
InlineConstantRefactoring refactoring = new InlineConstantRefactoring(context.getCompilationUnit(), context.getASTRoot(), context.getSelectionOffset(), context.getSelectionLength());
if (refactoring != null && refactoring.checkInitialConditions(new NullProgressMonitor()).isOK() && refactoring.getReferences(new NullProgressMonitor(), new RefactoringStatus()).length > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, so with this, we correctly defer these calculations to resolve right ? I noticed ChangeCorrectionProposalCore.getChange() only gets called from codeAction/resolve. That would definitely improve things both for javac and ecj.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice, so with this, we correctly defer these calculations to resolve right

Do you want me to defer Inline Constant, too?
I should change InlineVariableTest.testInlineLocalVariableWithNoReference -

public void testInlineLocalVariableWithNoReferences() throws Exception {

Copy link
Contributor

@rgrunber rgrunber Nov 12, 2024

Choose a reason for hiding this comment

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

I guess the issue is that checkInitialConditions is what determines whether there are any references to inline, but by defering it to codeAction/resolve, you end up showing the dialog in cases where it would have been hidden. It seems like a small price to pay for improving performance though, and it's not horribly wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess the issue is that checkInitialConditions is what determines whether there are any references to inline,

Right.

but by defering it to codeAction/resolve, you end up showing the dialog in cases where it would have been hidden. It seems like a small price to pay for improving performance though, and it's not horribly wrong.

We can solve it in a separate issue. The dialog requires a client update.

Copy link
Contributor

@rgrunber rgrunber left a comment

Choose a reason for hiding this comment

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

Looks pretty good overall. Just need to review that "change signature part".

@snjeza
Copy link
Contributor Author

snjeza commented Nov 12, 2024

Looks pretty good overall. Just need to review that "change signature part".

You have to use redhat-developer/vscode-java#3845 or try https://github.com/snjeza/vscode-test/raw/refs/heads/master/java-1.38.3.vsix

@snjeza
Copy link
Contributor Author

snjeza commented Nov 13, 2024

Test this please.

Copy link
Contributor

@rgrunber rgrunber left a comment

Choose a reason for hiding this comment

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

Overall, looks pretty good. Just one issue I found with the "Introduce Parameter" seeming to permit things that it later denies.

Signed-off-by: Snjezana Peco <[email protected]>
@snjeza
Copy link
Contributor Author

snjeza commented Nov 16, 2024

test this please

@rgrunber
Copy link
Contributor

rgrunber commented Nov 19, 2024

Just from testing on lemminx with triggering code actions on XMLLanguageServer.initialize()

Before (javac)

[Trace - 12:44:42] Received response 'textDocument/codeAction - (310)' in 2629ms.
[Trace - 12:44:46] Received response 'textDocument/codeAction - (315)' in 2263ms.
[Trace - 12:44:51] Received response 'textDocument/codeAction - (317)' in 2336ms.
[Trace - 12:44:56] Received response 'textDocument/codeAction - (319)' in 2315ms.
[Trace - 12:45:01] Received response 'textDocument/codeAction - (321)' in 2336ms.

After (javac)

[Trace - 12:51:40] Received response 'textDocument/codeAction - (49)' in 99ms.
[Trace - 12:51:43] Received response 'textDocument/codeAction - (54)' in 103ms.
[Trace - 12:51:46] Received response 'textDocument/codeAction - (56)' in 97ms.
[Trace - 12:51:48] Received response 'textDocument/codeAction - (58)' in 129ms.
[Trace - 12:51:50] Received response 'textDocument/codeAction - (60)' in 109ms.

🧑‍💻 ⬅️ 🕶️

Copy link
Contributor

@rgrunber rgrunber left a comment

Choose a reason for hiding this comment

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

Overall, I think this is ready to be merged. It will definitely improve the code action performance, and given that it gets triggered per cursor re-location, it should free up the worker threads for other computations.

@snjeza , what's the situtation with the unit.reconcile(..) issue ? Is there anything to do there at a later time ?

@snjeza
Copy link
Contributor Author

snjeza commented Nov 19, 2024

what's the situtation with the unit.reconcile(..) issue ? Is there anything to do there at a later time ?

We can't do anything.

@rgrunber rgrunber merged commit 839831f into eclipse-jdtls:master Nov 19, 2024
6 of 7 checks passed
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.

Improve code actions
4 participants