language-tools icon indicating copy to clipboard operation
language-tools copied to clipboard

Bug: Auto import from vue adds separate import statements in .vue files

Open ddenev opened this issue 1 year ago • 22 comments
trafficstars

Vue - Official extension or vue-tsc version

2.1.2

VSCode version

1.92.2

Vue version

3.4.38

TypeScript version

5.5.4

System Info

No response

Steps to reproduce

This happens only in .vue files, works ok in .js files.

Every time I use auto import from 'vue', the symbol I select is imported in a separate import statement (separate line), resulting in multiple import { ... } from 'vue' statements.

Note: I already reported this issue to VSCode devs (https://github.com/microsoft/vscode/issues/227042) but they said it's Vue related and should be reported here.

VSCode Extensions (19)
Extension Author (truncated) Version
project-manager ale 12.8.0
npm-intellisense chr 1.4.5
path-intellisense chr 2.9.0
js-codeformer cms 2.6.1
vscode-eslint dba 3.0.10
gitlens eam 15.3.1
EditorConfig Edi 0.16.4
prettier-vscode esb 11.0.0
html-slim-scss-css-class-completion gen 1.7.8
JavaScriptSnippetsStandard jms 1.8.0
remote-ssh ms- 0.113.1
remote-ssh-edit ms- 0.86.0
remote-explorer ms- 0.4.3
abracadabra nic 9.4.6
material-icon-theme PKi 5.10.0
vscode-yaml red 1.15.0
volar Vue 2.1.2
vscode-todo-highlight way 1.0.5
material-theme zhu 3.17.2

What is expected?

Expected result is to reuse the 1st import statement and add the symbol there.

What is actually happening?

Here is the state before I auto-import the second symbol from vue: image And here is what happens immediately after I hit Enter on the computed symbol: image

Link to minimal reproduction

No response

Any additional comments?

No response

ddenev avatar Aug 30 '24 07:08 ddenev

Can't reproduce. Please try to reproduce this with an empty vscode profile (no extensions). If you can still reproduce, let me know. Otherwise, enable one extension after the other in the empty profile to find out if this issue is caused by a thirdparty extension. Thanks

davidmatter avatar Aug 30 '24 09:08 davidmatter

I have same issues with auto import in Nuxt

svenit avatar Aug 30 '24 09:08 svenit

There seems to be a regression. Nuxt auto-imports are not working in 2.1x

tobychidi avatar Aug 30 '24 10:08 tobychidi

Who wants to open an issue with nuxt? :)

davidmatter avatar Aug 30 '24 10:08 davidmatter

Can't reproduce. Please try to reproduce this with an empty vscode profile (no extensions). If you can still reproduce, let me know. Otherwise, enable one extension after the other in the empty profile to find out if this issue is caused by a thirdparty extension. Thanks

I have disabled all extensions, except Volar (so that it can autocomplete in a .vue file) and the problem is still happening. Interesting thing is - every time I restarted an extension after disabling it, auto-import worked properly only the 1st time but when I Ctrl-Z and try to do it again, it was still adding a separate import line.

Here is how to reproduce it (this is my setup):

  1. Install Quasar: yarn global add @quasar/cli (use yarn v1.x)
  2. Create a new Quasar project: yarn create quasar (accept all defaults)
  3. Open the new project folder in VSCode (only Volar extension is enabled)
  4. Create a new .vue file in src
  5. Try to reproduce the above behaviour

The result is:

<template>
  <div>A</div>
</template>

<script setup>
import { computed } from 'vue'
import { ref } from 'vue'

const t1 = ref()
const t2 = computed
</script>

<style lang="scss" scoped></style>

image

ddenev avatar Aug 30 '24 10:08 ddenev

I just tested with a brand new Vue project (npm create vue@latest) and there is NO problem there. It might be related to Quasar somehow. I will be reporting this to the Quasar team as well.

ddenev avatar Aug 30 '24 11:08 ddenev

  1. Please show the Vue langauge status of your vscode status bar. image

  2. Please try creating a new .ts file. Can you reproduce the problem in that .ts file?

johnsoncodehk avatar Aug 31 '24 16:08 johnsoncodehk

Experiencing this as well, this only occurs in .vue files, not seeing any issue in .ts files.

https://github.com/user-attachments/assets/5e5a5772-476f-49e4-9710-407fd52a58ca

Note popup incorrectly shows Hybrid ModeDisabled, even tho workspace option is typeScriptPluginOnly

minht11 avatar Aug 31 '24 16:08 minht11

We are no longer actively maintaining LSP-only mode, does enabling hybrid mode resolve the problem?

johnsoncodehk avatar Aug 31 '24 17:08 johnsoncodehk

Which option is that? image

Edit: changing it to auto does seem to fix it for duplicate vue imports, though it breaks my monorepo auto imports with different issues.

minht11 avatar Aug 31 '24 17:08 minht11

though it breaks my monorepo auto imports with different issues.

Is there an existing issue? If not, can you open a new issue?

johnsoncodehk avatar Aug 31 '24 22:08 johnsoncodehk

I confirm that switching Hybrid Mode to auto does resolve the issue (mine was previously set to false, possibly since the switch from old Volar).

ddenev avatar Sep 01 '24 11:09 ddenev

Having the same issue. Tried new project - looks to works well, but in existing one works randomly. I played with "Hybrid mode" - no difference. Removed all extensions apart Volar, and removed anything JS related from the project. It still works randomly 🤯

Screencast From 2024-12-03 18-08-20.webm

tomastan avatar Dec 03 '24 16:12 tomastan

@KazariEX Can you please suggest if this was really fixed, since I see no change in the just updated version 2.2.6? The problem remains the same as reported above.

tomastan avatar Mar 01 '25 11:03 tomastan

I closed this issue because I cannot reproduce it and no one provides any minimal reproduction.

KazariEX avatar Mar 01 '25 11:03 KazariEX

@KazariEX look, I've stripped down my case to a smallest one I can reproduce and made a repo to test.

https://github.com/tomastan/vuejs-language-tools-import-problem-example

Just clone it and run npm i

This make me reproduce almost all the time. Here it is:

https://github.com/user-attachments/assets/61591d6f-92c8-4dc1-abc3-4c1d9043bdad

Important

What did I found is that the problem looks to be connected with vue-tel-input package. When I remove it, all works fine. I have no idea how this is connected though. Hope it helps. Since this bug is really irritating :)

tomastan avatar Mar 01 '25 14:03 tomastan

Does changing jsconfig.json to tsconfig.json resolve your problem?

KazariEX avatar Mar 01 '25 14:03 KazariEX

Does changing jsconfig.json to tsconfig.json resolve your problem?

Yes. This helps. Is this by design?

tomastan avatar Mar 01 '25 15:03 tomastan

It might be some kind of weird bug.

KazariEX avatar Mar 01 '25 15:03 KazariEX

It might be some kind of weird bug.

Are you able to replicate it now?

tomastan avatar Mar 01 '25 20:03 tomastan

Are you able to replicate it now?

Yep, but I have no idea how to resolve it.

KazariEX avatar Mar 01 '25 20:03 KazariEX

@KazariEX clear. At least there is a quick fix of jsconfig.json to tsconfig.json renaming and you know about this bug to possibly find a universal solution.

tomastan avatar Mar 01 '25 20:03 tomastan

I'm experiencing this bug and I don't have a jsconfig.json file 🤔

Meesayen avatar Apr 03 '25 11:04 Meesayen

Close as Hybrid Mode is mandatory after 3.0.

johnsoncodehk avatar Jul 05 '25 11:07 johnsoncodehk