Open Nxt3 opened 1 year ago
Thanks for the feedback!
You can set line wrapping style to be compatible with Prettier. More details: https://github.com/daidodo/format-imports/wiki/Line-Wrapping-Style#prettier-compatibility
Please tell me if you still have questions.
I already have this setting enabled: "tsImportSorter.configuration.wrappingStyle": "prettier"
and it doesn't seem to fix the problem. Can there be a setting to only sort/organize? Having this extension also handle formatting seems more problematic than it's worth given it can easily conflict with external formatting tools.
The correct output should be having those imports split across several lines. If I disable this extension and let prettier handle formatting, the code is formatted properly.
If I disable prettier and let this extension format the code, the output is incorrect with all of the imports on a single line, even with "tsImportSorter.configuration.wrappingStyle": "prettier"
Disabling eslint
has no effect on the formatting.
I had the "jumping around on every save" issue, and setting "tsImportSorter.configuration.wrappingStyle": "prettier"
fixed it for me. Thank you.
I had the "jumping around on every save" issue, and setting
"tsImportSorter.configuration.wrappingStyle": "prettier"
fixed it for me. Thank you.
In the above, I already have this setting and it hasn't fixed the issue.
The real fix here would be to remove formatting responsibilities from this extension and have it purely handle sorting.
I'm having this issue too and it's very frustrating.
remove formatting responsibilities
@Nxt3 How?
I don't have an answer to that. Someone needs to submit a PR with those changes. There isn't a fix for this currently.
Sorry for the late response!
The long-term solution is to migrate the extension to a Prettier plugin. But I don't have time ATM. I'd appreciate if anyone want to help.
Another workaround is to add the following settings with help of this extension:
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": [
"source.formatDocument",
"source.organizeImports.sortImports"
],
Unfortunately that doesn't solve the problem as it just makes TS Importer/Sorter the formatter for imports; if someone else working in your project doesn't have this VS Code extension, their Prettier will undo the formatting changes causing an unnecessary diff.
Did you try to swap the code actions so prettier can prevail?
"editor.codeActionsOnSave": [
"source.addMissingImports",
"source.organizeImports.sortImports",
"source.formatDocument", // prettier
"source.fixAll.eslint"
]
It still causes the imports to change formatting on every save.
I think I fixed this by adding another prettier call:
"editor.codeActionsOnSave": [
"source.addMissingImports",
"source.organizeImports.sortImports",
"source.formatDocument",
"source.formatDocument",
"source.fixAll.eslint"
],
I not longer have the jump in formatting.
It's frustrating. Thinking of uninstalling this extension, I'm afraid.
I think I came up with a better solution when compared to running formatDocument
twice.
Download this extension: stereokai.vscode-run-commands-as-code-actions
It allows us to add delays to code actions run on save so you can "waterfall" the commands.
Add this to your settings.json
:
"run-commands-as-code-actions.jsTsFormatAndLint": [
{
"command": "tsImportSorter.command.sortImports",
"delay": 100
},
{
"command": "prettier.forceFormatDocument",
"delay": 150
},
{
"command": "eslint.executeAutofix",
"delay": 200
},
{
"command": "workbench.action.files.saveWithoutFormatting",
"delay": 250
}
],
"[typescript]": {
// here's the magic
"editor.codeActionsOnSave": ["source.addMissingImports", "source.runCommandsAsCodeActions.jsTsFormatAndLint"],
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": false,
},
This will add missing imports, then run the actions defined under jsTsFormatAndLint
: Sort imports, format using prettier, eslint fix, and then save the file. This has been working great for me for a couple of weeks now.
Thanks for sharing, still a problem with the delays of 100, 150 or 200 - how will you know the previous action did really complete before starting the next one? Especially in large code bases.
Thanks for sharing, still a problem with the delays of 100, 150 or 200 - how will you know the previous action did really complete before starting the next one? Especially in large code bases.
The extension author could probably answer that better.
After months of working fine, I got this again (after moving some eslint config files around). Very frustrating. But then I restarted VSCode and it worked again. Shrug.
....and it happened again. I had to restart a couple of times before it worked correctly. My guess is that every time you start VS Code, the 'order' of extensions that can format-on-save changes, and you just have to keep restarting until Prettier beats this (or vv, which ever you prefer)
Describe the bug Auto Imports seems to be interfering with prettier formatting still. Might be related to https://github.com/daidodo/format-imports-vscode/issues/39
To Reproduce Format this file:
with following VS Code settings:
Expected behavior TS Import sorter should allow prettier to handle the formatting for line length.
Actual behavior Formatting for long lines jumps between formatted an unformatted.
Screenshots
OS (please complete the following information):
v7.5.1
VS Code (please complete the following information):
Installed VS Code extensions
.prettier.yml
.eslintrc.json