Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mattwarkentin opened this issue Aug 10, 2024 · 4 comments
Open
Assignees
Labels
enhancement New feature or request lang: r support

Comments

@mattwarkentin
Copy link

mattwarkentin commented Aug 10, 2024

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.

@jmcphers
Copy link
Collaborator

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.

@juliasilge juliasilge added enhancement New feature or request support labels Aug 11, 2024
@juliasilge juliasilge added this to the Future milestone Aug 19, 2024
@lionel- lionel- modified the milestones: Future, 2024.12.0 Pre-Release Nov 4, 2024
@lionel-
Copy link
Contributor

lionel- commented Nov 4, 2024

Reported again in #5240.

@lionel- lionel- self-assigned this Nov 18, 2024
@DavisVaughan
Copy link
Contributor

DavisVaughan commented Nov 19, 2024

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

@lionel-
Copy link
Contributor

lionel- commented Nov 22, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request lang: r support
Projects
None yet
Development

No branches or pull requests

5 participants