AstroNvim / astrocommunity

A community repository of common plugin specifications
GNU General Public License v3.0
1.08k stars 222 forks source link

typescript pack formatting is broken #974

Closed MrMic closed 2 months ago

MrMic commented 2 months ago

Checklist

Neovim version (nvim -v)

0.10.0

Operating system/version

Linux Ubuntu 22.04

Terminal/GUI

kitty

Describe the bug

For a couple of days, the formatting with Javascript is broken. I think it is an issue with prettier and/or eslint. Everything is working with VS Code and Helix... I saw few days ago that prettier was updated/upgraded and this broke the formatting. Everything was OK before.

Capture d’écran du 2024-05-18 13-08-05

Steps to Reproduce

When I save a file, formatting failed

Expected behavior

formatting

Screenshots

see above

Additional Context

No response

Uzaaft commented 2 months ago

Do you have any custom logic locally?

Uzaaft commented 2 months ago

This has been raised earlier @MrMic. Not sure what's causing this, but I can't reproduce locally. All LSP's are up to date. Basic template + typescript pack.

Uzaaft commented 2 months ago

What do you mean with "broken" @MrMic. Broken as in non-functional, or broken as in wrong formatting?

MrMic commented 2 months ago

No custom logic. LSP is OK. The issue is with formatting, which does not work at all with JS / TS. All was working fine around 10 or 15 days ago. And then, I saw an update/upgrade and the formatting went wrong. And now, it is not working at all!

When I save JS file I got this notification error: Error detected while processing BufWritePre Autocommands for ""

MrMic commented 2 months ago

Moreover when I install prettier in my project Dev Dependencies: $> npm install --save-dev --save-exact prettier and run: $> npx prettier . --write Everything works as expected... I mean formatted.

Skarian commented 2 months ago

This is a significant issue. I am having the same problem, formatting completely broken in JS/TS.

Uzaaft commented 2 months ago

I Wonder if this is due to prettierd

MrMic commented 2 months ago

I think so. This bug happens when prettier was updated/upgraded a couple of days ago.

Uzaaft commented 2 months ago

I'll take a look and try and debug this, but no promises on a timeline. Feel free to also investigate the issue and come up with a fix. I'm very pressed on times nowadays @Skarian @MrMic

vadimshvetsov commented 2 months ago

Today I've updated AstroNvim and formatting was completely broken for all my TS projects. I have some easy repro steps:

So the first file save is always ok, but the second is always shifting all the contents to the start of line. image

MrMic commented 2 months ago

