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

[Feature Request] Support java.cleanup.actions #279

Open
sainnhe opened this issue Apr 4, 2024 · 3 comments
Open

[Feature Request] Support java.cleanup.actions #279

sainnhe opened this issue Apr 4, 2024 · 3 comments

Comments

@sainnhe
Copy link

sainnhe commented Apr 4, 2024

At present, the setting java.cleanup.actionsOnSave is supported, which can run a set of cleanup actions on document save.

The upstream now supports java.cleanup.actions, which is triggered manually.

IMO cleanup actions is very necessary but in many cases should not be triggered on save, since some files are very low-level and should not be easily modified.

So vscode-java added a new setting that supported manually trigger cleanup acions: redhat-developer/vscode-java#3424

Is it possible to allow manually triggering in coc-java?

@asmodeus812
Copy link

@sainnhe try this 7741efb Let me know if it works for you, i did a few small tests, its added as a code command, not code action fyi.

@sainnhe
Copy link
Author

sainnhe commented May 27, 2024

@asmodeus812 Sorry for late reply. I'm too busy recently :(

I cannot find this commit in your fork, is the branch deleted?

I've looked into your code, there seems to be 2 problems:

  1. The command is not registered in package.json
  2. There is a configuration in vscode-java named java.cleanup.actions which has the following definition:
        "java.cleanup.actions": {
          "type": "array",
          "markdownDescription": "The list of clean ups to be run on the current document when it's saved or when the cleanup command is issued. Clean ups can automatically fix code style or programming mistakes. Click [HERE](command:_java.learnMoreAboutCleanUps) to learn more about what each clean up does.",
          "items": {
            "type": "string",
            "enum": [
              "qualifyMembers",
              "qualifyStaticMembers",
              "addOverride",
              "addDeprecated",
              "stringConcatToTextBlock",
              "invertEquals",
              "addFinalModifier",
              "instanceofPatternMatch",
              "lambdaExpressionFromAnonymousClass",
              "lambdaExpression",
              "switchExpression",
              "tryWithResource",
              "renameFileToType"
            ]
          },
          "default": [
            "renameFileToType"
          ],
          "scope": "window",
          "order": 10
        },

This setting can control what actions to be executed when doCleanup command is executed. Maybe it can also be added.

@sainnhe
Copy link
Author

sainnhe commented May 27, 2024

I implemented the doCleanup command and java.cleanup.actions setting based on your commit and the source code of vscode-java sainnhe@e838824

It works nicely on my machine. Would you mind merge my commit into your branch and open a PR?

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

No branches or pull requests

2 participants