jupyterlab-contrib / jupyterlab_code_formatter

A JupyterLab plugin to facilitate invocation of code formatters.
https://jupyterlab-code-formatter.readthedocs.io/
MIT License
853 stars 55 forks source link

Cannot add custom formatter for any of the languages listed in INCOMPATIBLE_MAGIC_LANGUAGES #298

Open flaviomartins opened 1 year ago

flaviomartins commented 1 year ago

Checklist prior to opening an issue

Describe the bug Cannot add custom formatter for any of the languages listed in INCOMPATIBLE_MAGIC_LANGUAGES

Additional context I was trying to implement a custom formatter using sqlfluff for %sql cells but it looks like some languages are disallowed in this project.

I am thinking, maybe turning INCOMPATIBLE_MAGIC_LANGUAGES blacklist into COMPATIBLE_MAGIC_LANGUAGES whitelist and make the mechanism for whitelisting additional magic_languages just having a default formatter configured for it in the preferences?

Expected behaviour If a default_formatter is configured for "sql" in the user preferences then the corresponding formatter would be called regardless

ryantam626 commented 1 year ago

FWIW I am in middle to a big refactor for the project (mostly due to the evolution of jupyterlab's plugin tooling), I can look into how to integrate sqlfluff nicely here after that.

Without the the refactor, the development envrionment for this plugin is just nightmare-ish to use, so that is currently trumping all tasks.

ryantam626 commented 1 year ago

Hello :wave: I am back with some updates.

I have completed my refactor and have some time to work on this project.

I assume you are working on sqlfluff base on this link on adding custom formatter?

A stop gap solution would be copy and paste handle_line_ending_and_magic logic and any assoicated variables needed in your custom formatter, and don't ignore the sql related magics.

I am just a bit hesitant about turning blacklist into whitelist, as I don't fully comprehend how that helps/fits in in the grand scheme of things.

With that said, I would love to add sqlfluff support, would you mind sharing what you have got if you actually implemented it :pray:

flaviomartins commented 1 year ago

Hi Ryan, I haven't hacked anything yet. I decided to go forward without this for this year's edition (of the db course).

PS: I used jupyter-lsp and sql-language-server instead but I think having the Format button would be much better to reduce variability in students code :-)

ryantam626 commented 1 year ago

Hi @flaviomartins - could you perhaps attach a notebook from your course here please?

Such that I can confirm it works for your usecase from the get go :)

flaviomartins commented 1 year ago

Hi @ryantam626, ok, I think this notebook could be our MWE

Lab02.ipynb.zip

ryantam626 commented 1 year ago

sweet! thanks, i will see what i can do, but my bandwidth is more limited these days so i will be a bit slow.