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

feat: add support for (exact) class attributes #81

Closed
wants to merge 1 commit into from
Closed
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 @@ -448,7 +448,7 @@ Classes can be used to better structure your code and can be referenced as an ar

```lua
---@comment
---@class <name>[: <parent>]
---@class [(exact)] <name>[: <parent>]
---@comment
---@field [public|protected|private] <name[?]> <type> [desc]
---@see <ref>
Expand Down
3 changes: 2 additions & 1 deletion src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ impl Lexer {
.to(Scope::Private)
.or(keyword("protected").to(Scope::Protected))
.or(keyword("package").to(Scope::Package));
let exact_attr = just("(exact)");

let hidden = private
.clone()
Expand Down Expand Up @@ -224,7 +225,7 @@ impl Lexer {
)))
.map(|(ty, (name, desc))| TagType::Return(ty, name, desc)),
just("class")
.ignore_then(space)
.ignore_then(space.ignore_then((exact_attr.ignore_then(space)).or_not()))
.ignore_then(name)
.then(just(':').padded().ignore_then(ident()).or_not())
.map(|(name, parent)| TagType::Class(name, parent)),
Expand Down
9 changes: 9 additions & 0 deletions tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ fn classes() {
---@class XMen : Homosapien
---@field power number Power quantifier

---@class (exact) XactMen
---@field power number Power quantifier

return U
";

Expand Down Expand Up @@ -181,6 +184,12 @@ XMen : Homosapien *XMen*
{power} (number) Power quantifier


XactMen *XactMen*

Fields: ~
{power} (number) Power quantifier


"
)
}
Expand Down