R-nvim / R.nvim

Neovim plugin to edit R files
GNU General Public License v3.0
178 stars 18 forks source link

Issue sending lines with an `else` statement with a curly bracket on a new line #231

Closed typhooncamel closed 2 months ago

typhooncamel commented 2 months ago

I'm encountering an issue I've not had before. When I have an if/else statement, if the opening curly bracket is on a new line, then the closing bracket is not sent. E.g.,

z = FALSE
if (isTRUE(z))
{
  x = TRUE
} else
{
  x = FALSE
}

if I'm on the if statement, and send that line, it'll send all subsequent lines, except for the last }. This is not much of an issue in this specific example, but when these are inside functions, and I try to send the function, it can lead to errors. This happens when I send a single line so that then it automatically tries sending the whole statement/function. If I visually select the function or the if/else statement above and send that, there are no problems. Any idea why?

conig commented 2 months ago

I think this is likely an issue for https://github.com/r-lib/tree-sitter-r Using :InspectTree:

Code formatted with a new line before the else statement's opening brace:

if (TRUE) {
} else
{
}

errors

(program ; [0, 0] - [8, 0]
  (if_statement ; [0, 0] - [1, 1]
    condition: (true) ; [0, 4] - [0, 8]
    consequence: (braced_expression)) ; [0, 10] - [1, 1]
  (ERROR ; [1, 2] - [3, 1]
    (ERROR))) ; [2, 0] - [3, 1]

Whereas formatted more typically:

if (TRUE) {
} else {
}

gives...

(program ; [0, 0] - [7, 0]
  (if_statement ; [0, 0] - [2, 1]
    condition: (true) ; [0, 4] - [0, 8]
    consequence: (braced_expression) ; [0, 10] - [1, 1]
    alternative: (braced_expression))) ; [1, 7] - [2, 1]
PMassicotte commented 2 months ago

I think this was fixed there: https://github.com/r-lib/tree-sitter-r/issues/141

typhooncamel commented 2 months ago

Yep, thanks!