neoclide/coc-java

[Feature Request] Support java.cleanup.actions

sainnhe opened this issue · 3 comments

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?

@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.

@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.

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?