Skip to content

feat(language-service): Add Selection Range for smart expand selection in templates #66737

@kbrilla

Description

@kbrilla

Feature Request

Description

Add support for Selection Range (LSP 3.15) in the Angular Language Service to enable smart selection expansion in Angular templates.

Use Case

When working with Angular templates, developers use "Expand Selection" (Ctrl+Shift+Right/Left on Windows/Linux, Cmd+Shift+Right/Left on macOS) to quickly select code structures. The current selection expansion in Angular templates is suboptimal as it doesn't understand the template AST.

With Selection Range support:

  • Select a word → Expand to attribute value → Expand to attribute → Expand to element → Expand to parent
  • Works intelligently with Angular-specific structures like control flow blocks

Example

@if (user.isAuthenticated) {
  <div class="profile">
    <span>{{user.name}}</span>
  </div>
}

With cursor inside user.name:

  1. First expand: user.name
  2. Second expand: {{user.name}}
  3. Third expand: <span>{{user.name}}</span>
  4. Fourth expand: entire <div class="profile">...</div>
  5. Fifth expand: entire @if block

Technical Details

  • LSP method: textDocument/selectionRange
  • VS Code command: "Expand Selection" / "Shrink Selection"
  • Works with both external HTML templates and inline templates in TypeScript files
  • Handles Angular-specific nodes:
    • Control flow blocks (@if, @for, @switch, @defer)
    • Template syntax (*ngIf, *ngFor, ng-template)
    • Bindings and events ([property], (event), [(banana)])

Related

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