Skip to content

Commit

Permalink
Silently ignore ---@module
Browse files Browse the repository at this point in the history
Closes #39
  • Loading branch information
evaera committed Oct 2, 2021
1 parent 07b5e09 commit e39e427
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 5 deletions.
4 changes: 2 additions & 2 deletions extractor/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions extractor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "moonwave-extractor"
version = "0.1.0"
name = "moonwave"
version = "0.2.2"
authors = ["eryn L. K. <[email protected]>"]
edition = "2018"

Expand Down
16 changes: 15 additions & 1 deletion extractor/src/source_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,21 @@ impl<'a> SourceFile<'a> {
))
}
TokenType::SingleLineComment { comment } => {
if comment.starts_with('-') {
if let Some(comment) = comment.strip_prefix('-') {
if comment.len() > 1 {
if let Some(first_non_whitespace) =
comment.find(|char: char| !char.is_whitespace())
{
// Compatibility: Drop lines like `---@module <path>` used
// for Roblox LSP comments (#39)
let tag_body = &comment[first_non_whitespace..];

if tag_body.starts_with("@module") {
return None;
}
}
}

self.buffer.push(token.into_owned());
} else {
return self.flush();
Expand Down
4 changes: 4 additions & 0 deletions extractor/test-input/passing/drop_module.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--- @module hello
--- @class hi

---@module hi
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: tests/test-inputs.rs
expression: stderr

---

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
source: tests/test-inputs.rs
expression: stdout

---
[
{
"functions": [],
"properties": [],
"types": [],
"name": "hi",
"desc": "",
"source": {
"line": 3,
"path": ""
}
}
]

5 changes: 5 additions & 0 deletions extractor/tests/test-inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ fn class_with_index() -> anyhow::Result<()> {
run_moonwave("passing/class_with_index.lua", 0)
}

#[test]
fn drop_module() -> anyhow::Result<()> {
run_moonwave("passing/drop_module.lua", 0)
}

#[test]
fn triple_dash_but_wrong() -> anyhow::Result<()> {
run_moonwave("failing/triple_dash_but_wrong.lua", 1)
Expand Down

0 comments on commit e39e427

Please sign in to comment.