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 textDocument/formatting #61

Closed
qbedard opened this issue Jan 27, 2023 · 5 comments · Fixed by #64
Closed

Support textDocument/formatting #61

qbedard opened this issue Jan 27, 2023 · 5 comments · Fixed by #64
Labels
enhancement New feature or request

Comments

@qbedard
Copy link

qbedard commented Jan 27, 2023

It looks like the only way to have ruff-lsp format a document right now is via a textDocument/codeAction. From my experience, most LSP servers allow document formatting via textDocument/formatting.

It took me a bit to realize, because the example Neovim config registers a keymap for vim.lsp.buf.format(), so I was a bit baffled trying to use that to format a file, as ruff-lsp does nothing when that request is issued right now.

@charliermarsh charliermarsh added the enhancement New feature or request label Jan 27, 2023
@kalekseev
Copy link

Not sure what the convention for linter lsps and formatting command but at least something like RuffFixAll command would be helpful, this is how eslint do it https://github.com/neovim/nvim-lspconfig/blob/d005193b6476088ff032607baca07b1bbbeb36ee/lua/lspconfig/server_configurations/eslint.lua#L165

@kalekseev
Copy link

For example if someone setup null-ls with black and ruff-lsp that support formatting then he will need to control which lsp should handle formatting command https://github.com/jose-elias-alvarez/null-ls.nvim/wiki/Formatting-on-save#choosing-a-client-for-formatting

@charliermarsh
Copy link
Member

charliermarsh commented Feb 6, 2023

We actually do support that -- it's used in the VS Code extension. So we support source.fixAll, source.fixAll.ruff, and a special ruff.applyAutofix. The latter has to be configured by clients though since it's a custom command, so I think it requires some configuration on a per-client basis? I'd love to see an example if someone can get it working in the Lua config.

@kalekseev
Copy link

I think RuffFixAll command should be added to the nvim-lspconfig see my link how eslint do this in nvim-lspconfig.

@Jackevansevo
Copy link

Jackevansevo commented Mar 28, 2023

I'm still seeing this issue. Testing in neovim, using the configuration listed here: https://beta.ruff.rs/docs/editor-integrations/#language-server-protocol-official

Running

:lua vim.lsp.buf.format()
[LSP] Format request failed, no matching language servers

Can confirm this by querying the client capabilities itself (prints false)

local on_attach = function(client, bufnr)
    print(client.supports_method("textDocument/formatting"))
end

I can see 9f289ec got reverted, so unsure whether this is a config issue, or something that hasn't landed in main yet

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

Successfully merging a pull request may close this issue.

4 participants