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

🐛 Import sorting breaks with a particular import line when saving in VSCode #1570

Open
1 task done
jpike88 opened this issue Jan 16, 2024 · 41 comments
Open
1 task done
Assignees
Labels
A-LSP Area: language server protocol S-Bug-confirmed Status: report has been confirmed as a valid bug

Comments

@jpike88
Copy link

jpike88 commented Jan 16, 2024

Environment information

CLI:
  Version:                      1.5.1
  Color support:                true

Platform:
  CPU Architecture:             aarch64
  OS:                           macos

Environment:
  BIOME_LOG_DIR:                unset
  NO_COLOR:                     unset
  TERM:                         "xterm-256color"
  JS_RUNTIME_VERSION:           "v18.17.1"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         "npm/9.6.7"

Biome Configuration:
  Status:                       Loaded successfully
  Formatter disabled:           true
  Linter disabled:              false
  Organize imports disabled:    false
  VCS disabled:                 true

Workspace:
  Open Documents:               0

Biome VSCode extension version v2.1.1

What happened?

With organizeImports enabled and this config in workspace:

"editor.codeActionsOnSave": {
			"quickfix.biome": "explicit",
			"source.organizeImports.biome": "explicit"
		},

just add this particular import line to any script that has a bunch of existing imports.

import {MaxInteger32Value } from '@shared/MaxInteger32Value';

Minimal reproducible case below:

import {MaxInteger32Value } from '@shared/MaxInteger32Value';
import { a } from '@a';
import { b } from '@b';

Something about this particular string causes havoc by duplicating it, and replacing existing import lines below it. See screenshot

This only happens in VSCode, I can't reproduce it on the playground.

Expected result

Screenshot 2024-01-16 at 11 11 41 AM

Code of Conduct

  • I agree to follow Biome's Code of Conduct
@jpike88
Copy link
Author

jpike88 commented Jan 16, 2024

Seems to be problematic in this case too:

import { d } from '@dd';
import { a } from '@a';
import { b } from '@b';

But not in this:

import { d } from 'dd';
import { a } from '@a';
import { b } from '@b';

The @ symbol seems to be the reason here.

@ematipico
Copy link
Member

Can you share a playground link?

@jpike88
Copy link
Author

jpike88 commented Jan 16, 2024

I can't repro on playground, just vscode

@ematipico
Copy link
Member

Then you'll have to share a reproduction. This will help us to identify the issue

@ematipico ematipico added the S-Needs repro Status: needs a reproduction label Jan 16, 2024
@kainosnoema
Copy link

source.organizeImports.biome breaks for me in VSCode constantly. It sometimes eats multiple lines of code and then spits out repeated import lines probably due to competing with source.addMissingImports? I've had to disable source.organizeImports.biome entirely since I just can't get it to work consistently without breaking code.

I don't have a working reproduction offhand since it seems to have to do with combination of quickfix.biome, source.organizeImports.biome, and source.addMissingImports, but will try to replicate it next time I see it.

@kainosnoema
Copy link

kainosnoema commented Jan 16, 2024

@ematipico here's a simple reproduction showing the issue I'm having (maybe not related?):

Before save (swapped imports to be out of order)
Screenshot 2024-01-16 at 11 56 53 PM
After save
Screenshot 2024-01-16 at 11 57 04 PM

Settings
Screenshot 2024-01-16 at 11 58 29 PM

fwiw I also just tried disabling source.addMissingImports and got the same result, so this seems like a bug isolated to source.organizeImports.biome. Update: interestingly restarting VSCode or resetting the extension host seems to fix things temporarily, so the example above works again until it starts breaking and then I can reproduce it consistently until I restart again. Maybe there's some sort of corrupted internal state of either VSCode or the extension?

@ematipico
Copy link
Member

ematipico commented Jan 17, 2024

Sorry @kainosnoema , this isn't a reproduction.

We need to be able to reproduce the issue. A repository would be great.

Without that , we can't help.

@arendjr
Copy link
Contributor

arendjr commented Jan 17, 2024

I’ll try enabling source.organizeImports.biome in my setup, see if I run into it.

@jansedlon
Copy link

Yeah, same issue here. It randomly happens as well. Reloading VSCode works. Sometimes the imports completely disappears, sometimes it completely changes
image

@g-pex-aerian
Copy link

