Skip to content

feat: inline named model expressions#1

Open
Copilot wants to merge 11 commits intomainfrom
copilot/add-inline-named-models-support
Open

feat: inline named model expressions#1
Copilot wants to merge 11 commits intomainfrom
copilot/add-inline-named-models-support

Conversation

Copy link

Copilot AI commented Feb 10, 2026

Adds support for defining named models inline in type expression positions:

model Parent {
  child: model Child {
    grandchild: model Grandchild {
      age: int32;
    };
  };
}

@@doc(Child, "The child model");
@@doc(Grandchild, "The grandchild model");

Inline named models are declared in the enclosing namespace/script scope, making them referenceable by augment decorators and subject to standard duplicate-name detection. Arbitrarily deep nesting is supported.

Compiler

  • AST (types.ts): Optional id: IdentifierNode on ModelExpressionNode
  • Parser (parser.ts): ModelKeyword case in parsePrimaryExpression dispatches to parseInlineNamedModelExpression(); visitChildren traverses optional id
  • Binder (binder.ts): bindModelExpression uses getEnclosingDeclarationScope() to walk up to the nearest namespace/script scope for symbol declaration
  • Checker (checker.ts): checkModelExpression uses explicit createType (matching checkModelStatement pattern), sets Model.name from node.id, processes augment decorators for named inline models
  • Formatter (printer.ts): Emits model <Name> prefix for named model expressions

Grammar & Semantic Tokens

  • inlineNamedModelExpression TextMate rule for model <Name> { ... } in expression position
  • statementKeywordExceptModel / universalEndExceptModel prevent model from prematurely terminating type annotation and model property contexts
  • classify.ts handles ModelExpression with id for semantic token highlighting

Tests

  • Parser: deep nesting (2/3 levels), missing-name error
  • Checker positive: augment decorators, nested models, deep nesting + augment decorators, spread properties
  • Checker negative: duplicate sibling names, conflict with top-level model, nested name reuse
  • Typekit: model.is(), model.getEffectiveModel(), type.getPlausibleName(), type.clone(), type.isAssignableTo(), type.resolve()
  • Colorization: semantic + tmlanguage tokenization

Sample

Updated playground http.tsp with inline named models in a model property, operation response, and template parameter position.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits February 10, 2026 02:30
Add optional `id` field to `ModelExpressionNode` to support inline
named models in property type positions. Example:

```typespec
model Parent {
    child: model Child {
        age: int32;
    }
}
```

Co-authored-by: johanste <15110018+johanste@users.noreply.github.com>
Co-authored-by: johanste <15110018+johanste@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for inline named models with tests and documentation feat: add support for inline named model expressions Feb 10, 2026
Copilot AI requested a review from johanste February 10, 2026 02:37
@johanste
Copy link
Owner

@copilot update the changelog

Co-authored-by: johanste <15110018+johanste@users.noreply.github.com>
Copy link
Author

Copilot AI commented Feb 10, 2026

@copilot update the changelog

Added the changelog entry in commit 6ac054e.

Copilot AI and others added 3 commits February 10, 2026 03:14
…rator and nesting support with tests

Co-authored-by: johanste <15110018+johanste@users.noreply.github.com>
…st, response, and template parameter

Co-authored-by: johanste <15110018+johanste@users.noreply.github.com>
Co-authored-by: johanste <15110018+johanste@users.noreply.github.com>
Copilot AI changed the title feat: add support for inline named model expressions feat: inline named model expressions Feb 10, 2026
Co-authored-by: johanste <15110018+johanste@users.noreply.github.com>
Co-authored-by: johanste <15110018+johanste@users.noreply.github.com>
@johanste
Copy link
Owner

@copilot fix the failing checks

Co-authored-by: johanste <15110018+johanste@users.noreply.github.com>
Copy link
Author

Copilot AI commented Feb 11, 2026

@copilot fix the failing checks

Fixed in b0d2b6d:

  • Removed unused program variable in test/typekit/model.test.ts (lint warning)
  • Reformatted test/parser.test.ts (prettier formatting)

@johanste johanste marked this pull request as ready for review February 11, 2026 22:36
@github-actions
Copy link

All changed packages have been documented.

  • @typespec/compiler
Show changes

@typespec/compiler - feature ✏️

Add support for inline named model expressions in property type positions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants