Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bring back [desc] support in ---@type #43

Merged
merged 1 commit into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion emmylua.md
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ You can use `---@type` to document static objects, constants etc.

```lua
---@comment
---@type <type>
---@type <type> [desc]
---@see <tag>
---@usage `<code>`
```
Expand Down
7 changes: 4 additions & 3 deletions src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ pub enum TagType {
/// ```
Variant(String, Option<String>),
/// ```lua
/// ---@type <type>
/// ---@type <type> [desc]
/// ```
Type(String),
Type(String, Option<String>),
/// ```lua
/// ---@tag <name>
/// ```
Expand Down Expand Up @@ -273,7 +273,8 @@ impl Lexer {
just("type")
.ignore_then(space)
.ignore_then(ty)
.map(TagType::Type),
.then(desc)
.map(|(ty, desc)| TagType::Type(ty, desc)),
just("tag")
.ignore_then(space)
.ignore_then(comment)
Expand Down
28 changes: 15 additions & 13 deletions src/parser/tags/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use super::Usage;

#[derive(Debug, Clone)]
pub struct Type {
pub desc: Vec<String>,
pub prefix: Prefix,
pub name: String,
pub desc: (Vec<String>, Option<String>),
pub kind: Kind,
pub ty: String,
pub see: See,
Expand All @@ -23,22 +23,24 @@ impl_parse!(Type, {
TagType::Comment(x) => x
}
.repeated()
.then(select! { TagType::Type(ty) => ty })
.then(select! { TagType::Type(ty, desc) => (ty, desc) })
.then(See::parse())
.then(Usage::parse().or_not())
.then(select! { TagType::Expr { prefix, name, kind } => (prefix, name, kind) })
.map(|((((desc, ty), see), usage), (prefix, name, kind))| Self {
desc,
prefix: Prefix {
left: prefix.clone(),
right: prefix,
.map(
|((((extract, (ty, desc)), see), usage), (prefix, name, kind))| Self {
desc: (extract, desc),
prefix: Prefix {
left: prefix.clone(),
right: prefix,
},
name,
kind,
ty,
see,
usage,
},
name,
kind,
ty,
see,
usage,
})
)
});

impl Type {
Expand Down
18 changes: 9 additions & 9 deletions src/vimdoc/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ use std::fmt::Display;

use crate::parser::Type;

use super::{description, header, see::SeeDoc, usage::UsageDoc};
use super::{description, header, see::SeeDoc, usage::UsageDoc, Table};

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

impl Display for TypeDoc<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let Type {
desc,
desc: (extract, desc),
prefix,
name,
kind,
Expand All @@ -35,18 +35,18 @@ impl Display for TypeDoc<'_> {
)
)?;

if !desc.is_empty() {
description!(f, &desc.join("\n"))?;
if !extract.is_empty() {
description!(f, &extract.join("\n"))?;
}

writeln!(f)?;

description!(f, "Type: ~")?;
f.write_fmt(format_args!(
"{:>w$}\n\n",
format!("({})", ty),
w = 10 + ty.len()
))?;

let mut table = Table::new();
table.add_row([&format!("({})", ty), desc.as_deref().unwrap_or_default()]);

writeln!(f, "{table}")?;

if !see.refs.is_empty() {
writeln!(f, "{}", SeeDoc(see))?;
Expand Down
8 changes: 4 additions & 4 deletions tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,8 @@ fn alias_and_type() {

---List of all the lines in the buffer
---It can be more than one
---@type Lines
---@see something
---@type Lines lines in a buffer
---@see Lines
U.LINES = {}

---Global vim mode
Expand Down Expand Up @@ -601,10 +601,10 @@ U.LINES *U.LINES*
It can be more than one

Type: ~
(Lines)
(Lines) lines in a buffer

See: ~
|something|
|Lines|


U.VMODE *U.VMODE*
Expand Down