python-lsp/python-lsp-ruff

Unable to disable plugin

matthewsia98 opened this issue · 6 comments

Setting enabled key here does not affect anything.
However, setting ignore key causes ruff to ignore the specified key.

pylsp settings

    local lspconfig = require("lspconfig")
    lspconfig["pylsp"].setup({
        settings = {
            pylsp = {
                plugins = {
                    ruff = {
                        enabled = false,
                        ignore = {
                            "E741",
                        },
                    },
                },
            },
        },

Without ignore key
image

With ignore key
image

Hmm, this is odd indeed, I can reproduce this issue even when setting

@hookimpl
def pylsp_settings():
    return {
        "plugins": {
            "ruff": {
                "enabled": False,
            },
        }
    }

in the package itself. Do you have any idea @ccordoba12? I think pylsp is messing up here

I checked this and (I don't know why), third-party plugins can only be disabled by passing their module names. So, the above configuration should be:

    local lspconfig = require("lspconfig")
    lspconfig["pylsp"].setup({
        settings = {
            pylsp = {
                plugins = {
                    pylsp_ruff = {
                        enabled = false,
                    },
                    ruff = {
                        ignore = {
                            "E741",
                        },
                    },
                },
            },
        },

That works for me in Spyder.

Ok, I understood what happens. Plugins are enabled/disabled according to their entry point names. In this case, that name is pylsp_ruff, not ruff:

[project.entry-points.pylsp]
pylsp_ruff = "pylsp_ruff.ruff_lint"

So, there are two possible solutions for this:

  1. Rename the entry option to be ruff. I think that's safe because the server only loads plugins decorated with @hookimpl.
  2. Rename the options namespace to be pylsp_ruff instead of ruff.

Thanks for the help @ccordoba12! I'd rather stick to 1. to keep the plugin configurations consistent. Unfortunately I am unfamiliar with pluggy, changing the pyproject.toml in you code snippet to

[project.entry-points.pylsp]
ruff = "pylsp_ruff.ruff_lint"

doesn't fix it on my side. Am I missing something?

Am I missing something?

Yes, changing the name is not enough. Afterwards, you need to uninstall the plugin and reinstall it again in development mode for the change to take effect.

I tested it locally and it works for me with Spyder, so I'll submit a PR for it.

Right, that was it. Thanks for the help!