Skip to content

Prefer components over directives for auto-import in template suggestions of element tags #68522

Open

Description

@eblocha

Which @angular/* package(s) are relevant/related to the feature request?

language-service

Description

When automatically importing items into a component while typing in the template, components and directives are suggested in alphabetical order. I think it would be better to prefer a component import when possible.

Imagine a component library that provides a ButtonComponent and an AddButtonDirective to apply a preset to the button.

@Component({
  selector: 'app-button',
})
export class ButtonComponent {}
@Directive({
  selector: 'app-button[appAddButton]',
})
export class AddButtonDirective {}

When the language service suggests an automatic import, it prefers AddButtonDirective because it comes first alphabetically.

<!-- this should suggest ButtonComponent over AddButtonDirective -->
<app-button
Image

Proposed solution

The language service should suggest the component over the directive in this case.

Alternatives considered

Alternative is to leave the element selector off of all directive selectors, but this is not always ideal or possible, as some directives might require a specific component host.

Activity

  1. added this to the needsTriage milestone on May 2, 2026
  2. added this to the needsTriage milestone on May 2, 2026
  3. tuobi2 commented on May 2, 2026

    @tuobi2
  4. JeanMeche commented on May 2, 2026

    @JeanMeche
    Member

    This looks like to be WebStorm which uses its own language service. Please report the feature request directly to them.

  5. eblocha commented on May 2, 2026

    @eblocha
    Author

    @JeanMeche This is in vscode

  6. tuobi2 commented on May 2, 2026

    @tuobi2
  7. JeanMeche commented on May 2, 2026

    @JeanMeche
    Member

    Fwiw, you'll get better autocompletion with the quick fix feature:

    Image
  8. tuobi2 commented on May 2, 2026

    @tuobi2
  9. tuobi2 commented on May 2, 2026

    @tuobi2
  10. tuobi2 commented on May 2, 2026

    @tuobi2
  11. tuobi2 commented on May 2, 2026

    @tuobi2
  12. tuobi2 commented on May 2, 2026

    @tuobi2
  13. tuobi2 commented on May 2, 2026

    @tuobi2
  14. tuobi2 commented on May 2, 2026

    @tuobi2
  15. tuobi2 commented on May 2, 2026

    @tuobi2
  16. tuobi2 commented on May 2, 2026

    @tuobi2
  17. tuobi2 commented on May 2, 2026

    @tuobi2
  18. eblocha commented on May 2, 2026

    @eblocha
    Author

    Fwiw, you'll get better autocompletion with the quick fix feature:

    I believe quick fix works because the component is the only thing that matches the element tag. Quick fix can also suggest multiple actions, so if the attribute is added, it'll be listed in the fixes.

    Image
  19. tuobi2 commented on May 2, 2026

    @tuobi2
  20. tuobi2 commented on May 2, 2026

    @tuobi2
  21. tuobi2 commented on May 2, 2026

    @tuobi2
  22. tuobi2 commented on May 2, 2026

    @tuobi2
  23. added a commit that references this issue on May 2, 2026
    c70fb73
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: language-serviceIssues related to Angular's VS Code language service

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      Sponsor
      SponsoredKunjungi sekarang
      Promo