fix: support interfaces in Java and PHP (#183)

Closes #182
This commit is contained in:
Michael Härtl
2024-08-02 16:37:02 +02:00
committed by GitHub
parent f027ac49f6
commit 88698b12c3
6 changed files with 65 additions and 16 deletions

View File

@@ -26,7 +26,7 @@ jobs:
- name: Compile Needed Parsers - name: Compile Needed Parsers
working-directory: ./neogen working-directory: ./neogen
run: | 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 - name: Run tests
working-directory: ./neogen working-directory: ./neogen

View File

@@ -1,6 +1,7 @@
local extractors = require("neogen.utilities.extractors") local extractors = require("neogen.utilities.extractors")
local nodes_utils = require("neogen.utilities.nodes") local nodes_utils = require("neogen.utilities.nodes")
local template = require("neogen.template") local template = require("neogen.template")
local i = require("neogen.types.template").item
local function_tree = { local function_tree = {
{ {
@@ -28,7 +29,7 @@ local function_tree = {
node_type = "block|constructor_body", node_type = "block|constructor_body",
subtree = { subtree = {
{ retrieve = "first", node_type = "return_statement", extract = true }, { 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", retrieve = "first",
node_type = "try_statement", node_type = "try_statement",
@@ -52,7 +53,7 @@ local function_tree = {
return { return {
parent = { parent = {
class = { "class_declaration" }, class = { "class_declaration", "interface_declaration" },
func = { "method_declaration", "constructor_declaration" }, func = { "method_declaration", "constructor_declaration" },
}, },
@@ -103,8 +104,23 @@ return {
local nodes = nodes_utils:matching_nodes_from(node, tree) local nodes = nodes_utils:matching_nodes_from(node, tree)
local res = extractors:extract_from_matched(nodes) local res = extractors:extract_from_matched(nodes)
results.class_name = res.identifier return {
return results [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, end,
}, },
}, },

View File

@@ -7,7 +7,7 @@ return {
parent = { parent = {
type = { "property_declaration", "const_declaration", "foreach_statement" }, type = { "property_declaration", "const_declaration", "foreach_statement" },
func = { "function_definition", "method_declaration" }, func = { "function_definition", "method_declaration" },
class = { "class_declaration" }, class = { "class_declaration", "interface_declaration" },
}, },
data = { data = {
type = { type = {
@@ -83,6 +83,13 @@ return {
end, end,
}, },
}, },
["interface_declaration"] = {
["0"] = {
extract = function()
return {}
end,
},
},
}, },
}, },
template = template:add_default_annotation("phpdoc"), template = template:add_default_annotation("phpdoc"),

View File

@@ -309,7 +309,7 @@ end
--- with multiple annotation conventions. --- with multiple annotation conventions.
---@tag neogen-changelog ---@tag neogen-changelog
---@toc_entry Changes in neogen plugin ---@toc_entry Changes in neogen plugin
neogen.version = "2.19.2" neogen.version = "2.19.3"
--minidoc_afterlines_end --minidoc_afterlines_end
return neogen return neogen

View File

@@ -21,13 +21,4 @@ require("plenary.busted")
vim.cmd("runtime plugin/nvim-treesitter.lua") 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" }) require("neogen").setup({ snippet_engine = "nvim" })

View File

@@ -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)