Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect parameter list in Python #148

Closed
ColinKennedy opened this issue Jun 1, 2023 · 2 comments
Closed

Incorrect parameter list in Python #148

ColinKennedy opened this issue Jun 1, 2023 · 2 comments

Comments

@ColinKennedy
Copy link
Contributor

ColinKennedy commented Jun 1, 2023

When you have a parameter that takes an identifier as a default value, the default value shows up as a parameter in the docstring, which it should not.

docstring_incorrect_parameters.mp4

I took a try at fixing this myself by changing retrieve = "all" to retrieve = "first" and was surprised to find that didn't simply work

lua/neogen/configurations/python.lua

                                subtree = {
                                    { retrieve = "all", node_type = "identifier", extract = true, as = i.Parameter },
                                    {
                                        retrieve = "all",
                                        node_type = "default_parameter",
                                        subtree = {
                                            {
-                                               retrieve = "all",
+                                               retrieve = "first",
                                                node_type = "identifier",
                                                extract = true,
                                                as = i.Parameter,
                                            },
                                        },
                                    },

This issue may require someone more familiar with the codebase to take a look :)

@danymat danymat closed this as completed in 2f15416 Jun 7, 2023
@danymat
Copy link
Owner

danymat commented Jun 7, 2023

retrieve is used in matching_nodes_from() in nodes.lua.
retrieve = "first" will only get the first recursive element it finds, but it will not be used as recursive = false in this case. See here:

if subtree.recursive then
local first = subtree.retrieve == "first"
matched = self:recursive_find(parent, subtree.node_type, { first = first })
end

It's my fault, as the documentation does not seem precise.

To fix this specific bug, i instead used position = 1 to get the child node at the first position.

@ColinKennedy
Copy link
Contributor Author

ColinKennedy commented Jun 8, 2023

Oh I see, that makes more sense to have that as a separate argument. It's been such a breath of fresh air to use this repo, btw. Every other docstring generator project I've tried had lots of dependencies or hard to understand codebases. And Neogen re-uses snippet engines instead of rolling its own. Neogen is my favorite, by far. Thank you for making it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants