withastro / language-tools

Language tools for Astro
MIT License
240 stars 45 forks source link

🐛 BUG: Moving files results in formatting issues in Svelte files #869

Closed danielo515 closed 1 month ago

danielo515 commented 1 month ago

Describe the Bug

When I move a svelte file that contains some typescript definitions, like an interface for example, many times the code gets messed, and if you undo, it will not go back to it's original state. This seems to be related to a bug in refactoring imports, because it happens when the language server tries to correct the imports.

Steps to Reproduce

  1. npm init astro
  2. add svelte integration
  3. create a svelte file with imports
  4. Move the file to a nested folder or to a parent folder
  5. The code gets broken

This happens in VSCode by the way, not sure about other usages of the language server

Princesseuh commented 1 month ago

This extension does not run inside Svelte files. Is it the code inside the Svelte files that get messed up?

danielo515 commented 1 month ago

Yes, it also breaks autocompletion in svelte files. The extension may not directly deal with svelte files, but if I disable it then the problem goes away


https://danielorodriguez.com

On Sun, 12 May 2024 at 08:02, Erika @.***> wrote:

This extension does not run inside Svelte files. Is it the code inside the Svelte files that get messed up?

— Reply to this email directly, view it on GitHub https://github.com/withastro/language-tools/issues/869#issuecomment-2106131715, or unsubscribe https://github.com/notifications/unsubscribe-auth/AARKJWO3WFK3W63AN37GJVDZB4AXXAVCNFSM6AAAAABHSOJ5T6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMBWGEZTCNZRGU . You are receiving this because you authored the thread.Message ID: @.***>

Princesseuh commented 1 month ago

Does it break auto completions or does it break what you described in the first post?

danielo515 commented 1 month ago

It breaks automatic imports and refactors. Suggestions do work (but very bad)


https://danielorodriguez.com

On Sun, 12 May 2024 at 19:05, Erika @.***> wrote:

Does it break auto completions or does it break what you described in the first post?

— Reply to this email directly, view it on GitHub https://github.com/withastro/language-tools/issues/869#issuecomment-2106316195, or unsubscribe https://github.com/notifications/unsubscribe-auth/AARKJWNPTWTC4NFLAJSQ3Q3ZB6OOXAVCNFSM6AAAAABHSOJ5T6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMBWGMYTMMJZGU . You are receiving this because you authored the thread.Message ID: @.***>

Princesseuh commented 1 month ago

It seems to be some sort of conflict between the Svelte TypeScript plugin and the Astro one. It seems like both plugins are trying to do the refactor at the same time and so it ends up generating broken code. For what it's worth, you can actually undo the changes if you undo the move, and not the latest change. The LSPs are doing it correctly, as far as I can tell, just the TypeScript plugins.

I cannot reproduce a difference regarding auto imports / completions with or without the Astro plugin, so not sure on that one. Since auto imports in the respective files would be handled by the LSPs, I'm not sure how the Astro extension could affect the Svelte one in that regard.

Princesseuh commented 1 month ago

This should be fixed in 2.9.1. Apologies for the inconvenience. If you have the time and would like to, I would appreciate if you updated your review on the VS Code marketplace to reflect this.

danielo515 commented 1 month ago

That is awesome! Thank you very much. I will update it, sorry about it. I wrote it in a moment where I was very frustrated

Princesseuh commented 1 month ago

No worries, it happens! We're all humans here