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

Magic Racket is not recognized as a racket formatter in Jupyter Notebooks #120

Open
Maelcom opened this issue Aug 16, 2023 · 7 comments
Open
Labels
enhancement New feature or request langserver

Comments

@Maelcom
Copy link

Maelcom commented Aug 16, 2023

Environment

  • OS: Ubuntu
  • OS Version 22.04
  • VS Code Version 1.81.0
  • Racket version 8.6
  • Racket Langserver checksum 1325a43ff1962a66ce0e26901fa8c0e47fe708f7
  • Magic Racket version 0.6.6
  • IRacket kernel checksum 9af0e87d61565a9ecb41119c481e7e36c0c5287d

Steps to reproduce

  1. Set "Magic Racket" as default formatter for Racket
  2. Open .ipynb file
  3. Create a code cell with cell language set to "Racket"
  4. Try to format with the "Format Cell" command

Expected

Magic Racket formats the cell.

Actual

VS Code error message:
Extension 'Magic Racket' is configured as formatter but it cannot format 'Racket'-files

Additional context

  1. "Format Document With..." command inside .ipynb files reveals that Magic Racket is NOT present in the list of possible formatters.
    Same command inside .rkt files correctly displays Magic Racket.

  2. Same scenario with racket-fmt works correctly out of the box, so probably not complicated.

  3. Recording:

magic_racket_formatter_not_recognized_in_jupyter_notebooks.mp4
@Maelcom Maelcom added the bug Something isn't working label Aug 16, 2023
@jryans
Copy link
Collaborator

jryans commented Aug 17, 2023

Very interesting, thanks for filing this issue.

I've tried to reproduce this on my side (VS Code 1.81.1 on macOS), but I've hit an obstacle along the way... At moment, I don't see a way to choose Racket as a notebook cell language.

When I create a new notebook, the cells start out as Python by default. I can click the "Python" marker in the bottom right of the cell to get a menu of languages, but it seems to be a subset of the languages that VS Code and my extensions are aware of, as only a few of them appear there, and Racket is not one of them.

I wonder how this list of "notebook ready" languages is determined...

@Maelcom
Copy link
Author

Maelcom commented Aug 17, 2023

I can click the "Python" marker in the bottom right of the cell to get a menu of languages, but it seems to be a subset of the languages that VS Code and my extensions are aware of, as only a few of them appear there, and Racket is not one of them.

Just to make sure, did you run the second command during IRacket installation?

raco pkg install iracket
raco iracket install

https://docs.racket-lang.org/iracket/index.html

On my system that was enough for Jupyter to start seeing the new language.

@jryans jryans added enhancement New feature or request and removed bug Something isn't working labels Aug 18, 2023
@jryans
Copy link
Collaborator

jryans commented Aug 18, 2023

Ah thanks, that helped. I am now able to select Racket as a language in notebook cells.

Okay, it looks like this issue is similar to #113: this extension currently only registers itself for file documents. Notebook cells use the special vscode-notebook-cell scheme.

Just removing the filter and registered for all schemes is not enough, as presumably we need to do a bit of translation to get the content for notebook cells. Perhaps other extensions have found a good way to do that...

@Maelcom
Copy link
Author

Maelcom commented Aug 19, 2023

Perhaps other extensions have found a good way to do that

Well, racket-fmt uses a vscode.languages.registerDocumentFormattingEditProvider
inside of which it just manually takes document.getText(), passes through CLI and gets the resulting text.

Don't know if this could be applicable to LSP.

@jryans
Copy link
Collaborator

jryans commented Aug 21, 2023

Well, racket-fmt uses a vscode.languages.registerDocumentFormattingEditProvider inside of which it just manually takes document.getText(), passes through CLI and gets the resulting text.

Thanks, I noticed that as well. 🙂

In this case, it's a little different in that the language server currently assumes the document URI has a path-like shape to it. I believe the main options are either:

  • changing the language server to remove such assumptions
  • crafting a fake URL in the extension that language server is okay with

I need to review the language a bit more to make sure it does not actually use the file path to e.g. read content, and then from there I think a decent approach to move forward should become clear.

@jryans
Copy link
Collaborator

jryans commented Aug 24, 2023

At the moment, there are a few places where the language server assumes a filesystem. I have filed jeapostrophe/racket-langserver#122 to discuss this with others working on the language server.

@jryans
Copy link
Collaborator

jryans commented Sep 8, 2023

We've had a bit of progress on this front!

jeapostrophe/racket-langserver#122 has been resolved on the langserver side, which means it is now compatible with non-file documents.

The main issue that remains is that the langserver really wants #lang to be present, while IRacket wants the opposite, so it's challenging to use both for a given cell. (If you have any suggestions on what to do about this, please pass them along!)

To test out the current state:

  1. Update racket-langserver to jeapostrophe/racket-langserver@3f23f43 or beyond
  2. Install this test version of Magic Racket (which adjusts the document selector to match all document URI schemes): magic-racket.vsix.zip (Unzip the file first, drag and drop onto VS Code, reload window)

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

No branches or pull requests

2 participants