Capturing multiline code chunks
sdavidsson90 opened this issue · 4 comments
I rely on treesitter functionality to send multiline codechunks into an interactive REPL-window using iron.nvim.
I want to be able to capture semantic blocks, specifically using the function ["af"] = "@function.outer",
(described in this section) and send them to the REPL in one motion, as suggested by the plugin author in an issue I opened on the project's repo.
Sending the code:
add_10 <- function(x){
x = x + 10
print(x)
}
add_10(100)
add_20 <- function(x){
x = x + 20
print(x)
}
add_20(100)
Returns the output:
> function(x){
x = x + 10
print(x)
}
function(x){
x = x + 10
print(x)
Not quite what I was expecting. Further calling the following afterwards:
iris |>
head()
Returns:
>
Nothing. Same with the magrittr-pipe.
This works correctly for Bash and Python, but not for R. I therefore suspect this might be a bug.
I will also admit that my grasp of treesitter is still very limited, so I might be doing someting wrong.
Does anyone have an idea on how to overcome this issue?
FYI, we figured out a way to do this in R.nvim
by checking if the surrounding node is either "program"
or "brace_list"
.
FWIW we are planning to merge the next branch into main soon, and we are going to freeze main as something like old-main, so you'll likely have to rework that a little or pin to old-main
Thanks for the heads up!
From what I can tell, I don't think there is anything wrong on the tree-sitter-r side, so I'm going to close. The R.nvim approach seems reasonable