tamago324 / nlsp-settings.nvim

A plugin for setting Neovim LSP with JSON or YAML files
MIT License
316 stars 18 forks source link

Unable to load local settings for pylsp #31

Closed LukaK closed 2 years ago

LukaK commented 2 years ago

Hi, I have issues with local settings for pylsp.

When I define local settings for a project with LspSettings local pylsp, file is created successfully under .nlsp-settings in the project root and on save I get sucess message. Unfortunatelly configuration is not applied to he project.

Here are my local settings:

{
    "pylsp.plugins.flake8.enabled": false,
    "pylsp.plugins.pylsp_mypy.enabled": false
}

If I remove local settings and apply them to global scope with LspSettings pylsp, file is successfully created under nlsp-settings in nvim directory and the configuration is loaded ok.

Here is the pylsp configuration:

    -- pylsp settings
    pylsp = {
      settings = {
        pylsp = {
          plugins = {
            pylint = { enabled = false},
            pyflakes = { enabled = false },
            -- TODO: Not configuring for local environment
            flake8 = { enabled = true},
            pycodestyle = { enabled = false },
            pydocstyle = { enabled = false },
            jedi_completion = { fuzzy = true },
            pyls_isort = { enabled = true },
            black = { enabled = true },
            -- TODO: mypy is not working in virtualenvironments
            pylsp_mypy = { enabled = true, live_mode = true, overrides ={"--cache-dir", vim.env["HOME"] .. "/.mypy_cache", true} },
            yapf = { enabled = false },
          },
        },
      },
      flags = {debounce_text_changes = 200},
    }

And here is the server setup file with lsp_installer:

nlspsettings.setup({
  config_home = vim.fn.stdpath('config') .. '/nlsp-settings',
  local_settings_dir = ".nlsp-settings",
  local_settings_root_markers = { '.git' },
  append_default_schemas = true,
  loader = 'json'
})

-- install automatically servers for which you have configurations
for server_name, _ in pairs(server_configs.options) do
  local server_is_found, server = lsp_installer.get_server(server_name)
  if server_is_found then
    if not server:is_installed() then
      vim.notify("Installing " .. server_name, "info", {title = "nvim-lsp-installer"})
      server:install()
    end
  end
end

-- Specify the default options which we'll use to setup all servers
local common_setup_opts = {
  on_attach = lsp_utils.on_attach,
  capabilities = lsp_utils.capabilities,
}

-- configure servers
-- lsp installer has to modify cmd path for servers so it
-- overwrites configurations passed with lspconfig plugin
lsp_installer.on_server_ready(function(server)
  local opts = vim.deepcopy(common_setup_opts)

  -- augment servver options
  if server_configs.options[server.name] then
    opts = vim.tbl_deep_extend('force', opts, server_configs.options[server.name])
  end

  server:setup(opts)
end)

Thank you in advance.

LukaK commented 2 years ago

Ok, did a bit of testing and it seems I have and issue with target virtual environment and plugin is working ok on other virtual environments.

Closing, and tnx for the plugin and take care :).

LukaK commented 2 years ago

Just to document the solution. The issue was how pylsp handles root directory detection and the organization of the repository. Pysl root needs to be where .nslp-settings directory is to properly load local configuration.

To change root dir configuration for pyls see neovim/nvim-lspconfig/issues/320