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

Provide 'clean build' quickfix #1440

Closed
wants to merge 4 commits into from
Closed

Conversation

jdneo
Copy link
Contributor

@jdneo jdneo commented May 13, 2020

Somehow mitigate redhat-developer/vscode-java#314
We can leverage the quickfix to help user discover the command clean build in more scenarios.

Step to validate

  • New a Type in source, meanwhile add related import statement
  • delete the imported class file
  • Change the document and save, this will trigger WorkspaceDiagnosticHnadler.resourceChanged()
  • trigger 'clean build' in quickfix to fix it.

demo

client: redhat-developer/vscode-java#1450

Signed-off-by: Sheng Chen [email protected]

// Add proposals related with project steup, like: clean build, clean workspace, etc...
switch(id) {
case IProblem.ImportNotFound:
CleanBuildSubProcessor.cleanBuildForUnresolvedImportProposals(context, problem, proposals);
Copy link
Contributor

Choose a reason for hiding this comment

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

please indent properly

if (type != null) {
ICompilationUnit compilationUnit = (ICompilationUnit) type.getAncestor(IJavaElement.COMPILATION_UNIT);
IClassFile cf = (IClassFile) type.getAncestor(IJavaElement.CLASS_FILE);
if (compilationUnit != null && cf == null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

you need to check if the client supports that command

@fbricon
Copy link
Contributor

fbricon commented May 13, 2020

test this please

@@ -639,5 +640,12 @@ private void process(IInvocationContext context, IProblemLocationCore problem, C
// }
// ConfigureProblemSeveritySubProcessor.addConfigureProblemSeverityProposal(context,
// problem, proposals);

// Add proposals related with project steup, like: clean build, clean workspace, etc...
Copy link
Contributor

Choose a reason for hiding this comment

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

setup

import org.junit.Test;

public class CleanBuildQuickFixTest extends AbstractQuickFixTest {

Copy link
Contributor

Choose a reason for hiding this comment

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

need test when(clientPreferences.isClientBuildCommandSupported()).thenReturn(false);

@jdneo
Copy link
Contributor Author

jdneo commented May 15, 2020

@fbricon Want to listen your suggestion about this: When we detect that an unresolvable import is caused by missing .class file. Should be provide the quickfix as this PR shows, or directly trigger full build automatically?

Follow-up question: If we choose to way to provide quickfix, the current relevance value (0) is suitable or not? Personally I prefer to put this quickfix at a higher position.

@fbricon
Copy link
Contributor

fbricon commented May 15, 2020

or directly trigger full build automatically?

No! it's a surefire way to end up with infinite build loop!

Follow-up question: If we choose to way to provide quickfix, the current relevance value (0) is suitable or not? Personally I prefer to put this quickfix at a higher position.

No, this quickfix is a hack, this is a last resort measure so should have the lowest relevance IMO

@jdneo
Copy link
Contributor Author

jdneo commented May 15, 2020

@fbricon I see, make sense.

@fbricon
Copy link
Contributor

fbricon commented May 15, 2020

Doesn't work if the missing class is from the same package, so there's no import error

@fbricon
Copy link
Contributor

fbricon commented May 15, 2020

The fact the code action only shows up on import statements definitely feels confusing

@jdneo
Copy link
Contributor Author

jdneo commented May 16, 2020

@fbricon This is to open the chances to help users setup their projects. We can definitely add more scenarios like missing class is from the same package

@fbricon
Copy link
Contributor

fbricon commented May 18, 2020

Can we do the following: if type is missing (import or otherwise), then check project's source directories (then dependency projects' source directories), find if there's an existing matching foo/bar/Type.java, THEN, propose the code action

@jdneo
Copy link
Contributor Author

jdneo commented May 19, 2020

@fbricon Yes, that's much better than current solution! Let me think more about how to better expose this command. I'm now having the same feeling that put it in the quickfix might not be a good idea...

@jdneo
Copy link
Contributor Author

jdneo commented Jun 10, 2020

Close it for now...

@jdneo jdneo closed this Jun 10, 2020
@jdneo jdneo deleted the cs/build branch March 12, 2021 12:33
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.

2 participants