Skip to content

Improve code actions#3322

Merged
rgrunber merged 1 commit intoeclipse-jdtls:masterfrom
snjeza:issue-3321
Nov 19, 2024
Merged

Improve code actions#3322
rgrunber merged 1 commit intoeclipse-jdtls:masterfrom
snjeza:issue-3321

Conversation

@snjeza
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

snjeza commented Nov 7, 2024

Test this please

// 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

@snjeza
Copy link
Copy Markdown
Contributor Author

snjeza commented Nov 12, 2024

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

snjeza commented Nov 13, 2024

Test this please.

Copy link
Copy Markdown
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 <snjezana.peco@redhat.com>
@snjeza
Copy link
Copy Markdown
Contributor Author

snjeza commented Nov 16, 2024

test this please

@rgrunber
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
mfussenegger added a commit to mfussenegger/nvim-jdtls that referenced this pull request Jan 23, 2025
There were changes to no longer provide the `signature` within the
code-action command arguments but instead require an additional request
from the client.

See:
- eclipse-jdtls/eclipse.jdt.ls#3322
- redhat-developer/vscode-java#3845

Closes: #743
mfussenegger added a commit to mfussenegger/nvim-jdtls that referenced this pull request Jan 23, 2025
There were changes to no longer provide the `signature` within the
code-action command arguments but instead require an additional request
from the client.

See:
- eclipse-jdtls/eclipse.jdt.ls#3322
- redhat-developer/vscode-java#3845

Closes: #743
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