angular / vscode-ng-language-service

Angular extension for Visual Studio Code
MIT License
779 stars 117 forks source link

Import Module from Template #1917

Open R-Bower opened 1 year ago

R-Bower commented 1 year ago

This ticket was closed despite not having been resolved.

          I'm intending to enable this for external libraries in a future release. I was worried about performance issues, and so I put it on the back burner for a while. (Although the primary motivation is standalone, there's no reason we can't also do it for NgModules)

Originally posted by @dylhunn in https://github.com/angular/vscode-ng-language-service/issues/1501#issuecomment-1520730889

I'm posting it again here because this is a major blocker for my transition from WebStorm to vscode. It may seem minor, but my productivity is impacted by this issue.

🚀 feature request

Description

One of the killer features of Webstorm when working with angular is the ability to automatically import NgModules from templates as an auto completion for components, directives and pipes.

It would be fantastic if such a feature could be brought into vsc

Feature Type

What does this bug affect

Describe the solution you'd like

This is probably a tricky problem to solve as it relies on knowing all the possible NgModules (something that even TypeScript struggles with for things like submodules imports of @angular/material) and then adding the import via a code completion to a file that is potentially not open.

The closest thing I can think of that currently exist in vsc is renaming files automatically updating their imports which I believe the TypeScript language service manages.

Describe alternatives you've considered

Use WebStorm instead of vscode.

dylhunn commented 12 months ago

This would be a great feature. It is a performance challenge though, because the DtsMetadataReader needs to be able to enumerate all the selectors found in all directive/component metas in all Dts files.

m4riok commented 11 months ago

Automatic Imports from your own code base make way less sense than imports from an external library. This feature will seriously boost productivity. I too would love to see this implemented in vsc. If performance is an issue perhaps provide an option for loading all / some selectors so the user can choose whether he is willing to suffer the performance penalty in order to have this feature ?

Martinspire commented 10 months ago

I'm not entirely famililar with how webstorm does it, but do you propose something like this: When you use standalone modules, it doesn't recognize various components when you add them in your template. It would be nice if it automatically updated the imports when you use something in the template that isn't defined yet.

So when I would type <second-component /> then it would automatically update the imports of my component. Same for when I'm using forms that it would automatically update to add FormsModule and stuff like that. And when you removed one, it should also clean it up. Preferrably sort them alphabetically or perhaps modules first and then components and so on.

And for when you aren't using standalone modules, it would be nice if things get imported into the nearest modules file so that you can use it immediately without having to worry about adding it there.

m4riok commented 10 months ago

@Martinspire If I am not mistaken Webstorm does it by maintaining it's own indexes which it builds on startup and updates when changes are made to package.json.

Functionality is exactly as you describe it except it does not automatically remove the import when you remove the selector from the template, only adds it automatically when you add it.

hatsantos commented 8 months ago

I was searching for a VSCode plugin or a way to enable the functionality of importing components or directives directly from the template. For those who have fully embraced standalone components, it's tedious having to manually import each component.

This feature would be excellent to have and would result in an improved DX.

asphub commented 3 months ago

Need an option to import necessary modules or components directly from the HTML, at least for the standalone components. Need to show a Quick Fix bulb can be used for such imports.

322353785-3c6b26b9-12fa-4c28-8a07-b8a2724af606

nuriddin2468 commented 2 months ago

is there any news on this ?

codetroll commented 2 months ago

Yeah - this is sorely lacking in VS Code. As it is now, you don't even see that there is something missing.