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

Add magic number quick fix #293

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

karlvr
Copy link
Contributor

@karlvr karlvr commented Jan 12, 2021

I think this will conflict with the other quick fix when merged. I'm happy to rebase this PR when the time comes. I might do other quick fixes together in one PR, assuming that you're generally happy with any additional quick fix implementations!

@jdneo
Copy link
Owner

jdneo commented Jan 12, 2021

😃 Thanks for all the great contributions! I'll try my best to review them when I have time.

Just feel free to send PRs if you want. I would suggest one quick fix per PR, it will be easier for me to review

@jdneo jdneo added this to the 1.4.0 milestone Jan 13, 2021
@jdneo
Copy link
Owner

jdneo commented Jan 13, 2021

Great work!

While reviewing this PR. I found a new problem which is on the Java Language server side maybe.

I found that when the Checkstyle extension is disabled. User can find refactors like extract to constant at the code like Thread.sleep(1000).

But when the Checkstyle extension is enabled and report the magic number violation, refactors like extract ... from the Java Language Server disappear when right click on the 1000.

I'm now trying to figure out the root cause.

@karlvr
Copy link
Contributor Author

karlvr commented Jan 13, 2021

@jdneo It would be great, by the by, to be able to trigger the extract to constant command. Or actually, it feels like once we've recovered the extract to constant quick fix that we don't need a magic number quick fix at all!

@jdneo
Copy link
Owner

jdneo commented Jan 13, 2021

Ok it turns out that the code here: https://github.com/eclipse/eclipse.jdt.ls/blob/master/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/corrections/RefactorProcessor.java#L140

It skips a lot of refactors when the location has errors, but it does not check the source(reporter) of the errors.

So a fix could be, we need to take the error sources into consideration (This information is contained in the LSP body). Only consider it as errored when it do have errors come from the Java Language Server itself.

I'll raise a PR to fix this in the Language Server side.

it feels like once we've recovered the extract to constant quick fix that we don't need a magic number quick fix at all!

Yes the extract to constant refactor can definitely solve the magic number violation (I guess that's why the Eclipse Checkstyle plugin does not have such quickfix). One potential gap is that, the extract to constant is in the refactor list instead of the quickfix list. So the user can only find it in the yellow bulb, but no linked quickfix for this error.

image

@jdneo
Copy link
Owner

jdneo commented Jan 13, 2021

Here it is: eclipse-jdtls/eclipse.jdt.ls#1643

@karlvr
Copy link
Contributor Author

karlvr commented Jan 13, 2021

@jdneo great investigation. If it's practical to trigger the refactor from the checkstyle plugin, maybe that's how to implement this quick fix. I have no idea whether that's possible!

@jdneo
Copy link
Owner

jdneo commented Jan 14, 2021

@karlvr Seems not because the quickfix and refactor are two different kinds of Code Actions in VS Code, so probably no way to link them.

My suggestion is wait a little bit before we add the magic number quick fix into the extension. If we see more users request for this support, that can be a good chance to merge this PR. What do you think?

@karlvr
Copy link
Contributor Author

karlvr commented Jan 14, 2021

@jdneo I'm absolutely happy with that... it's a shame that we can't trigger the refactor. Maybe that's another enhancement to the bigger Java project to expose its functionality for other extensions to trigger :-) Definitely outside of my desired scope.

@jdneo jdneo modified the milestones: 1.4.0, Backlog Jan 14, 2021
@jdneo
Copy link
Owner

jdneo commented Jan 14, 2021

Mark this PR to backlog for now.

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

Successfully merging this pull request may close these issues.

2 participants