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.74k stars 272 forks source link

Mason and OpenBSD -- Is installing mason on OpenBSD pointless? #382

Closed anoduck closed 1 year ago

anoduck commented 2 years ago

Following the recommendations of others and blog entries read, I incorporated mason into my nvim configuration when I went to rewrite it. Unfortunately, I have yet to be able to facilitate the awesomeness that is mason, because it appears that mason only works with prebuilt binaries generated by repository managers, and the overwhelming majority of these only support mainstream linux distrobutions. So, it appears as if, although mason works fine on OpenBSD itself, it is not able to be facilitated on such platform.

Is there anyway that mason could, in the future, manage compilation of lsps for when a binary can not be located?

seannaswell commented 2 years ago

Here, here. Same issue with FreeBSD.

Attempted to install lua-language-server and received the following message:

...acker/start/mason.nvim/lua/mason-core/installer/init.lua:113: Could not find which release file to download.
      Most likely the current operating system, architecture (amd64), or libc (glibc) is not supported.

However, bash,css, html, elixir all installed with no issue.

anoduck commented 2 years ago

@seannaswell Wow, that is surprising. FreeBSD is extremely flexible, and possesses quite a dedicated following.

williamboman commented 2 years ago

Hello! This is related ro my comment here. For now you may see mason as a complement to other packages that you'll have to install manually. PRs or other suggestions are very welcome!

seannaswell commented 2 years ago

Well, FreeBSD and OpenBSD are a bit different than Android. They are obviously proper UNIX systems, not a mobile OS designed to run on a phone. And, a fair number of Linux users have been making the leap to the BSD's in recent years, so don't be surprised if you need to field a lot more of these kinds of inquiries as Mason becomes more popular.

I am just digging into this LSP thing, and don't yet understand if you are compiling these packages for Mason, or if it's done upstream somewhere. Can you clarify?

seannaswell commented 2 years ago

Okay, to answer my own question and provide some clarity...

Another language server package that does not install is Erlang, so I did some investigating. It appears that both Lua and Erlang have to be compiled by the user, due to a number of variables that need to be set before compiling.

So, @anoduck is correct, Mason would have to gather information about the system on which it is installed, perhaps supplemented by a configuration window with checkboxes or fields for install paths, and then compile and install the software based on those options.

In the long run it would definitely alleviate a lot of end-user confusion about having to install and maintain certain packages manually, but at the same time that sounds like a fair amount of extra functionality to implement. Wish I could help, but that is not my area of expertise.

So, going to figure out how to compile some language servers now... Thanks for your work, it definitely simplifies things for the majority of packages that I need, a lot actually...

anoduck commented 2 years ago

@seannaswell The sumneko lua language server, and the prosemd_lsp both had to be installed manually. Prosemd is just a simple cargo install prosemd-lsp (or some reasonable facsimile thereof), and although sumneko requires cloning of the repo, in my situation at least, it is a straight forward compile. Both could easily be configured to perform these operations automatically, via a shell or lua script.

Nvim is not my main editor, but is something I have been using often to make quick edits locally and on remote servers. The lightweight and fast load times make it optimal for these purposes, but I am by far a padawan on this journey. Having relied on one of those tacky prepackaged configurations after allowing my originally vimrc to deprecate into oblivion.

dch commented 1 year ago

would it make sense to add prosemd, erlang-ls and lua-lsp into FreeBSD ports? Easy enough to do, but what would need to be changed in mason to make use of this?

anoduck commented 1 year ago

@dch Little difference in compiling and installing from the ports tree and straight from the source code in my experience. Although, it is easier to have a port added to the tree in FreeBSD, than to have one added to the tree for OpenBSD. OpenBSD has very rigid standards for ports, they go through quite a lengthy and tedious testing period.

Prosemd-lsp installs on OpenBSD, but currently the sumneko only compiles with gcc11, and the defacto gcc version is currently still at 8.4. Which 8.4 being a dependency for other packages conflicts with gcc11, so only one can be installed at a time. Installing sumneko inside its own VM with gcc11 is an option, although I have not attempted it yet.

