Skip to content

refactor(language-service): extract shared AST/TCB modules and decouple private entry point - #72330

Open
atscott wants to merge 1 commit into
angular:mainfrom
atscott:ls-extract-shared-core
Open

atscott wants to merge 1 commit into
angular:mainfrom
atscott:ls-extract-shared-core

Conversation

@atscott

@atscott atscott commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

#72328 is now merged; this PR is standalone on main.

@angular/language-service/private previously pulled in the entire packages/language-service/src target along with NgCompiler and ts.LanguageService, which made it impractical for the NGP language service (or other consumers) to reuse pure template AST and TCB leaf helpers without dragging in the classic compiler infrastructure.

This splits the pure synchronous template AST and TCB helpers into two smaller Bazel targets under packages/language-service/src/shared/ and repoints @angular/language-service/private to them:

  • //packages/language-service/src/shared:ast depends only on //packages/compiler (no typescript or compiler-cli dependency) and holds template span/selector utilities, getTargetAtPosition and TemplateTarget context resolution, built-in quick info metadata ($any, $safeNavigationMigration, ng-template, control-flow and @defer built-ins), attribute and 13-keyword control-flow block completion helpers, rename span extraction, and pure TmplAstNode[] visitors for outlining spans, linked editing ranges, smart selection, and document symbols.
  • //packages/language-service/src/shared:tcb depends on :ast, //packages/compiler, typescript, and //packages/compiler-cli/private and holds getTcbNodesOfTemplateAtPosition, findTightestNode, getParentClassDeclaration, unwrapTcbSpanTarget, and resolveSignatureHelpTarget.
  • //packages/language-service:private now depends only on src/shared:ast and src/shared:tcb, keeping all existing exports while exposing the shared helpers. The classic packages/language-service/src/*.ts modules delegate to these shared helpers without changing their public return types or re-exports, and pure unit tests are added under packages/language-service/test/shared/.

…le private entry point

Extract pure synchronous template AST and TCB leaf helpers into two fine-grained Bazel targets under `packages/language-service/src/shared/` so both the Classic TypeScript language service and the NGP language service can consume them without pulling in monolithic `NgCompiler`/`ts.LanguageService` infrastructure:

- `//packages/language-service/src/shared:ast` (depends only on `//packages/compiler`, zero `typescript` or `compiler-cli` dependencies):
  - `template_utils.ts`: pure template AST, span, and selector matching utilities (`isWithin`, `toAttributeCssSelector`, `makeElementSelector`, `getDirectiveMatchesForElementTag`, generic `getDirectiveMatchesForAttribute`, `getTextSpanOfNode`, `isBoundEventWithSyntheticHandler`, `isDollarEvent`, `selectorAttributes`).
  - `template_target.ts`: `getTargetAtPosition` and `TemplateTarget` context types split out from TCB lookup.
  - `quick_info_built_ins.ts`: built-in block/trigger/helper hover metadata and span resolution (`$any`, `$safeNavigationMigration`, `ng-template`, control-flow and `@defer` built-ins).
  - `completion_utils.ts`: pure attribute and block completion helpers (`getStructuralAttributes`, all 13 block keywords, `buildBlockSnippet`, `CompletionNodeContext`, `nodeContextFromTarget`, `stripBindingSugar`, `shouldIncludeAttributeCompletion`).
  - `rename_utils.ts`: `getRenameTextAndSpanAtPosition`.
  - `outlining_spans.ts`, `linked_editing_range.ts`, `smart_selection.ts`, `document_symbols.ts`: pure `TmplAstNode[]` visitors decoupled from `NgCompiler` and TypeScript enums.
- `//packages/language-service/src/shared:tcb` (depends on `:ast`, `//packages/compiler`, `typescript`, and `//packages/compiler-cli/private`):
  - `tcb_target.ts`: `getTcbNodesOfTemplateAtPosition`.
  - `tcb_utils.ts`: `findTightestNode`, `getParentClassDeclaration`, and `unwrapTcbSpanTarget`.
  - `signature_help.ts`: `resolveSignatureHelpTarget`.

Repoint `//packages/language-service:private` (`private.ts`) to depend exclusively on `src/shared:ast` and `src/shared:tcb` instead of monolithic `//packages/language-service/src`, preserving all existing exports while exposing the new shared helpers. Keep all Classic `src/*.ts` public return types and `utils`/`template_target` re-exports unchanged, and add pure unit tests under `packages/language-service/test/shared/`.
@atscott
atscott force-pushed the ls-extract-shared-core branch from e7d0b72 to e37c38d Compare December 4, 2026 21:36
@atscott atscott added the target: minor This PR is targeted for the next minor release label Dec 4, 2026
@atscott
atscott requested a review from clydin December 4, 2026 21:49
@atscott
atscott marked this pull request as ready for review December 4, 2026 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

1 participant