Today I've updated AstroNvim and formatting was completely broken for all my TS projects. I have some easy repro steps:

  • Start new app with create-next-app with TailwindCSS (didn't test without)
  • Create new AstroNvim config and add community packages:
return {
  "AstroNvim/astrocommunity",
  { import = "astrocommunity.pack.tailwindcss" },
  { import = "astrocommunity.pack.typescript" },
}
  • Go to src/app/page.tsx file and save - everything will be fine
  • Go to the next file src/app/layout.tsx and save - everything will be shifted to the line start.

So the first file save is always ok, but the second is always shifting all the contents to the start of line. image

Got the same issue!

Uzaaft commented 2 months ago

@vadimshvetsov Feel free to help us in fixing this.

vadimshvetsov commented 2 months ago

I removed the tailwindcss pack and reproduced the issue, so it looks like the problem is somewhere in the typescript pack. It looks like wrong formatting is produced by prettierd, and the weird thing is that the first opened and saved file will be formatted correctly.

Uzaaft commented 2 months ago

We've already established that.

Uzaaft commented 2 months ago

I checked the two latest commits to the typescript pack, and those didn't break anything

MrMic commented 2 months ago

I saw the update of prettier a couple of days ago (10 or 15 days) and it was for the core of Astronvim not with the community packages. If I remember well. And from this point on I got issues with formatting.

vadimshvetsov commented 2 months ago

I've rollbacked to my previous lock file and updated just astrocommunity to 8.5 and can't see any issue with formatting. I'll update packages one by one and will find which one causes the issue.

vadimshvetsov commented 2 months ago

I've updated astrocore and astrolsp without any issue. But once I update AstroNvim 4.2 -> 4.7.5 I can see the issue. I'll figure out exact version next.

vadimshvetsov commented 2 months ago

To those who are blocked by this issue, you can change either the version in lazy-lock.json:

  "AstroNvim": { "branch": "main", "commit": "0f875f4a7f1963d6c61eb564cadb8e556e406dd5" },

After opening nvim, just run :Lazy restore, and it will pick up the last working formatting version.

Or directly set shiftwidth back to 2 or 4 depending on preference before opening any file or in config.

This issue appeared right after the commit that came with AstroNvim 4.5.1: AstroNvim/AstroNvim@f3dbb86 (PR)

Uzaaft commented 2 months ago

Wait. That shouldn't, if I'm thinking correctly, affect the prettier stuff

Uzaaft commented 2 months ago

Prettier should override that anyways since it has its own prefered logic for tabs/spaces.

vadimshvetsov commented 2 months ago

I've updated all my packages back to the latest and just put :set shiftwidth=2 - its working perfectly now for me 🤷‍♂️

Checked with latest create-next-app also.

vadimshvetsov commented 2 months ago

I guess prettier ignores tabWidth setting somehow.

Uzaaft commented 2 months ago

I think this just exposes an underlying issue with the prettier/prettierd and neovim.

Uzaaft commented 2 months ago

Issue is upstream: https://github.com/pmizio/typescript-tools.nvim/pull/270

MrMic commented 2 months ago

I notice an update but I still have no formatting and null-ls seems to get stuck at the bottom right corner of the UI.

Capture d’écran du 2024-05-23 14-14-16

Uzaaft commented 2 months ago

Issue is resolved for me with a basic template + typescript pack. nothing else init.

Uzaaft commented 2 months ago

I think this issue is proof that we should move away from typescript-tools.nvim to vtsls lsp instead.

mehalter commented 2 months ago

This should be fixed now that we have moved to vtsls. Let me know if this should be reopened.

MrMic commented 2 months ago

Not OK for me! Sorry. null-ls seems to be stuck with prettierd

Capture d’écran du 2024-05-24 14-12-52

Capture d’écran du 2024-05-24 14-12-23

Uzaaft commented 2 months ago

Make sure to update your dependencies @MrMic . It's working fine for me now

MrMic commented 2 months ago

Make sure to update your dependencies @MrMic . It's working fine for me now

What do you mean by "dependencies"? All my packages are up-to-date. I press "pa"...

mehalter commented 2 months ago

Also open Mason and make sure to uninstall tsserver

MrMic commented 2 months ago

Also open Mason and make sure to uninstall tsserver

I did it again. And it has been installed again but I still have the same issue... tsserver works perfectly fine, it is an issue with prettier(d) and formatting. One or 2 weeks ago I saw updates for prettier and since then I got issues.

mehalter commented 2 months ago

Well you shouldn't see tsserver at all in the latest update 😅 so it shouldn't be working at all haha . Can you share an example project that's throwing the error and steps to replicate.

MrMic commented 2 months ago

I see it when I open my project... Anyway, here it is: https://github.com/MrMic/NextJS-14-S04_NEW.git

BTW: When I work with VS Code on it I have no issue at all!

mehalter commented 2 months ago

It would definitely be strange if you got a null-ls error message in vs code 😂

Uzaaft commented 2 months ago

@MrMic delete your plugins and try again.

Uzaaft commented 2 months ago

I.e the lazy cache folder

MrMic commented 2 months ago

I.e the lazy cache folder

Where is it located? (on linux)

Uzaaft commented 2 months ago

I've send you it before 😐

rm -rf ~/.cache/nvim
rm -rf ~/.local/share/nvim
rm -rf ~/.local/state/nvim

Also: List time you had a bug in a plugin, you "...deleted and reinstalled the plugin, and this solved my issue... weird." Whatever that meant, try that as well.

mehalter commented 2 months ago

@MrMic I don't have any issues formatting that project, also it correctly only attaches vtsls and eslint, it doesn't add prettier at all. Can you share your config? You might have a bug on your end

MrMic commented 2 months ago

I've send you it before 😐

rm -rf ~/.cache/nvim
rm -rf ~/.local/share/nvim
rm -rf ~/.local/state/nvim

Also: List time you had a bug in a plugin, you "...deleted and reinstalled the plugin, and this solved my issue... weird." Whatever that meant, try that as well.

Done. But I still have this issue...

MrMic commented 2 months ago

@MrMic I don't have any issues formatting that project, also it correctly only attaches vtsls and eslint, it doesn't add prettier at all. Can you share your config? You might have a bug on your end

https://github.com/MrMic/astronvim_v4.git

mehalter commented 2 months ago

I get a 404, that might be private

MrMic commented 2 months ago

I get a 404, that might be private

Yes indeed. Should be public now for some time...

mehalter commented 2 months ago

Ok, I found the error. Investigating now.

Uzaaft commented 2 months ago

Ok, I found the error. Investigating now.

Seems to be a reccuring thing with your config @MrMic 😂

mehalter commented 2 months ago

Ok @MrMic , AstroNvim v4.7.7 should resolve the specific error message you are getting, but there are still a lot of issues with your configuration. I will make a PR with a few fixes I found immediately, but I haven't really gone through it with a fine tooth comb

mehalter commented 2 months ago

Ok, I opened a PR on your config. Hopefully it all makes sense. God speed!

https://github.com/MrMic/astronvim_v4/pull/1