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

Is it possible to add to Format Document? #3

Open
deakjahn opened this issue Sep 15, 2022 · 5 comments
Open

Is it possible to add to Format Document? #3

deakjahn opened this issue Sep 15, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@deakjahn
Copy link

Does VS Code allow the plugin to be linked to whatever code formatter you use with Format Document? It would be nice to do it in one step. I'm not sure it's possible but it would be very comfortable.

Yes, I'm aware of the possibility to do it on save but that doesn't work with auto save functionality added (it removes items before you get a chance to edit them).

@tarik02
Copy link
Owner

tarik02 commented Sep 15, 2022

Hello. Yes, vscode allows extensions to register document formatters: https://code.visualstudio.com/api/references/vscode-api#DocumentFormattingEditProvider

But there's still a caveat that you can use only one formatter for document (they're sorted by score).

Will add this feature to TODOs.

@tarik02 tarik02 added the enhancement New feature or request label Sep 15, 2022
@deakjahn
Copy link
Author

deakjahn commented Sep 15, 2022

That won't really help then... I was thinking about adding it as a second step after my current formatter (which is Intelephense; actually, I saw you mention the question of use imports about a year ago or so in the issue queue there, I guess you made this plugin just because Intelephense doesn't offer it by itself).

@tarik02
Copy link
Owner

tarik02 commented Sep 15, 2022

Than won't really help then... I was thinking about adding it as a second step after my current formatter (which is Intelephense; actually, I saw you mention the question of use imports about a year ago or so in the issue queue there, I guess you made this plugin just because Intelephense doesn't offer it by itself).

I can suggest you to use a command or assign a hotkey to command to format imports then.

Also, I found that there is special code action for organizing imports in vscode API (CodeActionKind.SourceOrganizeImports) which should be actually implemented by this extension.

@deakjahn
Copy link
Author

That's what I do but I have two shortcuts then, one for formatting the document, another one for yours.

Come to think of it, what if you provided one more entry point in your plugin that calls whatever source formatter is currently defined in VSCode, and then call your own formatter? Then we could kill two birds with one stone...

@deakjahn
Copy link
Author

A little Googling revealed that we can create tasks in VSC to perform consecutive tasks. So I created this to perform both actions:

{
  // See https://go.microsoft.com/fwlink/?LinkId=733558
  // for the documentation about the tasks.json format
  "version": "2.0.0",
  "tasks": [
    {
      "label": "cmd-mine-format-1",
      "command": "${command:vscode-php-imports.format}"
    },
    {
      "label": "cmd-mine-format-2",
      "command": "${command:editor.action.formatDocument}"
    },
    {
      "label": "cmd-mine-format",
      "dependsOrder": "sequence",
      "dependsOn": [
        "cmd-mine-format-1",
        "cmd-mine-format-2"
      ],
      "problemMatcher": []
    }
  ]
}

This is just fine for me now but still, you might possibly consider the idea above. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants