Skip to content

Commit

Permalink
feat: allow desc in ---@alias enum (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
numToStr committed Jun 28, 2022
1 parent c906714 commit d902592
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/parser/tags/alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct TypeDef {
#[derive(Debug, Clone)]
pub enum AliasKind {
Type(TypeDef),
Enum(Vec<TypeDef>),
Enum(Vec<String>, Vec<TypeDef>),
}

#[derive(Debug, Clone)]
Expand All @@ -35,14 +35,11 @@ parser!(Alias, {
},
},
select! { TagType::Alias { name, .. } => name }
.then(
select! { TagType::Variant(ty, desc) => TypeDef { ty, desc } }
.repeated()
.map(AliasKind::Enum),
)
.map(|(name, kind)| Self {
.then(select! { TagType::Comment(x) => x }.repeated())
.then(select! { TagType::Variant(ty, desc) => TypeDef { ty, desc } }.repeated())
.map(|((name, desc), variants)| Self {
name,
kind,
kind: AliasKind::Enum(desc, variants),
prefix: Prefix::default(),
}),
))
Expand Down Expand Up @@ -71,7 +68,8 @@ impl Display for Alias {
description!(f, "Type: ~")?;
writeln!(f, "{:>w$}", ty, w = 8 + ty.len())?;
}
AliasKind::Enum(variants) => {
AliasKind::Enum(desc, variants) => {
description!(f, &desc.join("\n"))?;
writeln!(f)?;
description!(f, "Variants: ~")?;

Expand Down
2 changes: 2 additions & 0 deletions tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ fn alias_and_type() {
---@alias Lines string[] All the lines in the buffer
---@alias VMode
---Vim operator-mode motions. Read `:h map-operator`
---| 'line' Vertical motion
---| 'char' Horizontal motion
---| 'v'
Expand Down Expand Up @@ -379,6 +380,7 @@ Lines *Lines*
VMode *VMode*
Vim operator-mode motions. Read `:h map-operator`
Variants: ~
('line') Vertical motion
Expand Down
1 change: 1 addition & 0 deletions tests/test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ end
-- You can define a (psuedo) enum using `alias`

---@alias VMode
---Vim operator-mode motions. Read `:h map-operator`
---| 'line' Vertical motion
---| 'char' Horizontal motion
---| 'v'
Expand Down

0 comments on commit d902592

Please sign in to comment.