dante-robinson commented 1 year ago

@anoduck

Following the recommendations of others and blog entries read, I incorporated mason into my nvim configuration when I went to rewrite it. Unfortunately, I have yet to be able to facilitate the awesomeness that is mason, because it appears that mason only works with prebuilt binaries generated by repository managers, and the overwhelming majority of these only support mainstream linux distrobutions. So, it appears as if, although mason works fine on OpenBSD itself, it is not able to be facilitated on such platform.

Is there anyway we can open bug reports for said servers to see if they would be willing to support BSD?

anoduck commented 1 year ago

@dante-robinson Yeah, it is possible, but it is a matter of quite an undertaking. Nvim-lsp supports a staggering 215 different language servers, which is quite a lot. Out of those, I currently employ 16, which is honestly more than I realized.

Honestly, I didn't quite realize how foolish my inquiry was when I opened this issue. To make allowances to build 215 different language servers, would take a gargantuan effort.

If it is any consolidation, language servers are starting to make their way to the ports tree, and should be able to be installed from there sometime in the near future.

dante-robinson commented 1 year ago

@anoduck

@dante-robinson Yeah, it is possible, but it is a matter of quite an undertaking. Nvim-lsp supports a staggering 215 different language servers, which is quite a lot. Out of those, I currently employ 16, which is honestly more than I realized.

Not asking for every single one but I think we should at least demand basic server support 1 per langauge. I mean I can't even get clangd or a java language server through mason without some error.

If it is any consolidation, language servers are starting to make their way to the ports tree, and should be able to be installed from there sometime in the near future.

Any examples? How are these picked up by neovim does mason/nvim-lsp see them?

anoduck commented 1 year ago

@dante-robinson Full disclosure, once I realized Mason was not going to manage automated installation of servers, I removed it from my nvim configuration, and opted to keep my manual lsp server configuration. I actually learned about mason AFTER I had already configured the lsp servers by hand using the below guide. Installing servers without mason would entail the location of the server binaries not being in the default system path, but in a user defined path.

Von Heikemen has the best tutorial on how to do this. He also provides a working example, and is in general a nice guy. Setup Nvim lspconfig plus nvim cmp

Not asking for every single one but I think we should at least demand basic server support 1 per langauge. I mean I can't even get clangd or a java language server through mason without some error.

So, funny you should ask about clangd, I noticed yesterday it was installed on my system, but I have no recollection of installing it myself. This means it was installed through OpenBSD packages. In particular, it is installed through the llvm package. Because it is connected to the llvm package, which is an important system library, you are going to want to install it this way. (Keep in mind, my system follows CURRENT not RELEASE.)

Regarding java language server (jdtls), that one is going to be a bitch, the binary release was created only supporting "the big three" OSs, although you might be able to compile it yourself. :question: :man_shrugging: :question: I don't see this one remaining an obstacle for too long, though, java is too popular for that. I would not hesitate to open up an issue in the jdtls github repository.

When you do get it up and running, you will need to install the the Nvim Jdtls plugin.

Any examples? How are these picked up by neovim does mason/nvim-lsp see them?

As mentioned above, I chose to drop mason, as to my knowledge it would not provide any additional benefit to keep it. I will drop the configuration of lsp from my init file below. Keep in mind, it is in lua and I use packer to manage my plugins.


-- WARNING: This file needs it's format cleaned up.

-- This goes somewhere at the top of my config
vim.cmd([[
augroup packer_user_config
    autocmd!
    autocmd BufWritePost init.lua source <afile> | PackerCompile
augroup end
]])

-- packer configuration goes here

    -- null-ls
    use {
        'jose-elias-alvarez/null-ls.nvim',
        requires = {
            'nvim-lua/plenary.nvim',
        },
    }
    -- use prettier
    use {
        'MunifTanjim/prettier.nvim',
        config = function()
            require("prettier").setup {
                bin = 'prettierd',
                filetypes = {
                    "css",
                    "graphql",
                    "html",
                    "javascript",
                    "javascriptreact",
                    "json",
                    "less",
                    "markdown",
                    "scss",
                    "typescript",
                    "typescriptreact",
                    "yaml",
                }
            }
        end
    }
