jupyterlab_code_formatter icon indicating copy to clipboard operation
jupyterlab_code_formatter copied to clipboard

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

Open flaviomartins opened this issue 2 years ago • 6 comments

Checklist prior to opening an issue

  • [x] I have followed fully the installation steps laid out in the documentation site.
  • [x] I have restarted jupyterlab.
  • [x] I have read the FAQ section in the documentation site.

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

flaviomartins avatar Mar 27 '23 21:03 flaviomartins

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 avatar May 05 '23 09:05 ryantam626

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:

ryantam626 avatar Jun 11 '23 09:06 ryantam626

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 :-)

flaviomartins avatar Jul 07 '23 16:07 flaviomartins

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 :)

ryantam626 avatar Jul 08 '23 11:07 ryantam626

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

Lab02.ipynb.zip

flaviomartins avatar Jul 11 '23 16:07 flaviomartins

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

ryantam626 avatar Jul 12 '23 08:07 ryantam626