positron
positron copied to clipboard
Semi-colons not respected when running single line commands in R
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.
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.
Reported again in https://github.com/posit-dev/positron/discussions/5240.
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.
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.
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: