positron icon indicating copy to clipboard operation
positron copied to clipboard

R code cell parser issues

Open kylebutts opened this issue 1 year ago • 4 comments
trafficstars

Positron Version:

Positron-2024.06.1-27

Steps to reproduce the issue:

My favorite part of VSCode and R is the code cell feature, so I'm very excited to see support in Positron. There's a few features missing, so I wanted to flag them here. I'm happy to submit a pull request if outside contributions are welcomed? I've contributed to the R VSCode on this feature, so am aware of VSCode extension development (https://github.com/REditorSupport/vscode-R/pull/1454)

  1. Create a new R file and a new python file and insert this code:
#+
2 + 1
3 + 2 


#+ 
1 + 1

2 + 2

#+
2 + 2

#' # Hi
#' 
#' Testing `knitr::spin` markdown syntax
#' 
# %%
2 + 1
3 + 2


# %%
1 + 1

2 + 2

# %%
2 + 2
# %% [markdown]
# Hi

Testing `knitr::spin` markdown syntax

What did you expect to happen?

This is the resulting view: CleanShot 2024-06-28 at 12 57 50@2x

Here are the bugs I'm seeing

  1. Note the cells only can be one contiguous blob of code (no new lines). That is from isCellEnd: (line) => line.trim() === '',. I think the tests for this have no extra new lines, so this is not noticed. https://github.com/posit-dev/positron/blob/c929d52f6635bd35e6fa773e3b397fde32f53097/extensions/positron-code-cells/src/parser.ts#L83-L90

  2. Cold folding does not seem to work (it does in python). I'm not sure how this test is passing. When I copy the text to mine, it does not offer folding. https://github.com/posit-dev/positron/blob/c929d52f6635bd35e6fa773e3b397fde32f53097/extensions/positron-code-cells/src/test/folding.test.ts#L37-L42

  3. Pyright is creating errors for a markdown cell.

  4. knitr has markdown support via the #' syntax, but is not being recognized

  5. Also, # %% is supported by VSCode, knitr::spin(), and quarto. Would love to add that option for R: https://www.rdocumentation.org/packages/knitr/versions/1.46/topics/spin

Were there any error messages in the output or Developer Tools console?

There were not any error messages.

kylebutts avatar Jun 28 '24 17:06 kylebutts

Thanks for the feedback!

Cold folding does not seem to work (it does in python). I'm not sure how this test is passing. When I copy the text to mine, it does not offer folding.

This is #2924; we've temporarily disabled the code cell folder (which indeed used to work) until we can integrate it with the other language folding rule providers.

jmcphers avatar Jun 28 '24 17:06 jmcphers

Thanks Kyle! Aside from the issue Jonathan mentioned, the rest of your points do indeed look like bugs. Outside contributions are welcomed, please feel free to tag me in any PRs.

seeM avatar Jun 30 '24 12:06 seeM

Hi @seeM, I'm working on a PR and wanted to add more test coverage. I'm trying to figure out how to run the tests with mocha. What is the correct way to do that? Compile to out/ and then run mocha out/?

kylebutts avatar Jul 02 '24 20:07 kylebutts

I usually:

  1. Run yarn from the root positron dir.
  2. Run both yarn watch-client and yarn watch-extensions from the same dir to compile to TS on save.
  3. Run yarn test-extension -l positron-code-cells from the same dir to test the code cells extension specifically. You can additionally pass -g <grep> to grep for specific test suites/cases.

Steps 1 and 2 are both needed since these tests actually run against a build of Positron.

The VSCode contributing docs may also be helpful: https://github.com/microsoft/vscode/wiki/How-to-Contribute.

seeM avatar Jul 03 '24 12:07 seeM

Verified Fixed

Positron Version(s) : 2024.07.0-67 OS Version(s) : Windows 11

Test scenario(s)

Provided examples work as expected

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

Tests were included as part of PR

jonvanausdeln avatar Jul 18 '24 23:07 jonvanausdeln