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

Run custom command in editor.codeActionsOnSave #109500

Closed
felipecrs opened this issue Oct 27, 2020 · 5 comments
Closed

Run custom command in editor.codeActionsOnSave #109500

felipecrs opened this issue Oct 27, 2020 · 5 comments
Assignees
Labels
editor-code-actions Editor inplace actions (Ctrl + .) *extension-candidate Issue identified as good extension implementation

Comments

@felipecrs
Copy link
Contributor

felipecrs commented Oct 27, 2020

So, I could do something like:

"[shellscript]": {
    "editor.defaultFormatter": "foxundermoon.shell-format",
    "editor.codeActionsOnSave": {
      "command": "argbash -i ${relativeFile}"
    }
  },

PS: I'm talking about a shell command, not a VSCode command.

I can think of 3 approaches:

  1. Support calling VSCode commands (so we can call a task)
  2. Support calling tasks (so we can set a task which run that command)
  3. Support calling commands

I think the first is the best one since it would extend to many possibilities.

@jrieken jrieken assigned mjbvz and unassigned jrieken Oct 27, 2020
@mjbvz mjbvz added the *extension-candidate Issue identified as good extension implementation label Oct 27, 2020
@mjbvz
Copy link
Collaborator

mjbvz commented Oct 27, 2020

This like a good candidate for an extension that converts tasks/commands into source actions.

If that proves popular, we could look into integrating it into VS Code

@mjbvz mjbvz added the editor-code-actions Editor inplace actions (Ctrl + .) label Oct 27, 2020
@felipecrs
Copy link
Contributor Author

I was able to successfully create an extension to transform tasks into source code actions, and therefore be able to use them in codeActionsOnSave.

However, there is a challenge:

The command which the task runs changes the document contents, therefore it triggers a VS Code error:

dhBDM1eRSZ

Is there a way to work around this?

@mjbvz
Copy link
Collaborator

mjbvz commented Nov 11, 2020

Looks like your task writes to disk before the file is written by VS Code. Try delaying your task until the save has completed

@felipecrs
Copy link
Contributor Author

felipecrs commented Nov 11, 2020

But in fact, I need the formatter (formatOnSave) to actually run after the task. =/

Just like how the formatOnSave was intended to run after all the codeActionsOnSave.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
editor-code-actions Editor inplace actions (Ctrl + .) *extension-candidate Issue identified as good extension implementation
Projects
None yet
Development

No branches or pull requests

4 participants
@jrieken @mjbvz @felipecrs and others