Closed wurli closed 3 months ago
Thank you for your contribution! In a quick test, it seems to work and not introduce any bugs, including in an Rnoweb file. And I agree that it's more useful to send the whole chain of piped lines than only from the current line to the end. @PMassicotte has implemented a new way of sending part of a piped chain and might want to review this pull request too.
Thank you for your review! I've just snuck in one more change to include commented lines. Now, all the lines in the following code would be sent if the cursor was placed on any of them:
# Bla
# Bla
iris |>
subset(Species == "setosa") |>
# Bla
# Bla
transform(Sepal.Area = Sepal.Length * Sepal.Width)
Again, this is the same behaviour as RStudio. If you prefer I'd be more than happy to move this commit to its own pull request.
I think it's better to keep the new commits here. Thanks!
Great, thanks! A couple more changes in line with RStudio's behaviour:
Now the following bits of code will all be sent in their entirety, regardless of where the cursor is:
2 %%
4
1:
10
!
TRUE
a?
b
list(a = 1)$
a
list(a = 1)[
"a"
]
# setClass("foo", representation(bar = "character"))
new("foo", bar = "baz")@
bar
Think this will be it for now 😁
I've temporarily closed this - I've noticed a couple more bugs I'd like to fix, then will reopen.
Let me know when it is ready to review/test!
Hi both, thanks for bearing with. After some head scratching looking for an algorithm to reliably detect code to be sent, I decided to change tack and try using treesitter. This turned out to work really well!
Now:
{ # With the cursor here, all 6 lines get sent
1 + 1 # With the cursor here, only this line gets sent
list(a = 1)$ # With the cursor here, lines 3 and 4 get sent
a # With the cursor here, lines 3 and 4 get sent
# With the cursor here, all 6 lines get sent
} # With the cursor here, all 6 lines get sent
The only slightly tricky bit was getting this to work with Quarto/R Markdown/Rnoweb, which I was able to get working by manually telling treesitter to parse the current chunk as R code. Based on my testing it all seems to work okay.
Thank you!
Rapidly browsed the code and it looks good. I will take a deeper look when I am back to home in 1-2 hr!
Excellent, many thanks 🙂
Tx for your contribution.
I'm seeing some warnings coming from the Lua server. The problems highlighted are two:
vim.treesitter.get_parser():parse()
receives only one argument (a table, according to treesitter's documentation). So, line 55 of lua/r/send.lua
should be: vim.treesitter.get_parser(0, "r"):parse({ chunk_start_row, chunk_end_row })
node
can be nil
in lines 98, 103, and 105.I will make a PR
Thanks both! For future reference - how does one check the Lua server for warnings?
As far as I remember, when you run the Lua Language Server (lua_ls
), the diagnostics are displayed by default, but diagnostics and completions of Neovim functions are available only because I have installed neodev. I also get additional diagnostics from selene
enabled by none-ls.nvim. My complete configuration is in this comment.
Many thanks! I’ll make sure to put any additional pull requests through a bit more testing using these.
For example, hitting
<CR>
with the cursor on the second line here, all 3 lines will now be sent to the console:The previous behaviour in this case was that only lines 2 and 3 would be sent, so you'd either have to go back to line 1 and re-send, or select all 3 lines before sending in visual mode.
This also works in the case of mismatched parentheses. For example, hitting
<CR>
with the cursor on the second line here will now cause both lines to be sent:The new behaviour mimics RStudio, which feels more seamless to me.
I've tested in both R scripts and Quarto.
I haven't tested with rnoweb. I understand R chunks in noweb are delimited at the start by lines like
<<my-chunk>>
, so when looking for the start of a noweb chunk I've just tested for lines beginning with<<
.