positron icon indicating copy to clipboard operation
positron copied to clipboard

Semi-colons not respected when running single line commands in R

Open mattwarkentin opened this issue 1 year ago • 1 comments

Hi,

Running a line of code with Cmd + Enter does not work as expected (or as it does in RStudio) when using semi-colons to separate commands. I know this is probably not a recommend practice, but nevertheless it should probably work.

x = 1; y = 2; z = 3

Running this will create x only and jump down the editor to the next command on a new line, but does not create y or z. In RStudio all three objects would be created, and this is what happens if you run the code directly in the console.

mattwarkentin avatar Aug 10 '24 23:08 mattwarkentin

image

Can confirm! Happens because we try to run one statement at a time and this is (technically) three statements. Agree the behavior doesn't make sense, though; RStudio's behavior is would be preferable.

jmcphers avatar Aug 11 '24 00:08 jmcphers

Reported again in https://github.com/posit-dev/positron/discussions/5240.

lionel- avatar Nov 04 '24 10:11 lionel-

I happened to be in the vicinity of this today. A few things to note about what ark does:

Consider 1; 2

  • Regardless of where you put your cursor in there, ark sends back [(0, 0), (0, 1)] as the Range to execute. This is because ark actually ignores the column position of the cursor, and only uses the row position of the cursor and works from there.
  • Semicolons currently don't exist in the tree-sitter-r grammar. i.e. you see a float at [(0, 0), (0, 1)] and another float at [(0, 3), (0, 4)] and everything else looks like whitespace.

Given that we don't see semicolons, I'm not 100% sure what to do to fix this yet. But it's probably something like

"if the end column of the node you are about to select doesn't end at the end of the line (and there isnt a trailing comment), then you probably have something else on this line, so expand your node search and don't return this partial line node"

Or maybe similarly we could check if the following sibling starts on the same line as the node ends on, which I think can only happen if there is a semicolon. That seems like it may work as a signal to keep expanding.

Image

DavisVaughan avatar Nov 19 '24 22:11 DavisVaughan

I see. I wouldn't mind using the R parser for this though, the potential inconsistencies do not worry me here.

So if the whole line at point parses completely with the R parser, we just return the line range.

lionel- avatar Nov 22 '24 15:11 lionel-

Verified Fixed

Positron Version(s) : 2025.01.0-50
OS Version          : OSX

Test scenario(s)

Tested with initial filing scenario.

Link(s) to TestRail test cases run or created:

testlabauto avatar Dec 10 '24 14:12 testlabauto