diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4405a7e..d1536ca 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,7 +26,7 @@ jobs: - name: Compile Needed Parsers working-directory: ./neogen run: | - nvim -u tests/minimal_init.lua --headless -c "TSInstallSync python lua julia" -c "q" + nvim -u tests/minimal_init.lua --headless -c "TSInstallSync python lua julia java" -c "q" - name: Run tests working-directory: ./neogen diff --git a/lua/neogen/configurations/java.lua b/lua/neogen/configurations/java.lua index f6be31c..34119c5 100644 --- a/lua/neogen/configurations/java.lua +++ b/lua/neogen/configurations/java.lua @@ -1,6 +1,7 @@ local extractors = require("neogen.utilities.extractors") local nodes_utils = require("neogen.utilities.nodes") local template = require("neogen.template") +local i = require("neogen.types.template").item local function_tree = { { @@ -28,7 +29,7 @@ local function_tree = { node_type = "block|constructor_body", subtree = { { retrieve = "first", node_type = "return_statement", extract = true }, - { retrieve = "all", recursive = true, node_type = "throw_statement", extract = true }, + { retrieve = "all", recursive = true, node_type = "throw_statement", extract = true }, { retrieve = "first", node_type = "try_statement", @@ -52,7 +53,7 @@ local function_tree = { return { parent = { - class = { "class_declaration" }, + class = { "class_declaration", "interface_declaration" }, func = { "method_declaration", "constructor_declaration" }, }, @@ -103,8 +104,23 @@ return { local nodes = nodes_utils:matching_nodes_from(node, tree) local res = extractors:extract_from_matched(nodes) - results.class_name = res.identifier - return results + return { + [i.ClassName] = res.identifier + } + end, + }, + }, + ["interface_declaration"] = { + ["0"] = { + extract = function(node) + local results = {} + local tree = { { retrieve = "all", node_type = "identifier", extract = true } } + local nodes = nodes_utils:matching_nodes_from(node, tree) + local res = extractors:extract_from_matched(nodes) + + return { + [i.ClassName] = res.identifier + } end, }, }, diff --git a/lua/neogen/configurations/php.lua b/lua/neogen/configurations/php.lua index b808b2c..45bd54c 100644 --- a/lua/neogen/configurations/php.lua +++ b/lua/neogen/configurations/php.lua @@ -7,7 +7,7 @@ return { parent = { type = { "property_declaration", "const_declaration", "foreach_statement" }, func = { "function_definition", "method_declaration" }, - class = { "class_declaration" }, + class = { "class_declaration", "interface_declaration" }, }, data = { type = { @@ -83,6 +83,13 @@ return { end, }, }, + ["interface_declaration"] = { + ["0"] = { + extract = function() + return {} + end, + }, + }, }, }, template = template:add_default_annotation("phpdoc"), diff --git a/lua/neogen/init.lua b/lua/neogen/init.lua index 2c67cbf..70d3403 100644 --- a/lua/neogen/init.lua +++ b/lua/neogen/init.lua @@ -309,7 +309,7 @@ end --- with multiple annotation conventions. ---@tag neogen-changelog ---@toc_entry Changes in neogen plugin -neogen.version = "2.19.2" +neogen.version = "2.19.3" --minidoc_afterlines_end return neogen diff --git a/tests/minimal_init.lua b/tests/minimal_init.lua index 19dd321..4ef58a9 100644 --- a/tests/minimal_init.lua +++ b/tests/minimal_init.lua @@ -21,13 +21,4 @@ require("plenary.busted") vim.cmd("runtime plugin/nvim-treesitter.lua") --- -- Some tests require the Python parser --- -- vim.cmd([[TSInstallSync! python]]) --- require("nvim-treesitter.configs").setup({ --- ensured_installed = { --- "python", --- "lua" --- } --- }) - require("neogen").setup({ snippet_engine = "nvim" }) diff --git a/tests/neogen/java_javadoc_spec.lua b/tests/neogen/java_javadoc_spec.lua new file mode 100644 index 0000000..1ba5383 --- /dev/null +++ b/tests/neogen/java_javadoc_spec.lua @@ -0,0 +1,35 @@ +--- Test cases for emmylua +--- +--- @module 'tests.neogen.lua_spec' + +local specs = require('tests.utils.specs') + +local function make_emmylua(source, type) + return specs.make_docstring(source, 'java', { type = type, annotation_convention = { java = 'javadoc' } }) +end + +describe("java: javadoc", function() + describe("class", function() + it("works with an basic interface", function() + local source = [[ + public interface Entity { + @NonNull UUID getId();|cursor| + } + ]] + + local expected = [[ + /** + * [TODO:description] + * + */ + public interface Entity { + @NonNull UUID getId(); + } + ]] + + local result = make_emmylua(source, "class") + + assert.equal(expected, result) + end) + end) +end)