nu_protocol/type_alias.rs
1use crate::{Span, SyntaxShape};
2
3/// A named type annotation defined with `type Name = <type>`.
4///
5/// [`TypeAlias::shape`] is the shape the right-hand side parses to when written in place of the
6/// name, so an alias behaves exactly like its expansion. A parameter annotation keeps the shape,
7/// as it does a written one: a parameter's type is a shape, and the shape decides how its
8/// argument is parsed and completed (`path` and `directory` expand `~`, `string` doesn't). Every
9/// other annotation (`let`, `mut`, `const`, input/output types) converts it with
10/// [`SyntaxShape::to_type`], as it does a written type. Storing a [`Type`](crate::Type) instead
11/// would lose `path`, `directory` and `external_arg`, which `to_type` turns into `string` and
12/// `any`.
13///
14/// Only the expansion is stored where the alias is used, so the alias name never reaches a
15/// [`Signature`](crate::Signature), a [`Type`](crate::Type) or the plugin protocol.
16#[derive(Debug, Clone)]
17pub struct TypeAlias {
18 pub name: String,
19 /// The right-hand side, parsed as it would be in a parameter annotation.
20 pub shape: SyntaxShape,
21 /// The whole `type` statement.
22 pub span: Span,
23}