feat(python): fixed bugs + added unittests (#189)
This commit is contained in:
@@ -38,6 +38,30 @@ local get_nearest_parent = function(node, type_name)
|
||||
end
|
||||
|
||||
|
||||
--- Remove raise (aka throw) nodes so there is only one node per-type.
|
||||
---
|
||||
---@param nodes table<string, TSNode[]> The nodes to simplify / reduce.
|
||||
local deduplicate_throw_nodes = function(nodes)
|
||||
if not nodes[i.Throw] then
|
||||
return
|
||||
end
|
||||
|
||||
local output = {}
|
||||
|
||||
local seen = {}
|
||||
|
||||
for _, node in ipairs(nodes[i.Throw]) do
|
||||
local text = helpers.get_node_text(node)[1]
|
||||
|
||||
if not vim.tbl_contains(seen, text) then
|
||||
table.insert(seen, text)
|
||||
table.insert(output, node)
|
||||
end
|
||||
end
|
||||
|
||||
nodes[i.Throw] = output
|
||||
end
|
||||
|
||||
--- Modify `nodes` if the found return(s) are **all** bare-returns.
|
||||
---
|
||||
--- A bare-return is used to return early from a function and aren't meant to be
|
||||
@@ -253,6 +277,8 @@ return {
|
||||
|
||||
validate_yield_nodes(nodes)
|
||||
|
||||
deduplicate_throw_nodes(nodes)
|
||||
|
||||
local res = extractors:extract_from_matched(nodes)
|
||||
res[i.Tparam] = temp[i.Tparam]
|
||||
|
||||
@@ -292,7 +318,7 @@ return {
|
||||
return (t[i.Parameter] or t[i.Tparam]) and { true }
|
||||
end,
|
||||
[i.HasReturn] = function(t)
|
||||
return (t[i.ReturnTypeHint] or t[i.Return]) and { true }
|
||||
return (not t[i.Yield] and (t[i.ReturnTypeHint] or t[i.Return]) and { true })
|
||||
end,
|
||||
[i.HasThrow] = function(t)
|
||||
return t[i.Throw] and { true }
|
||||
|
||||
@@ -309,7 +309,7 @@ end
|
||||
--- with multiple annotation conventions.
|
||||
---@tag neogen-changelog
|
||||
---@toc_entry Changes in neogen plugin
|
||||
neogen.version = "2.19.0"
|
||||
neogen.version = "2.19.1"
|
||||
--minidoc_afterlines_end
|
||||
|
||||
return neogen
|
||||
|
||||
Reference in New Issue
Block a user