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

Support black preview flag #35

Closed
mattishallen opened this issue Jun 24, 2022 · 9 comments
Closed

Support black preview flag #35

mattishallen opened this issue Jun 24, 2022 · 9 comments
Milestone

Comments

@mattishallen
Copy link

mattishallen commented Jun 24, 2022

Hi! I use this plugin with neovim's built in LSP and call it from vim.lsp.buf.formatting. The formatting works but it does not respect my black configurations, neither my global config in ~/.config/black nor pyproject.toml in project roots. I also have black installed from pip and there everything works fine.

pyproject.toml:

[tool.black]
line-length = 80
experimental-string-processing = true
target-version = ["py38"]
skip-string-normalization = true

pylsp-black config in init.lua:

    settings = {
      pylsp = {
        plugins = {
          black = {
            enabled = true,
            cache_config = false,
            line_length = 80,
          },

However when I format this code

image

the underlined error (line length 83 > 80) is not formatted. If i format this using black directly in a shell it is formatted.

@mattishallen mattishallen changed the title python-lsp-black does not respect my black configurations python-lsp-black does not respect black configurations Jun 24, 2022
@haplo
Copy link
Collaborator

haplo commented Jul 4, 2022

Hello @mattishallen, sorry for the late reply.

Can you look at the LSP server's log messages? python-lsp-black has logging about which configuration file is found and used. You might need to increase the logging level of LSP server.

@JesusTorrado
Copy link
Contributor

Hi both,

In case it helps, I am finding a similar issue to @mattishallen's in emacs+eglot. In particular, it is just the preview option that is not applied (in particular the string reflow), while the line length is respected.

My running pylsp configuration is

"pylsp": {
    "plugins": {
      "black": {
        "enabled": true,
        "line_length": 90,  # acknowledged
        "preview": true,  # ignored
        "cache_config": null
      }

A black --preview shell call works as expected.

My black version is 22.10.0 and my python-lsp-black version is 1.2.1.

eglot does not provide access to the LSP logs AFAIK, so not sure whether I can help much with this.

@JesusTorrado
Copy link
Contributor

Maybe setting a preview kwarg is missing in this definition?

mode = black.FileMode(

@haplo
Copy link
Collaborator

haplo commented Feb 28, 2023

@JesusTorrado
Copy link
Contributor

Hi @haplo
Not sure I understand what you are asking me to do: there is already a PR at #38

@mahmoudajawad
Copy link

@haplo any update on this? Can #38 be merged and a new release be made so we benefit from black preview features?

@haplo haplo closed this as completed in 4b80007 May 19, 2023
haplo added a commit that referenced this issue May 19, 2023
Added missing `preview` kwarg in `black.FileMode`. Fixes #35.
@haplo
Copy link
Collaborator

haplo commented May 19, 2023

I apologize for the long delay, I have merged the changes and I'm working towards making a new release with this and other changes.

@haplo haplo added this to the v1.3.0 milestone May 19, 2023
@mahmoudajawad
Copy link

@haplo, no apology needed. Everything you do is much appreciated and I thank you for making it possible for us to use black with lsp.

Keep up the good work!

@haplo haplo changed the title python-lsp-black does not respect black configurations Support black preview flag May 20, 2023
@haplo
Copy link
Collaborator

haplo commented May 20, 2023

@haplo, no apology needed. Everything you do is much appreciated and I thank you for making it possible for us to use black with lsp.

Keep up the good work!

Thank you for the kind words. ❤️ The reality is that I used to work daily with Python, so I was an active user. Now I use Python more sporadically for some personal projects, so finding time for maintenance is harder.

In other news: python-lsp-black 1.3.0 is out! 🎉

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

No branches or pull requests

4 participants