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

How to add to vim/nvim LanguageClient (or lsp-nvim)? #31

Open
RustemB opened this issue Jul 30, 2020 · 2 comments
Open

How to add to vim/nvim LanguageClient (or lsp-nvim)? #31

RustemB opened this issue Jul 30, 2020 · 2 comments

Comments

@RustemB
Copy link

RustemB commented Jul 30, 2020

How can I configure LanguageClient to use black?

@farvour
Copy link

farvour commented Mar 17, 2021

If you're using a relatively newer (v0.5+?) version of neovim, I discovered the built-in lua LanguageClient supports invoking the hook:

lua vim.lsp.buf.formatting()

So just bind this to your favorite key or setup an autocmd BufWritePre for it.

autocmd BufWritePre *.py lua vim.lsp.buf.formatting()

Just ensure you have the pyls-black option installed with your python-language-server pip package and the LS will handle the formatting for you.

@JudgeGregg
Copy link

Thank you, it does work indeed. However I had to use vim.lsp.buf.formatting_sync(), else due to the async nature of formating, the modifications appear after the file has been written to disk, hence I had to save the file twice.

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

3 participants