vetur icon indicating copy to clipboard operation
vetur copied to clipboard

Imports to Components were inserted to random positions.

Open infinnie opened this issue 4 years ago • 6 comments

  • [x] I have searched through existing issues
  • [x] I have read through docs
  • [x] I have read FAQ
  • [x] I have tried restarting VS Code or running Vetur: Restart VLS

Info

  • Platform: Windows
  • Vetur version: 0.30.3
  • VS Code version: 1.51.1

Problem

When editing the template of a component with help from IntelliSense auto completion and typing the component name as a tag name, even if already declared, a new import is still generated, its contents being inserted to random positions in the script part of the Vue code.

component

Reproducible Case

infinnie avatar Nov 27 '20 05:11 infinnie

Please provide a repro project https://github.com/vuejs/vetur/blob/master/.github/NO_REPRO_CASE.md

yoyo930021 avatar Nov 27 '20 06:11 yoyo930021

I am also having this issue. Also maybe https://github.com/vuejs/vetur/issues/2633 is related.

When I create a component to use in my view, auto-complete pops up when I begin typing in the component tag in my template and always auto-imports regardless if I have imported it or not. Sometimes somewhere random in my script, thus breaking it.

No matter of how many imports there are, auto-complete will offer a choice and it will always be to import the component.

Perhaps it's something with my settings? Or VSCode even? I'm not sure and would like to know if anyone has encountered the same. But the workaround I've found is to turn this setting off vetur.completion.autoImport.

I have only just found the workaround here https://github.com/vuejs/vetur/issues/2633#issuecomment-757603397 so not sure how many things it affects, however it does solve the issue.

Autocomplete appearing Screen Shot 2021-03-04 at 15 43 55 Importing forevermore Screen Shot 2021-03-04 at 15 44 14 Additions to the view component Screen Shot 2021-03-04 at 15 44 33

MrSiby avatar Mar 04 '21 15:03 MrSiby

@MrSiby I guess you didn't set up path aliases for typescript, as the comment suggested. So typescript, which powers the js/ts language features, is not aware that these import paths are the same.

jasonlyu123 avatar Mar 05 '21 02:03 jasonlyu123

@jasonlyu123 I've set up the typescript config and after changing all of the kebab-case references to pascal case the auto complete works better and does not import the component infinitely.

However it doesn't auto import at all, but I'm assuming it's to do with some other part of my configs. I'm still learning how to build SPAs with vue 3 and referencing multiple learning sources, all with different experience levels so my set up is a bit messy anyway.

Thank you for the link and pointing me in the right direction. It has helped my learning.

MrSiby avatar Mar 05 '21 15:03 MrSiby

This happens for me as well. The project I'm writing in doesn't use typescript either.

A few strange things happen:

  1. Auto-completing an already imported component causes it to add a duplicate import (this is the most frustrating part honestly).
  2. The inserted import statement and the component definition don't respect the correct indentation (in this project everything inside <script> tags is indented 2 spaces minimum).
  3. Component definition is inserted randomly somewhere inside the
  4. No comma is added after the previous component definition.

gburning avatar Apr 21 '21 21:04 gburning

Any update on this? This bug is absolutely detrimental to developer experience and is still here in 0.35.0.

Sidenote, to me the "no repro case" label seems kind of dubious as this bug happens to me in literally every Vue 2 project where Vetur is active.

Schermafbeelding 2022-05-23 om 10 18 46 Schermafbeelding 2022-05-23 om 11 06 16 Schermafbeelding 2022-05-24 om 09 30 14

stefvw93 avatar May 24 '22 07:05 stefvw93