Skip to content

Commit

Permalink
feat: add node for Python function definitions (#157)
Browse files Browse the repository at this point in the history
* Add `function_definition` node for Python

Using parameters as target. Inspired by the same functionality in
`r.lua`.

* Add test specs for python `function_definition`

Re-using the same code as for arguments

* Add comment for `function_definition` in Python test `index.py`
  • Loading branch information
vandalt committed Jul 14, 2024
1 parent 6e8bd00 commit 4141d16
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lua/treesj/langs/python.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,7 @@ return {
'argument_list',
},
},
function_definition = {
target_nodes = { 'parameters' },
},
}
9 changes: 9 additions & 0 deletions tests/langs/python/python_join_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ local data_for_join = {
expected = { 48, 49 },
result = { 54, 55 },
},
{
path = PATH,
mode = 'join',
lang = LANG,
desc = 'lang "%s", node "function_definition", preset default',
cursor = { 55, 4 },
expected = { 48, 49 },
result = { 54, 55 },
},
{
path = PATH,
mode = 'join',
Expand Down
9 changes: 9 additions & 0 deletions tests/langs/python/python_split_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ local data_for_split = {
expected = { 54, 58 },
result = { 48, 52 },
},
{
path = PATH,
mode = 'split',
lang = LANG,
desc = 'lang "%s", node "function_deinition", preset default',
cursor = { 49, 4 },
expected = { 54, 58 },
result = { 48, 52 },
},
{
path = PATH,
mode = 'split',
Expand Down
4 changes: 2 additions & 2 deletions tests/sample/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@
end="!"
)

# RESULT OF JOIN (node "parameters", preset default)
# RESULT OF JOIN (node "parameters" and "function_definition", preset default)
def create_adder(x, b):
def adder(y):
return x + y
return adder

# RESULT OF SPLIT (node "parameters", preset default)
# RESULT OF SPLIT (node "parameters" and "function_definition", preset default)
def create_adder(
x,
b
Expand Down

0 comments on commit 4141d16

Please sign in to comment.