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

Feature request: auto importing components #194

Closed
sheremet-va opened this issue May 20, 2021 · 8 comments
Closed

Feature request: auto importing components #194

sheremet-va opened this issue May 20, 2021 · 8 comments
Labels
enhancement New feature or request

Comments

@sheremet-va
Copy link

sheremet-va commented May 20, 2021

PhpStorm has a nice feature of auto importing components when typing it's name inside template tag. Is it possible to add such functionality?

Examples:

<script lang="ts">
import { defineComponent } from 'vue'; 

export default defineComponent({
   name: 'Placeholder'
});
</script>

<template>
    <test-c... <-- picking suggestion
</template>

After picking:

<script lang="ts">
import { defineComponent } from 'vue'; 
import TestComponent from '@/components/TestComponent.vue';

export default defineComponent({
   name: 'Placeholder',
   components: {
      TestComponent
  }
});
</script>

<template>
    <test-component>
</template>

Would be great if it also worked with script setup!

But I wonder how it will be handled with default typescript behavior? Because for example, if you store components inside folder like so:

- TestComponent
  - types.ts
  - index.ts
  - TestComponent.vue

and try importing component from index, will it handle it correctly? Because right now importing defineComponent imports it from @vue/runtime-core and not from vue (which actually breaks our Vite application, but it's whole another story). I try not to open issues if Volar's behavior matches default.

@johnsoncodehk johnsoncodehk added the enhancement New feature or request label May 20, 2021
@johnsoncodehk
Copy link
Member

I personally don't like this feature... It introduces some DX conventions outside TS. And it will increase many component item in completion list for a large project.

As I know Vetur also has this feature, have you used one of them for a while? Does this feature bring substantial DX improvements?

But I wonder how it will be handled with default typescript behavior?

Considering performance, we may only be able to handle auto-import from *.vue files.

@sheremet-va
Copy link
Author

sheremet-va commented May 20, 2021

I wrote a project using PhpStorm and the main drawback of switching to VSCode was the loss of auto-importing components (and bad initial responsiveness). In fact some of our coworkers stay on Storm because of this.

But I haven't used Vetur with this feature.

@johnsoncodehk
Copy link
Member

Thanks for shared! "initial responsiveness" mean language server initialization speed, or first LSP request (like hover info) response speed? Will take a look for improve.

In fact some of our coworkers stay on Storm because of this.

I don't think your coworkers will switch to VSCode when we add this feature. 🤣

Anyway I will try to implement this feature as experiment first.

@sheremet-va
Copy link
Author

sheremet-va commented May 22, 2021

Thanks for shared! "initial responsiveness" mean language server initialization speed, or first LSP request (like hover info) response speed? Will take a look for improve.

LSP requests can be quite long. I mean hover info, reference window and go to definitions (this ones can be reeeeeealy long). It really throttles if I make edits in multiple files at once (I mean > 10). This workflow happens very rarely tho.

If you need any info from me, I will happily provide it!

@johnsoncodehk
Copy link
Member

I want to improve it if possible, will be helpful if you can provide profiling.

@sheremet-va
Copy link
Author

I started debugging, and I so far I can say I see a lot of these errors:
image

By the way maybe we should discuss this in another thread? Where should we switch?

@johnsoncodehk
Copy link
Member

@sheremet-va Sorry for missing the message!

You can open a new Issue / Discussion or ask on Discord anyway is ok.

Please post how and where to get this error.

@johnsoncodehk
Copy link
Member

johnsoncodehk commented May 31, 2021

Supported in v0.25.15 v0.25.16.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants