Skip to content

Commit

Permalink
fix: support interfaces in Java and PHP (#183)
Browse files Browse the repository at this point in the history
Closes #182
  • Loading branch information
mikehaertl authored Aug 2, 2024
1 parent f027ac4 commit 88698b1
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 20 additions & 4 deletions lua/neogen/configurations/java.lua
Original file line number Diff line number Diff line change
@@ -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 = {
{
Expand Down Expand Up @@ -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",
Expand All @@ -52,7 +53,7 @@ local function_tree = {

return {
parent = {
class = { "class_declaration" },
class = { "class_declaration", "interface_declaration" },
func = { "method_declaration", "constructor_declaration" },
},

Expand Down Expand Up @@ -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,
},
},
Expand Down
9 changes: 8 additions & 1 deletion lua/neogen/configurations/php.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -83,6 +83,13 @@ return {
end,
},
},
["interface_declaration"] = {
["0"] = {
extract = function()
return {}
end,
},
},
},
},
template = template:add_default_annotation("phpdoc"),
Expand Down
2 changes: 1 addition & 1 deletion lua/neogen/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 0 additions & 9 deletions tests/minimal_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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" })
35 changes: 35 additions & 0 deletions tests/neogen/java_javadoc_spec.lua
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 88698b1

Please sign in to comment.