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

source.addMissingImports auto import props field #2304

Closed
tjx666 opened this issue Jan 10, 2023 · 3 comments
Closed

source.addMissingImports auto import props field #2304

tjx666 opened this issue Jan 10, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@tjx666
Copy link
Contributor

tjx666 commented Jan 10, 2023

enable takeover mode: yes
vscode settings:

{
    "editor.codeActionsOnSave": {
        "source.addMissingImports": true,
        "source.fixAll.eslint": true,
        "source.fixAll.stylelint": true,
        "source.fixAll.markdownlint": true,
        "source.organizeImports.sortImports": false
    },
}
2023-01-10.16.27.49.mov
@Doeke
Copy link

Doeke commented Jan 10, 2023

Same here, it keep trying to add the import even though there is already a prop defined with the same name

Edit: This issue is in version Volar 1.0.24, and downgrading the extension to 1.0.22 fixes it for me

@danielwaltz
Copy link

danielwaltz commented Jan 11, 2023

I am also running into this for globally registered components in a vue@2.7.* application using vuetify@2.* with unplugin-vue-components.

Old behavior is a template like this works just fine without automatically adding imports:

<script setup lang="ts">
import AppMain from '@/components/AppMain.vue';
import AppMainHeader from '@/components/AppMainHeader.vue';
</script>

<template>
  <AppMain>
    <AppMainHeader class="mb-6" />

    <v-card>
      <router-view />
    </v-card>
  </AppMain>
</template>

New behavior is after saving it looks like this:

<script setup lang="ts">
import AppMain from '@/components/AppMain.vue';
import AppMainHeader from '@/components/AppMainHeader.vue';
import { RouterView } from 'vue-router'; // automatically added
import { VCard } from 'vuetify/lib'; // automatically added
</script>

<template>
  <AppMain>
    <AppMainHeader class="mb-6" />

    <v-card>
      <router-view />
    </v-card>
  </AppMain>
</template>

I found that I can work around this by defining vueCompilerOptions.nativeTags with a list of these globally registered components to skip the auto import, but that feels kludgy and hard to maintain. Is there a way to exclude globally registered components from this source.addMissingImports option?

@johnsoncodehk
Copy link
Member

Since source.addMissingImports actually has never worked for codeActionsOnSave in the past, setting "source.addMissingImports": false is the best workaround for now.

@johnsoncodehk johnsoncodehk added the bug Something isn't working label Jan 11, 2023
@johnsoncodehk johnsoncodehk pinned this issue Jan 12, 2023
@johnsoncodehk johnsoncodehk unpinned this issue Feb 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants