Skip to content

Commit d65f2a5

Browse files
authored
fix: bring back [desc] support in ---@type (#43)
This PR brings back `[desc]` support in `---@type` which was removed in #37
1 parent f98322f commit d65f2a5

5 files changed

Lines changed: 33 additions & 30 deletions

File tree

emmylua.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ You can use `---@type` to document static objects, constants etc.
532532

533533
```lua
534534
---@comment
535-
---@type <type>
535+
---@type <type> [desc]
536536
---@see <tag>
537537
---@usage `<code>`
538538
```

src/lexer.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ pub enum TagType {
118118
/// ```
119119
Variant(String, Option<String>),
120120
/// ```lua
121-
/// ---@type <type>
121+
/// ---@type <type> [desc]
122122
/// ```
123-
Type(String),
123+
Type(String, Option<String>),
124124
/// ```lua
125125
/// ---@tag <name>
126126
/// ```
@@ -273,7 +273,8 @@ impl Lexer {
273273
just("type")
274274
.ignore_then(space)
275275
.ignore_then(ty)
276-
.map(TagType::Type),
276+
.then(desc)
277+
.map(|(ty, desc)| TagType::Type(ty, desc)),
277278
just("tag")
278279
.ignore_then(space)
279280
.ignore_then(comment)

src/parser/tags/type.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use super::Usage;
99

1010
#[derive(Debug, Clone)]
1111
pub struct Type {
12-
pub desc: Vec<String>,
1312
pub prefix: Prefix,
1413
pub name: String,
14+
pub desc: (Vec<String>, Option<String>),
1515
pub kind: Kind,
1616
pub ty: String,
1717
pub see: See,
@@ -23,22 +23,24 @@ impl_parse!(Type, {
2323
TagType::Comment(x) => x
2424
}
2525
.repeated()
26-
.then(select! { TagType::Type(ty) => ty })
26+
.then(select! { TagType::Type(ty, desc) => (ty, desc) })
2727
.then(See::parse())
2828
.then(Usage::parse().or_not())
2929
.then(select! { TagType::Expr { prefix, name, kind } => (prefix, name, kind) })
30-
.map(|((((desc, ty), see), usage), (prefix, name, kind))| Self {
31-
desc,
32-
prefix: Prefix {
33-
left: prefix.clone(),
34-
right: prefix,
30+
.map(
31+
|((((extract, (ty, desc)), see), usage), (prefix, name, kind))| Self {
32+
desc: (extract, desc),
33+
prefix: Prefix {
34+
left: prefix.clone(),
35+
right: prefix,
36+
},
37+
name,
38+
kind,
39+
ty,
40+
see,
41+
usage,
3542
},
36-
name,
37-
kind,
38-
ty,
39-
see,
40-
usage,
41-
})
43+
)
4244
});
4345

4446
impl Type {

src/vimdoc/type.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ use std::fmt::Display;
22

33
use crate::parser::Type;
44

5-
use super::{description, header, see::SeeDoc, usage::UsageDoc};
5+
use super::{description, header, see::SeeDoc, usage::UsageDoc, Table};
66

77
#[derive(Debug)]
88
pub struct TypeDoc<'a>(pub &'a Type);
99

1010
impl Display for TypeDoc<'_> {
1111
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1212
let Type {
13-
desc,
13+
desc: (extract, desc),
1414
prefix,
1515
name,
1616
kind,
@@ -35,18 +35,18 @@ impl Display for TypeDoc<'_> {
3535
)
3636
)?;
3737

38-
if !desc.is_empty() {
39-
description!(f, &desc.join("\n"))?;
38+
if !extract.is_empty() {
39+
description!(f, &extract.join("\n"))?;
4040
}
4141

4242
writeln!(f)?;
4343

4444
description!(f, "Type: ~")?;
45-
f.write_fmt(format_args!(
46-
"{:>w$}\n\n",
47-
format!("({})", ty),
48-
w = 10 + ty.len()
49-
))?;
45+
46+
let mut table = Table::new();
47+
table.add_row([&format!("({})", ty), desc.as_deref().unwrap_or_default()]);
48+
49+
writeln!(f, "{table}")?;
5050

5151
if !see.refs.is_empty() {
5252
writeln!(f, "{}", SeeDoc(see))?;

tests/basic.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,8 @@ fn alias_and_type() {
546546
547547
---List of all the lines in the buffer
548548
---It can be more than one
549-
---@type Lines
550-
---@see something
549+
---@type Lines lines in a buffer
550+
---@see Lines
551551
U.LINES = {}
552552
553553
---Global vim mode
@@ -601,10 +601,10 @@ U.LINES *U.LINES*
601601
It can be more than one
602602
603603
Type: ~
604-
(Lines)
604+
(Lines) lines in a buffer
605605
606606
See: ~
607-
|something|
607+
|Lines|
608608
609609
610610
U.VMODE *U.VMODE*

0 commit comments

Comments
 (0)