Skip to content

feature request: add pyright's pyright.organizeimports #466

@carschandler

Description

@carschandler

Did you check existing requests?

  • I have searched the existing issues

Describe the feature

pyright (and basedpyright) provides a pyright.organizeimports (basedpyright.organizeimports) command that organizes Python imports. It would be nice to be able to simply specify my Python config in conform like

python = { "pyright_organize_imports", "black" }

Provide background

My current workflow is to use the :PyrightOrganizeImports command provided by lspconfig, but it would be much nicer to have this as part of conform so that it weaves into the auto-formatting workflow. I'd like to achieve this without having to install a separate program just for organizing imports. It's just a couple of lines of lua in lspconfig that define the command, but given that this is technically part of the LSP, I'm not sure if this disqualifies it from being part of conform.

This seems pretty straightforward to implement... if someone could point me in the right direction for the idiomatic way to implement a simple lua function as the command, I'd be happy to open a PR!

What is the significance of this feature?

nice to have

Additional details

Command from lspconfig:

local function organize_imports()
  local params = {
    command = 'pyright.organizeimports',
    arguments = { vim.uri_from_bufnr(0) },
  }

  local clients = util.get_lsp_clients { -- This is just a one-liner function that could be extracted
    bufnr = vim.api.nvim_get_current_buf(),
    name = 'pyright',
  }
  for _, client in ipairs(clients) do
    client.request('workspace/executeCommand', params, nil, 0)
  end
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions