Skip to content

Commit bcb0a38

Browse files
authored
feat: support ---@{protected,package,public} (#71)
This adds support for `---@protected`, and `---@package` which act precisely as `---@private`, which is already implemented, hiding any node from the vimdoc. And `---@public` support, which gets parsed and stripped away and doesn't affect vimdoc in any way.
1 parent 4353a66 commit bcb0a38

File tree

4 files changed

+23
-15
lines changed

4 files changed

+23
-15
lines changed

emmylua.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -694,12 +694,18 @@ U.VMODE *U.VMODE*
694694

695695
### Private
696696

697-
This tag can be used to discard any part of the code that is exported but it is not considered to be a part of the public API
697+
One of the following tags can be used to discard any part of the code that is not considered a part of the public API. All these tags behaves exactly same when it comes to vimdoc generation but have different use cases when used together with LLS.
698+
699+
- Spec: [`---@private`](https://github.com/sumneko/lua-language-server/wiki/Annotations#private), [`---@protected`](https://github.com/sumneko/lua-language-server/wiki/Annotations#protected), [`---@package`](https://github.com/sumneko/lua-language-server/wiki/Annotations#package)
698700

699701
- Syntax
700702

701703
```lua
702704
---@private
705+
706+
---@protected
707+
708+
---@package
703709
```
704710

705711
- Input
@@ -719,9 +725,9 @@ function U.ok()
719725
print('Ok! I am exported')
720726
end
721727

722-
---@private
728+
---@protected
723729
function U.no_emmy()
724-
print('Private func with no emmylua!')
730+
print('Protected func with no emmylua!')
725731
end
726732

727733
return U

src/lexer.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ impl Lexer {
2727
let comment = till_eol.map(|(x, _)| x.iter().collect());
2828
let desc = space.ignore_then(comment).or_not();
2929

30-
let scope = choice((
31-
keyword("public").to(Scope::Public),
32-
keyword("protected").to(Scope::Protected),
33-
keyword("private").to(Scope::Private),
34-
));
35-
36-
let private = just("private")
37-
.then_ignore(newline())
30+
let public = keyword("public").to(Scope::Public);
31+
let private = keyword("private")
32+
.to(Scope::Private)
33+
.or(keyword("protected").to(Scope::Protected))
34+
.or(keyword("package").to(Scope::Package));
35+
36+
let hidden = private
37+
.clone()
38+
.ignore_then(newline())
3839
.then_ignore(choice((
3940
// eat up all the emmylua, if any, then one valid token
4041
triple
@@ -181,7 +182,7 @@ impl Lexer {
181182
});
182183

183184
let tag = just('@').ignore_then(choice((
184-
private.to(TagType::Skip),
185+
hidden.or(public.clone().ignored()).to(TagType::Skip),
185186
just("toc")
186187
.ignore_then(space)
187188
.ignore_then(comment)
@@ -226,7 +227,7 @@ impl Lexer {
226227
.then(just(':').padded().ignore_then(ident()).or_not())
227228
.map(|(name, parent)| TagType::Class(name, parent)),
228229
just("field")
229-
.ignore_then(space.ignore_then(scope).or_not())
230+
.ignore_then(space.ignore_then(private.or(public)).or_not())
230231
.then_ignore(space)
231232
.then(ident())
232233
.then(optional)

src/lexer/token.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ pub enum Scope {
153153
Public,
154154
Private,
155155
Protected,
156+
Package,
156157
}
157158

158159
#[derive(Debug, Clone, PartialEq, Eq, Hash)]

tests/basic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,9 +676,9 @@ fn private() {
676676
print('Ok! I am exported')
677677
end
678678
679-
---@private
679+
---@protected
680680
function U.no_emmy()
681-
print('Private func with no emmylua!')
681+
print('Protected func with no emmylua!')
682682
end
683683
684684
return U

0 commit comments

Comments
 (0)