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

feature request: use Ruff native language server for "ruff_format" #502

Open
1 task done
steakhutzeee opened this issue Jul 26, 2024 · 0 comments
Open
1 task done
Labels
enhancement New feature or request

Comments

@steakhutzeee
Copy link

steakhutzeee commented Jul 26, 2024

Did you check existing requests?

  • I have searched the existing issues

Describe the feature

Actually ruff_format formatter does not work with the native ruff language server but only with the CLI.

Provide background

See issue on Ruff astral-sh/ruff#12514

What is the significance of this feature?

strongly desired

Additional details

My actual config is:

local M = {
  'stevearc/conform.nvim'
}

function M.config()
  require("conform").setup({
    formatters_by_ft = {
      -- python = {'ruff_organize_imports', 'ruff_format'},
    },
    format_after_save = {
      lsp_format = "fallback",
    },
    notify_on_error = true,
  })
end

return M

I'm not specifying any formatter in order to fall back to the LSP. This way I can format with the native Ruff server but I can't organize imports.

EDIT: Also added the following autocommand to sort imports:

vim.api.nvim_create_autocmd({ "BufWritePost" }, {
  pattern = { "*.py" },
  callback = function()
    vim.lsp.buf.code_action {
      context = {
        only = { 'source.organizeImports.ruff' },
      },
      apply = true,
    }
  end,
})

Maybe this can be integrated in Conform somehow?

@steakhutzeee steakhutzeee added the enhancement New feature or request label Jul 26, 2024
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

No branches or pull requests

1 participant