From 88c4d400787d0bf6ebfc3d64fca47586d34696cf Mon Sep 17 00:00:00 2001 From: Daniel Mathiot Date: Mon, 23 Aug 2021 18:31:22 +0200 Subject: [PATCH] Support for optional params in python --- lua/neogen/configurations/python.lua | 37 ++++++++++++++++++---------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/lua/neogen/configurations/python.lua b/lua/neogen/configurations/python.lua index 5ae40ac..6b658fd 100644 --- a/lua/neogen/configurations/python.lua +++ b/lua/neogen/configurations/python.lua @@ -16,25 +16,38 @@ return { local params = neogen.utilities.nodes:matching_child_nodes(node, "parameters")[1] - local regular_params - local typed_params_node + local found_nodes if #params ~= 0 then + -- Find regular parameters - regular_params = neogen.utilities.extractors:extract_children_text("identifier")(params) + local regular_params = neogen.utilities.extractors:extract_children_text("identifier")(params) if #regular_params == 0 then regular_params = nil end results.parameters = regular_params - -- Find typed params - typed_params_node = neogen.utilities.nodes:matching_child_nodes(params, "typed_parameter") - for _,_node in pairs(typed_params_node) do - local typed_params = neogen.utilities.extractors:extract_children_text("identifier")(_node)[1] - table.insert(results.parameters, typed_params) + -- Find regular optional parameters + found_nodes = neogen.utilities.nodes:matching_child_nodes(params, "default_parameter") + for _,_node in pairs(found_nodes) do + local _params = neogen.utilities.extractors:extract_children_text("identifier")(_node)[1] + table.insert(results.parameters, _params) + end + + -- Find typed params + found_nodes = neogen.utilities.nodes:matching_child_nodes(params, "typed_parameter") + for _,_node in pairs(found_nodes) do + local _params = neogen.utilities.extractors:extract_children_text("identifier")(_node)[1] + table.insert(results.parameters, _params) + end + + -- TODO Find optional typed params + found_nodes = neogen.utilities.nodes:matching_child_nodes(params, "typed_default_parameter") + for _,_node in pairs(found_nodes) do + local _params = neogen.utilities.extractors:extract_children_text("identifier")(_node)[1] + table.insert(results.parameters, _params) end - -- TODO Find optional params end local body = neogen.utilities.nodes:matching_child_nodes(node, "block")[1] @@ -46,11 +59,9 @@ return { if #return_statement == 0 then return_statement = nil end + results.return_statement = return_statement - return { - parameters = regular_params, - return_statement = return_statement - } + return results end }, },