From e39e427cbc438b999b67d8ae984fd6ac33b72413 Mon Sep 17 00:00:00 2001 From: Eryn Lynn Date: Sat, 2 Oct 2021 01:12:33 -0400 Subject: [PATCH] Silently ignore ---@module Closes #39 --- extractor/Cargo.lock | 4 ++-- extractor/Cargo.toml | 4 ++-- extractor/src/source_file.rs | 16 +++++++++++++++- extractor/test-input/passing/drop_module.lua | 4 ++++ ...puts__passing__drop_module.lua-stderr.snap | 6 ++++++ ...puts__passing__drop_module.lua-stdout.snap | 19 +++++++++++++++++++ extractor/tests/test-inputs.rs | 5 +++++ 7 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 extractor/test-input/passing/drop_module.lua create mode 100644 extractor/tests/snapshots/test_inputs__passing__drop_module.lua-stderr.snap create mode 100644 extractor/tests/snapshots/test_inputs__passing__drop_module.lua-stdout.snap diff --git a/extractor/Cargo.lock b/extractor/Cargo.lock index ac61ea9..3a2936d 100644 --- a/extractor/Cargo.lock +++ b/extractor/Cargo.lock @@ -245,8 +245,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" [[package]] -name = "moonwave-extractor" -version = "0.1.0" +name = "moonwave" +version = "0.2.2" dependencies = [ "anyhow", "codespan-reporting", diff --git a/extractor/Cargo.toml b/extractor/Cargo.toml index 12e6ce2..330d488 100644 --- a/extractor/Cargo.toml +++ b/extractor/Cargo.toml @@ -1,6 +1,6 @@ [package] -name = "moonwave-extractor" -version = "0.1.0" +name = "moonwave" +version = "0.2.2" authors = ["eryn L. K. "] edition = "2018" diff --git a/extractor/src/source_file.rs b/extractor/src/source_file.rs index e2be904..a63f795 100644 --- a/extractor/src/source_file.rs +++ b/extractor/src/source_file.rs @@ -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 ` 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(); diff --git a/extractor/test-input/passing/drop_module.lua b/extractor/test-input/passing/drop_module.lua new file mode 100644 index 0000000..de506dc --- /dev/null +++ b/extractor/test-input/passing/drop_module.lua @@ -0,0 +1,4 @@ +--- @module hello +--- @class hi + +---@module hi \ No newline at end of file diff --git a/extractor/tests/snapshots/test_inputs__passing__drop_module.lua-stderr.snap b/extractor/tests/snapshots/test_inputs__passing__drop_module.lua-stderr.snap new file mode 100644 index 0000000..15f0a72 --- /dev/null +++ b/extractor/tests/snapshots/test_inputs__passing__drop_module.lua-stderr.snap @@ -0,0 +1,6 @@ +--- +source: tests/test-inputs.rs +expression: stderr + +--- + diff --git a/extractor/tests/snapshots/test_inputs__passing__drop_module.lua-stdout.snap b/extractor/tests/snapshots/test_inputs__passing__drop_module.lua-stdout.snap new file mode 100644 index 0000000..b337d78 --- /dev/null +++ b/extractor/tests/snapshots/test_inputs__passing__drop_module.lua-stdout.snap @@ -0,0 +1,19 @@ +--- +source: tests/test-inputs.rs +expression: stdout + +--- +[ + { + "functions": [], + "properties": [], + "types": [], + "name": "hi", + "desc": "", + "source": { + "line": 3, + "path": "" + } + } +] + diff --git a/extractor/tests/test-inputs.rs b/extractor/tests/test-inputs.rs index 8908e32..d414f75 100644 --- a/extractor/tests/test-inputs.rs +++ b/extractor/tests/test-inputs.rs @@ -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)