Skip to content

Conversation

@kv9898
Copy link
Contributor

@kv9898 kv9898 commented Oct 21, 2025

Currently, R chunks in Jupyter/Positron .ipynb notebooks cannot be formatted by Air. I brought up this issue in #405 but it was closed as it was considered "out of scope for Air" for Air. I opened another issue in posit-dev/positron#10059.

However, it turned out that by adding the following line to lsp.ts would enable Air to work for notebooks quite seamlessly:

{ language: "r", scheme: "vscode-notebook-cell" },

So I thought it would be worth writing a PR to enable this feature.

@lionel-
Copy link
Collaborator

lionel- commented Oct 22, 2025

Thanks a lot for taking a look at this!

It does work quite well but we're adding a newline at the end of chunks that shouldn't be there:

Screen.Recording.2025-10-22.at.11.02.32.mov

ruff explicitly trims this newline: https://github.com/astral-sh/ruff/blob/6271fba1e1c01c9c49a360b1084217955145bce6/crates/ruff_server/src/server/api/requests/format.rs#L121-L134

Would you like to also take a look at this issue? It would involve detecting cell URIs in the format request handler to trim the result before creating edits. I'm also happy to take it from here, just let me know.

@kv9898
Copy link
Contributor Author

kv9898 commented Oct 22, 2025

@lionel- I also noted this, but i thought this was the desired behaviour. I would love to have a look but it will probably take me (or claude) a while to find out which part of the codebase is responsible for this.

Is there anything that stops us from mimicking ruff's solution?

BTW: i've also fixed the 2 PRs to ark.

* Initial plan

* Fix empty line at end of R chunks in notebooks

- Add check for vscode-notebook-cell scheme in document_formatting
- Remove trailing newline for notebook cells to avoid empty line
- Add test cases for notebook cell formatting
- Range formatting already handled correctly

Co-authored-by: kv9898 <[email protected]>
@kv9898
Copy link
Contributor Author

kv9898 commented Oct 22, 2025

@lionel- I think copilot did a pretty good job fixing the end-of-chunk empty line issue.

Note: if the empty line at then end is the only thing to be fixed, my current version would ignore it. But it won't add new empty lines, and, if there are other problems to be fixed, the trailing empty line would be removed.

@lionel-
Copy link
Collaborator

lionel- commented Oct 23, 2025

I notice that if there is an existing trailing newline, it is still preserved. If there is more, they are all stripped. I think this is behaviour from the notebook extension, probably to avoid removing line breaks when editing:

Screen.Recording.2025-10-23.at.12.01.08.mov

Thanks a lot for this contribution @kv9898, I'm very happy to have notebook cell support!

@lionel- lionel- merged commit e3655e9 into posit-dev:main Oct 23, 2025
8 checks passed
@kv9898 kv9898 deleted the feature/support-notebooks branch October 23, 2025 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants