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

organize imports has conflict with prettier on "formatOnSave" #13

Open
sethyuan opened this issue Apr 9, 2020 · 4 comments
Open

organize imports has conflict with prettier on "formatOnSave" #13

sethyuan opened this issue Apr 9, 2020 · 4 comments

Comments

@sethyuan
Copy link

sethyuan commented Apr 9, 2020

The issue happens when prettier decides to format the import in a multi-line manner but organize imports want to format the same import as a single line.

@alfnielsen
Copy link
Owner

This is a know timing issue.
Unfortunately its really hard to fix.
Prettier always run before this and it will create multiline formatting.
and they (the prettier team) refuse to add options for single line!

After Prettier was run than this extension run, and the main issue is that vscode timeout the extension,
leaving the Prettier multiline. It's most clearly in large files that take longe time to process.

At the moment I dont really have a fix for this. :-/
(Please write on the Prettier issue - maybe if enough people write to them they will change their mind,
it an easy fix in their code base, but they argue that its a general decision that they dont wanna change..)

For most part this issue dont appear (The speed of your pc, how many other program your running and the size of your files all influence how often this happens )

@Nxt3
Copy link

Nxt3 commented Jan 27, 2021

If I want to keep multiline imports, how would I do that? It seems the organizer always keeps it as a single line even though I want multiline.

@karlhorky
Copy link

karlhorky commented Feb 15, 2021

@alfnielsen what about making a setting to format the same way as Prettier?

It's what the JS/TS Import/Export Sorter extension is adding over here: daidodo/format-imports-vscode#39

@stereokai
Copy link

FWIW I made a VSCode extension that can run a sequence of commands as a code action: Run commands as code actions

You can set a delay per command if necessary and enforce a "waterfall" of commands. Here is an example configuration:

  "editor.formatOnSave": false,
  "editor.codeActionsOnSave": [
    "source.organizeImports", // For example
    "source.runCommandsAsCodeActions.formatAndSave"
  ],
  "run-commands-as-code-actions.formatAndSave": [{
    "command": "prettier.forceFormatDocument",
    "delay": 0
  }, {
    "command": "tsImportSorter.command.sortImports",
    "delay": 400 // Shorter might also work, but this is safe
  }, {
    "command": "workbench.action.files.saveWithoutFormatting",
    "delay": 400 // Shorter might also work, but this is safe
  }],
  },

I wrote it to solve a longstanding Prettier issue with multi-line imports

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants