williamboman / mason.nvim

Portable package manager for Neovim that runs everywhere Neovim runs. Easily install and manage LSP servers, DAP servers, linters, and formatters.
Apache License 2.0
7.82k stars 275 forks source link

Server XYZ is not a valid entry in ensure_installed. #1090

Closed Arjun31415 closed 1 year ago

Arjun31415 commented 1 year ago

I've searched open issues for similar requests

Yes

I've recently downloaded the latest plugin version of mason.nvim

Problem description

ensure installed option on mason-lspconfig results in error

require("mason-lspconfig").setup {
    ensure_installed = { "lua_ls", "rust_analyzer" },
}

Expected behavior

ensure installed at least does not throw an error

Affected packages

All (not sure because it is something to do with registry)

Mason output

|| [mason-lspconfig.nvim] Server "lua_ls" is not a valid entry in ensure_installed. Make sure to only provide lspconfig server names.
|| [mason-lspconfig.nvim] Server "rust_analyzer" is not a valid entry in ensure_installed. Make sure to only provide lspconfig server names.

Installation log


[ERROR Friday 10 March 2023 08:08:05 PM] ...l/share/nvim/lazy/mason.nvim/lua/mason-registry/init.lua:77: Cannot find package "\"lua-language-server\"".
[ERROR Friday 10 March 2023 08:08:05 PM] ...l/share/nvim/lazy/mason.nvim/lua/mason-registry/init.lua:77: Cannot find package "\"rust-analyzer\"".

Neovim version (>= 0.7)

NVIM v0.9.0-dev-1187+g845efb8e1 Build type: Release LuaJIT 2.1.0-beta3

Operating system/version

 6.2.2-zen1-1-zen #1 ZEN SMP PREEMPT_DYNAMIC Fri, 03 Mar 2023 15:58:29 +0000 x86_64 GNU/Linux

Healthcheck

==============================================================================
mason: require("mason.health").check()

mason.nvim report ~
- OK neovim version >= 0.7.0
- OK **Go**: `go version go1.20.1 linux/amd64`
- OK **cargo**: `cargo 1.70.0-nightly (7d3033d2e 2023-03-08)`
- OK **luarocks**: `/usr/bin/luarocks 3.9.2`
- WARNING **Ruby**: not available
- WARNING **RubyGem**: not available
- WARNING **Composer**: not available
- WARNING **PHP**: not available
- OK **npm**: `8.19.2`
- OK **node**: `v16.19.1`
- OK **python3**: `Python 3.10.9`
- OK **pip3**: `pip 23.0.1 from /home/arjun/.local/lib/python3.10/site-packages/pip (python 3.10)`
- WARNING **javac**: not available
- OK **java**: `openjdk version "1.8.0_362"`
- WARNING **julia**: not available
- OK **wget**: `GNU Wget 1.21.3 built on linux-gnu.`
- OK **curl**: `curl 7.88.1 (x86_64-pc-linux-gnu) libcurl/7.88.1 OpenSSL/3.0.8 zlib/1.2.13 brotli/1.0.9 zstd/1.5.4 libidn2/2.3.4 libpsl/0.21.2 (+libidn2/2.3.4) libssh2/1.10.0 nghttp2/1.52.0`
- OK **gzip**: `gzip 1.12`
- OK **tar**: `tar (GNU tar) 1.34`
- WARNING **pwsh**: not available
- OK **bash**: `GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)`
- OK **sh**: `Ok`
- OK **python3_host_prog**: `Python 3.10.9`
- OK **python3_host_prog pip**: `pip 23.0.1 from /home/arjun/.local/lib/python3.10/site-packages/pip (python 3.10)`
- OK GitHub API rate limit. Used: 7. Remaining: 4993. Limit: 5000. Reset: Friday 10 March 2023 08:47:42 PM.

Screenshots

image

bjornsnoen commented 1 year ago

Not much to add except that it seems to apply to all language servers, these are from my log


[ERROR Mon 13 Mar 2023 09:28:47 AM CET] ...pack/packer/start/mason.nvim/lua/mason-registry/init.lua:77: Cannot find package "\"pyright\"".
[ERROR Mon 13 Mar 2023 09:28:47 AM CET] ...pack/packer/start/mason.nvim/lua/mason-registry/init.lua:77: Cannot find package "\"lua-language-server\"".
[ERROR Mon 13 Mar 2023 09:28:47 AM CET] ...pack/packer/start/mason.nvim/lua/mason-registry/init.lua:77: Cannot find package "\"json-lsp\"".
[ERROR Mon 13 Mar 2023 09:28:47 AM CET] ...pack/packer/start/mason.nvim/lua/mason-registry/init.lua:77: Cannot find package "\"yaml-language-server\"".
[ERROR Mon 13 Mar 2023 09:28:47 AM CET] ...pack/packer/start/mason.nvim/lua/mason-registry/init.lua:77: Cannot find package "\"taplo\"".
[ERROR Mon 13 Mar 2023 09:28:47 AM CET] ...pack/packer/start/mason.nvim/lua/mason-registry/init.lua:77: Cannot find package "\"eslint-lsp\"".
[ERROR Mon 13 Mar 2023 09:28:47 AM CET] ...pack/packer/start/mason.nvim/lua/mason-registry/init.lua:77: Cannot find package "\"omnisharp\"".```
MadoScientist97 commented 1 year ago

Yeah same here, it seems if we have lsp-install installed then it expects the names used in lsp-install and it is not the same as the the name when we install it from mason, it is a pain to find the name lsp-install expects as well.

williamboman commented 1 year ago

Make sure to set up mason.nvim before any dependents. The reason packages aren't found is because Mason hasn't been set up yet (this used to however work until recently, but it wasn't intended or supported)

Arjun31415 commented 1 year ago

Yeah it is fixed by doing above mentioned change. Thank you

bjornsnoen commented 1 year ago

In my case it wasn't quite that simple. I am sure this results in a configuration where somehow mason-lspconfig setup gets called early, but I couldn't say why. This is the packer definition for mason I had.

return {
    {
        'williamboman/mason.nvim',
        config = function()
            require('mason').setup()
        end,
    },
    {
        'williamboman/mason-lspconfig.nvim',
        requires = {
            'neovim/nvim-lspconfig',
            'williamboman/mason.nvim',
        },
        config = function()
            require('mason-lspconfig').setup({
                ensure_installed = {
                    'tsserver',
                    'pyright',
                    'lua_ls',
                    'jsonls',
                    'yamlls',
                    'taplo',
                    'eslint',
                    'omnisharp',
                },
            })
        end,
    },
    {
        'WhoIsSethDaniel/mason-tool-installer.nvim',
        requires = {
            'williamboman/mason.nvim',
        },
        config = function()
            require('mason-tool-installer').setup({
                ensure_installed = {
                    'prettierd',
                    'black',
                    'isort',
                    'cspell',
                    'stylua',
                    'debugpy',
                },
            })
        end,
    },
}

Removing neovim/nvim-lspconfig from the mason-lspconfig requirements fixes the problem for me. The nvim-lspconfig definition doesn't mention mason at all. I have no idea why it was in there though as it doesn't make sense to require nvim-lspconfig before the necessary lsp servers are installed by mason.

acampove commented 1 week ago

I have the same problem with mypy, I am using:

return {
    "williamboman/mason.nvim",
    dependencies = {
        "williamboman/mason-lspconfig.nvim",
        "WhoIsSethDaniel/mason-tool-installer.nvim",
    },
    config = function()
        -- import mason
        local mason = require("mason")

        -- import mason-lspconfig
        local mason_lspconfig = require("mason-lspconfig")

        local mason_tool_installer = require("mason-tool-installer")

        -- enable mason and configure icons
        mason.setup({
            ui = {
                icons = {
                    package_installed = "✓",
                    package_pending = "➜",
                    package_uninstalled = "✗",
                },
            },
        })

        mason_lspconfig.setup({
            -- list of servers for mason to install
            ensure_installed = {
                "lua_ls",
                "mypy",
                "clangd",
                "ltex",
                "bashls",
                "jsonls",
            },
        })

        mason_tool_installer.setup({
            ensure_installed = {
                "prettier", -- prettier formatter
                "stylua", -- lua formatter
                "isort", -- python formatter
                "pylint",
            },
        })
    end,