-- cmp-nvim-lsp
    use {
        'hrsh7th/cmp-nvim-lsp',
        config = function()
            require("cmp_nvim_lsp").setup {}
        end
    }

-- The important bit
-- lspconfig
use 'neovim/nvim-lspconfig'

--schemastore (being a java guy, you will want this)
-- for schema store
    use "b0o/schemastore.nvim"

-- :end: packer plugin list & :BEGIN: plugin configuration

-- For Null LS
require('null-ls').setup {
    sources = {
        require("null-ls").builtins.code_actions.gitsigns,
        require("null-ls").builtins.code_actions.shellcheck,
        require("null-ls").builtins.diagnostics.shellcheck,
        require("null-ls").builtins.diagnostics.flake8,
    },
    on_attach = function(client, bufnr)
    if client.supports_method("textDocument/formatting") then
      vim.keymap.set("n", "<Leader>f", function()
        vim.lsp.buf.format({ bufnr = vim.api.nvim_get_current_buf() })
      end, { buffer = bufnr, desc = "[lsp] format" })

      -- format on save
      vim.api.nvim_clear_autocmds({ buffer = bufnr, group = group })
      vim.api.nvim_create_autocmd('event', {
        buffer = bufnr,
        group = group,
        callback = function()
          vim.lsp.buf.format({ bufnr = bufnr, async = async })
        end,
        desc = "[lsp] format on save",
      })
    end

    if client.supports_method("textDocument/rangeFormatting") then
      vim.keymap.set("x", "<Leader>f", function()
        vim.lsp.buf.format({ bufnr = vim.api.nvim_get_current_buf() })
      end, { buffer = bufnr, desc = "[lsp] format" })
    end
  end,
}

-- lsp config

vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(
    vim.lsp.handlers.hover,
    { border = 'rounded' }
)

vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with(
    vim.lsp.handlers.signature_help,
    { border = 'rounded' }
)

-- ------------------------------------------
-- Config begins here
-- ------------------------------------------

local lspconfig = require("lspconfig")

local lsp_defaults = lspconfig.util.default_config

lsp_defaults.capabilities = vim.tbl_deep_extend(
    'force',
    lsp_defaults.capabilities,
    require('cmp_nvim_lsp').default_capabilities()
)

---
-- Diagnostic customization
---
local sign = function(opts)
  -- See :help sign_define()
  vim.fn.sign_define(opts.name, {
    texthl = opts.name,
    text = opts.text,
    numhl = ''
  })
end

sign({name = 'DiagnosticSignError', text = '✘'})
sign({name = 'DiagnosticSignWarn', text = '▲'})
sign({name = 'DiagnosticSignHint', text = '⚑'})
sign({name = 'DiagnosticSignInfo', text = ''})

-- See :help vim.diagnostic.config()
vim.diagnostic.config({
  virtual_text = false,
  severity_sort = true,
  float = {
    border = 'rounded',
    source = 'always',
    header = '',
    prefix = '',
  },
})

vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(
  vim.lsp.handlers.hover,
  {border = 'rounded'}
)

vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with(
  vim.lsp.handlers.signature_help,
  {border = 'rounded'}
)

-- -----------------------------------
-- Unsure about the following
-- ------------------------------------

local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true

---
-- LSP Keybindings
---
vim.api.nvim_create_autocmd('LspAttach', {
  group = group,
  desc = 'LSP actions',
  callback = function()
    local bufmap = function(mode, lhs, rhs)
      local opts = {buffer = true}
      vim.keymap.set(mode, lhs, rhs, opts)
    end

    -- You can search each function in the help page.
    -- For example :help vim.lsp.buf.hover()

    bufmap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<cr>')
    bufmap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<cr>')
    bufmap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<cr>')
    bufmap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<cr>')
    bufmap('n', 'go', '<cmd>lua vim.lsp.buf.type_definition()<cr>')
    bufmap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<cr>')
    bufmap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<cr>')
    bufmap('n', '<F2>', '<cmd>lua vim.lsp.buf.rename()<cr>')
    bufmap('n', '<F3>', '<cmd>lua vim.lsp.buf.format({async = true})<cr>')
    bufmap('n', '<F4>', '<cmd>lua vim.lsp.buf.code_action()<cr>')
    bufmap('x', '<F4>', '<cmd>lua vim.lsp.buf.range_code_action()<cr>')
    bufmap('n', 'gl', '<cmd>lua vim.diagnostic.open_float()<cr>')
    bufmap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<cr>')
    bufmap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<cr>')
  end
})

-----------------------------------------
-- New Config
-- -----------------------------------------

if vim.g.lsp_setup_ready == nil then
    vim.g.lsp_setup_ready = true

    lspconfig.lua_ls.setup({
        single_file_support = true,
        --[[ flags = { ]]
        --[[    debounce_text_changes = 150, ]]
        --[[ } ]]
    })

    lspconfig.jedi_language_server.setup({})
    lspconfig.bashls.setup({})
    --[[ lspconfig.ltex.setup({}) ]]
    lspconfig.prosemd_lsp.setup({})
    lspconfig.pyright.setup({})
    lspconfig.eslint.setup({})
    lspconfig.cssls.setup({
        capabilities = capabilities,
    })
    lspconfig.jsonls.setup({
        capabilities = capabilities,
    })
    lspconfig.grammarly.setup({})
    lspconfig.html.setup({
        capabilities = capabilities,
        cmd = { "vscode-html-language-server", "--stdio" },
        init_options = {
            configurationSection = { "html", "css", "javascript" },
            embeddedLanguages = {
                css = true,
                javascript = true
            },
            provideFormatter = true
        }
    })
    --[[ lspconfig.tailwindcss.setup({}) ]]
    lspconfig.tsserver.setup({})
    lspconfig.taplo.setup({})
    lspconfig.emmet_ls.setup({})
    lspconfig.yamlls.setup({
        settings = {
            yaml = {  -- Change below
                cmd = { "/home/$USER/.local/share/yarn/global/node_modules/yaml-language-server/bin/yaml-language-server",
                    "--stdio" },
                schemas = require('schemastore').json.schemas(),
            },
        }
    })
    lspconfig.beancount.setup({
        init_options = {
-- Make sure to change below.
            journal_file = "/home/$USER/Documents/beancount/my_ledger.beancount",
        }
    })
    lspconfig.awk_ls.setup({
        cmd = { "/usr/local/bin/node", "/usr/local/lib/node_modules/awk-language-server/out/cli.js" }
    })
end

Does this help any? Did I answer your questions?

badlandz commented 1 year ago

@seannaswell Wow, that is surprising. FreeBSD is extremely flexible, and possesses quite a dedicated following.

I just had the same issue in FreeBSD: https://github.com/nvim-lua/kickstart.nvim/issues/312

seannaswell commented 1 year ago

@badlandz Yeah, the vonheikemen page that @anoduck mentioned above is the best way forward.

It's both understandable and frustrating that anything other than Linux is often overlooked, but often that also leads to finding a better and simpler way...

anoduck commented 1 year ago

It might worth the investment to consider implementing vonheikemen's lsp-zero. It performs a brilliant job of interlacing both lsp and cmp together, while still allowing customization of both to occur. Of course, I personally opted out of configuration of Mason with this setup, after encountering issues with mason not recognizing BSD's tar and java commands.

Mason is quite alluring, as it is brilliantly developed to manage lsp installations and the management of various formatters. Unfortunately, it appears to be developed with solely the big three OSs in mind. If you do decide to go the manual configuration route remember to include installation and configuration of null-ls. Null-ls will provide formatting for your code.

Vonheikemen also provides a brilliantly assembled starter kit: https://github.com/VonHeikemen/nvim-starter


If anyone ever figures out how to create aliases for system commands in lua for nvim, as you would in your shell configuration, let us know. I have asked around, and been given a solution in vimscript, but not lua.

https://stackoverflow.com/questions/76262256/creation-of-aliases-for-shell-commands-in-neovim-with-lua

Happy coding, my friends.