I have also been experiencing this issue. It seems to be because there is many Biome agents running and happens if I have left my Mac on overnight. If I hover over a Biome warning or error I can see the error repeated, sometimes 20 times.

Closing VSCode completely does fix the issue and Biome suggestions are no longer duplicated.

So I would suggest the issue is with Biome seemingly restarting without killing the previous process for some reason?

@arendjr
Copy link
Contributor

arendjr commented Jan 17, 2024

I wonder to what extent this issue and #1584 are related. I'm getting the impression both situations may be caused by having too many daemons running.

As far as I see, I also only see Mac users in these threads. So if there's a non-Mac user experiencing this, please raise your voice, since it might help us figure out in which direction to look.

@ematipico ematipico added A-LSP Area: language server protocol S-Bug-confirmed Status: report has been confirmed as a valid bug and removed S-Needs repro Status: needs a reproduction labels Jan 18, 2024
@Conaclos Conaclos changed the title 🐛 Import sorting breaks with a particular import line when savin in VSCode 🐛 Import sorting breaks with a particular import line when saving in VSCode Jan 18, 2024
@ematipico
Copy link
Member

We just published a nightly with a possible fix: https://github.com/biomejs/biome/releases/tag/cli/v1.5.2-nightly.91c7730

It would be great if someone can try it, and let us know.

@jpike88
Copy link
Author

jpike88 commented Jan 24, 2024

Still a problem on 1.5.3

@jansedlon
Copy link

Hasn't happened to me since 1.5.2-dev and 1.5.3 🤔

@jpike88
Copy link
Author

jpike88 commented Jan 24, 2024

I'm not sure how or why... but disabling reenabling plugin seemed to work afterwards... I'll keep you posted

@ematipico
Copy link
Member

Thank you all for confirming.

For anyone coming here , to apply the fix you must restart your VSCode after updating to Biome 1.5.3. There was an issue in the LSP.

@arendjr
Copy link
Contributor

arendjr commented Feb 9, 2024

Today I heard reports from several co-workers that seem to be running into this issue still, all on 1.5.3. Unfortunately, I haven't been able to witness it myself, but I did notice just now that I had 4 Biome formatter entries in VS Code, which was also one of the things my co-workers witnessed.

So while #1590 seems to have fixed #1584 (the issue that two Biome formatter entries appear in VS Code right away), I think there is still a lurking issue that causes additional entries to be registered over time. And my assumption here is that once there are multiple entries, they can still conflict and trigger this behavior.

I'm afraid I still have no additional information what might be the root cause however :(

@arendjr
Copy link
Contributor

arendjr commented Feb 9, 2024

And just like that, I finally witnessed the imports being messed up with my own eyes too! I'd been keeping the session with 4 Biome entries open, and it further reinforces my suspicion of the mangled imports and duplicate formatter entries being related: The mangled imports I witnessed had one of the imports being repeated 4 times:

mangled_imports

One thing of note though, this didn't happen to me on Save or by manually using Organize Imports. It happened when I renamed a symbol in one file and VS Code applied the refactoring to update that symbol in another file. Maybe that somehow triggered all four formatters to kick in, causing the renamed symbol to appear 4 times.

@arendjr arendjr reopened this Feb 9, 2024
@arendjr
Copy link
Contributor

arendjr commented Feb 9, 2024

Okay, and now that it happened once, if I use Undo to revert to how the imports were before they got mangled, then hit Save (I have Organize Imports enabled on Save) it mangles it again.

Update: One more piece of information: If I invoke Organize Imports explicitly, I get to choose between 5 entries. I think one is VS Code's native Organize Imports, while the other 4 are marked as Biome:

organize_import_entries

I can select any of those 5 entries, and the imports get organized as expected. So the functionality itself is fine. But I hit Save, and it mangles again, presumably because multiple get invoked at the same time.

Update: If I reorder imports in another file and Save, it also mangles there. So somehow I've gotten into a state now where it will always mangle if I Save while there are imports that need sorting. Saving files where the imports are already sorted is still fine.

@ematipico
Copy link
Member

Is it possible that you enabled the rule https://biomejs.dev/linter/rules/use-import-type/ ?

@arendjr
Copy link
Contributor

arendjr commented Feb 9, 2024

It shouldn't be, no...

@ematipico
Copy link
Member

Also I have noUnusedImports on, might make the issue worse.

I noticed that some of the bugs reported are caused by this very rule.

@Sec-ant
Copy link
Member

Sec-ant commented Apr 3, 2024

Can anyone confirm whether the failing cases in this issue can still be reproducible in the latest version (v1.6.4)?

@hilja
Copy link

hilja commented Apr 3, 2024

Just did little refactoring, removing and shuffling around code and so far it worked flawlessly 👍 But that was only about 15 minutes of coding, I'll report if anything else pops up.

@jansedlon
Copy link

Just messed up my imports 😅 Had 2 biome instances on version 1.6.4
image

@Sec-ant
Copy link
Member

Sec-ant commented Apr 4, 2024

Yeah I don't think the issue caused by multiple instances are fixed. And there're still failing cases that I'm aware of even there is only one instance. This is a complex issue, but we'll fix it step by step.

@jpike88
Copy link
Author

jpike88 commented Apr 4, 2024

I just want to say you guys are the best, eslint is happily far in the rear view mirror and it's hard to imagine things were any different. Just need that pesky no-hanging-promises and this will be literally perfection in both how it's written and its application.

@hilja
Copy link

hilja commented Apr 6, 2024

First import sorting issue since updating to 1.6.4. It might have something to do with the automatic fixing of the double quotes. If I cmd+z the last fix and then save again it's fixed.

In general it’s been working so much better! Thanks for fixing it.

Screen.Recording.2024-04-06.at.08.48.29.mov

@toteto
Copy link

toteto commented May 30, 2024

After initially enabling the "source.organizeImports.biome": "explicit" I was getting shuffled and random imports. They were overlapping with one another, and there were also duplicates.

Doing "undo" and formatting again, worked OK.

What fixed it for now was restarting VS Code as some of the previous comments have mentioned.

@valeneiko
Copy link

Looks like this issue is a bit broader and applies to lint rule fixes too: biomejs/biome-vscode#241
I can consistenlty reproduce the issue with the linked example, so hopefully this will help debug it.
And I only have one instance of Biome LSP running.

@benhickson
Copy link

i run into garbled imports anytime i try to save where i have a regular import and a type import in the same import line

@gonta1026
Copy link

I just want to report a similar problem that I have encountered.

gonta1026/next-my-template#1 (comment)

@depsimon
Copy link

@Sec-ant any news on this issue? How could we help?

@Sec-ant
Copy link
Member

Sec-ant commented Aug 27, 2024

@Sec-ant any news on this issue? How could we help?

@depsimon Sorry, these past few months have been the toughest for me because I have been working on revising my dissertation and preparing for the final defense. I’m having difficulty keeping up with things here. My advice would be to either wait a bit longer or try going through the code yourself. An overview of this issue is here.

@depsimon
Copy link

@Sec-ant No need to apologize really :)

I don't think I'll be able to help in the code as I never touched Rust, but if I can help by testing & reproducing I'll be glad.

Wish you all the best for your defense!

@flippingtables
Copy link

I hit this issue quite often as well. I had to remove the "source.organizeImports.biome": "explicit" setting because biome would constantly break my imports.

@ematipico
Copy link
Member

I hit this issue quite often as well. I had to remove the "source.organizeImports.biome": "explicit" setting because biome would constantly break my imports.

It's possible you have multiple instances of the server running. Check your task manager, search for the biome process. If you see multiple of them, that's likely the issue. Stop them all, and restart VSCode. Let us know if that fixes the issue

@bglgwyng
Copy link

I upgraded my global biomejs from 1.6.x to 1.9.x and solved this issue.

@jazmon
Copy link

jazmon commented Nov 5, 2024

I think the issue is indeed multiple instances of biome running @ematipico. It'd be great to get this fixed though as it's a regular issue my team is having too and having to reload the editor often isn't great.

Thanks for all your efforts 🙏

@ematipico
Copy link
Member

I think the issue is indeed multiple instances of biome running @ematipico. It'd be great to get this fixed though as it's a regular issue my team is having too and having to reload the editor often isn't great.

Thanks for all your efforts 🙏

Use the preview release of the VSCode extension, that should fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LSP Area: language server protocol S-Bug-confirmed Status: report has been confirmed as a valid bug
Projects
None yet
Development

No branches or pull requests