python-lsp / python-lsp-server

Fork of the python-language-server project, maintained by the Spyder IDE team and the community
MIT License
1.75k stars 186 forks source link

How can I specify for autopep8 to run in aggressive level 2 #495

Closed MKrbm closed 7 months ago

MKrbm commented 7 months ago
local python_folder = os.getenv("CONDA_PREFIX")
local python_executable = python_folder .. "/bin/python"
local pylsp_executable = python_folder .. "/bin/pylsp"

require("lspconfig").pylsp.setup({
    cmd = { pylsp_executable },
    filetypes = { "python" },
    settings = {
        pylsp = {
            configurationSources = { "pycodestyle" },
            formatCommand = { "autopep8" },
            plugins = {
                -- Lint
                pycodestyle = {
                    enabled = true,
                    maxLineLength = 100, -- default: 79
                },
                mypy = {
                    enabled = true,
                    live_mode = false,
                    strict = true,
                    overrides = { "--python-executable", python_executable },
                },
                -- -- Code refactor
                rope = { enabled = true }, 

                -- Formatting
                black = { enabled = false },
                pyls_isort = { enabled = false },
                yapf = { enabled = false },
                autopep8 = { enabled = true, maxLineLength = 100}, 
            },
        },
    },
})

Above is my current settings and wondering if I can specify -aa flag for autopep8. Also, is it necessary to use formatCommand here? I couldn't find any description about this in documentation but I saw this is used in more than a few configs.

I'm using pylsp with neovim's lspconfig. Thank you very much.

MKrbm commented 7 months ago

I found the solution. I could specify aggressive = 2 in the setting of autopep8.