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

Imports to Components were inserted to random positions. #2501

Open
4 tasks done
infinnie opened this issue Nov 27, 2020 · 6 comments
Open
4 tasks done

Imports to Components were inserted to random positions. #2501

infinnie opened this issue Nov 27, 2020 · 6 comments

Comments

@infinnie
Copy link

infinnie commented Nov 27, 2020

  • I have searched through existing issues
  • I have read through docs
  • I have read FAQ
  • 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

@yoyo930021
Copy link
Member

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

@MrSiby
Copy link

MrSiby commented Mar 4, 2021

I am also having this issue. Also maybe #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 #2633 (comment) 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

@jasonlyu123
Copy link
Contributor

@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.

@MrSiby
Copy link

MrSiby commented Mar 5, 2021

@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.

@yoyo930021 yoyo930021 added the bug label Mar 9, 2021
@gburning
Copy link

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 <script>.
  4. No comma is added after the previous component definition.

@yoyo930021 yoyo930021 added this to the v0.36.0 milestone Nov 2, 2021
@stefvw93
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants