Prefer components over directives for auto-import in template suggestions of element tags
- Dominant language
- TypeScript
- Stars
- 101k
- Forks
- 27.5k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 288
Description
### 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.
```ts
@Component({
selector: 'app-button',
})
export class ButtonComponent {}
```
```ts
@Directive({
selector: 'app-button[appAddButton]',
})
export class AddButtonDirective {}
```
When the language service suggests an automatic import, it prefers `AddButtonDirective` because it comes first alphabetically.
```html
### 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.
Contributor guide
Research direction
Start in the Angular language-service implementation for template auto-import suggestions and reproduce the example with an element selector matching both ButtonComponent and AddButtonDirective. Trace how candidates are ordered, then verify that the component is suggested first while directive suggestions remain available.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, typescript
- Domain
- frontend, tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100