Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Initial language service support for selectorless #61240

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

Closed
wants to merge 6 commits into from

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented May 9, 2025

Sets up some initial support for selectorless in the language service which handles things like resolving definitions and hover tooltips. We're still missing at least the following:

  • Initiating a rename from a component/directive class. Currently it only works when initiated from the template.
  • Completions in a selectorless. Both the directive name and its attributes.

Includes the following changes:

fix(compiler-cli): symbol builder duplicating host directives

The template symbol builder works by finding the variables referring to template AST nodes with specific offsets and resolving them to directives. Afterwards it goes through the directives and resolves their host directives.

The problem is that host directives are added with the exact same offsets as their host which means they get added once initially and again when resolving host directives.

These changes resolve the issue by de-duplicating them.

refactor(compiler-cli): produce template symbols for selectorless nodes

Updates the template type checker to produce symbols for selectorless nodes. This is necessary for integration into the language service.

refactor(language-service): set up template targets for selectorless

Adds the logic to resolve the template targets for the selectorless component and directive nodes. This is a prerequisite for other functionality.

refactor(language-service): support definitions for selectorless

Updates the language service to handle producing definition information for selectorless components and directives.

refactor(language-service): support quick info selectorless symbols

Updates the language service to produce quick info for selectorless components and directives.

refactor(language-service): initial reference and rename implementation for selectorless

Adds an initial implementation for finding references and renaming to selectorless components/directives.

Finding references should work everywhere, whereas renaming only currently works when initiated from the template.

@crisbeto crisbeto added action: review The PR is still awaiting reviews from at least one requested reviewer target: rc This PR is targeted for the next release-candidate labels May 9, 2025
@angular-robot angular-robot bot added area: compiler Issues related to `ngc`, Angular's template compiler area: language-service Issues related to Angular's VS Code language service labels May 9, 2025
@ngbot ngbot bot added this to the Backlog milestone May 9, 2025
@crisbeto crisbeto requested a review from devversion May 9, 2025 13:19
@crisbeto crisbeto marked this pull request as ready for review May 9, 2025 13:19
if (meta !== null && meta.selector !== null) {
const ref = new Reference<ClassDeclaration>(symbol.tsSymbol.valueDeclaration as any);
// Host directives will be added as identifiers with the same offset as the host
// which means that they'll get added twice. De-duplicate them to avoid confusion.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of curiosity, is this new or why is this surfacing now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was always like that, we just didn't have any tests with host directives so we never noticed it. I think that also the language service integration was de-duping the information produced as a result at some point so it didn't affect users either.

/**
* A `TmplAstComponent` element node that's targeted, where the given position is within the body.
*/
export interface ComponentInBodyContext {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is not new, but "body" was confusing me for a bit.

crisbeto added 6 commits May 12, 2025 14:32
The template symbol builder works by finding the variables referring to template AST nodes with specific offsets and resolving them to directives. Afterwards it goes through the directives and resolves their host directives.

The problem is that host directives are added with the exact same offsets as their host which means they get added once initially and again when resolving host directives.

These changes resolve the issue by de-duplicating them.
Updates the template type checker to produce symbols for selectorless nodes. This is necessary for integration into the language service.
Adds the logic to resolve the template targets for the selectorless component and directive nodes. This is a prerequisite for other functionality.
Updates the language service to handle producing definition information for selectorless components and directives.
Updates the language service to produce quick info for selectorless components and directives.
…on for selectorless

Adds an initial implementation for finding references and renaming to selectorless components/directives.

Finding references should work everywhere, whereas renaming only currently works when initiated from the template.
@crisbeto crisbeto force-pushed the selectorless-lang-service branch from f6858dc to 2580eda Compare May 12, 2025 12:38
@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker target: minor This PR is targeted for the next minor release and removed action: review The PR is still awaiting reviews from at least one requested reviewer target: rc This PR is targeted for the next release-candidate labels May 12, 2025
@alxhub
Copy link
Member

alxhub commented May 12, 2025

This PR was merged into the repository by commit fa27b76.

The changes were merged into the following branches: main

@alxhub alxhub closed this in c439d69 May 12, 2025
alxhub pushed a commit that referenced this pull request May 12, 2025
…es (#61240)

Updates the template type checker to produce symbols for selectorless nodes. This is necessary for integration into the language service.

PR Close #61240
alxhub pushed a commit that referenced this pull request May 12, 2025
…61240)

Adds the logic to resolve the template targets for the selectorless component and directive nodes. This is a prerequisite for other functionality.

PR Close #61240
alxhub pushed a commit that referenced this pull request May 12, 2025
)

Updates the language service to handle producing definition information for selectorless components and directives.

PR Close #61240
alxhub pushed a commit that referenced this pull request May 12, 2025
…61240)

Updates the language service to produce quick info for selectorless components and directives.

PR Close #61240
alxhub pushed a commit that referenced this pull request May 12, 2025
…on for selectorless (#61240)

Adds an initial implementation for finding references and renaming to selectorless components/directives.

Finding references should work everywhere, whereas renaming only currently works when initiated from the template.

PR Close #61240
crisbeto added a commit to crisbeto/angular that referenced this pull request May 13, 2025
Follow-up from angular#61240 (comment). Adds a `isSelfClosing` property on element-like AST nodes so consumers can easily determine if it's self-closing, rather than having to look at the spans. This is useful for migrations and in the language service.
crisbeto added a commit to crisbeto/angular that referenced this pull request May 13, 2025
…ectives

Follow-up to angular#61240 that adds renaming support for selectorless components/directives both from the template and from the TypeScript source.
crisbeto added a commit that referenced this pull request May 14, 2025
Follow-up from #61240 (comment). Adds a `isSelfClosing` property on element-like AST nodes so consumers can easily determine if it's self-closing, rather than having to look at the spans. This is useful for migrations and in the language service.

PR Close #61307
crisbeto added a commit that referenced this pull request May 14, 2025
…ectives (#61307)

Follow-up to #61240 that adds renaming support for selectorless components/directives both from the template and from the TypeScript source.

PR Close #61307
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jun 12, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: compiler Issues related to `ngc`, Angular's template compiler area: language-service Issues related to Angular's VS Code language service target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants