jay-babu / mason-null-ls.nvim

GNU Affero General Public License v3.0
549 stars 22 forks source link

Not automatically installing or automatically setting up #58

Closed bartdorsey closed 1 year ago

bartdorsey commented 1 year ago

I don't know if something changed in null-ls that broke this, but right now the only way I can get this to install things is to list them out in ensure_installed. I've tried both methods of setting this up (null-ls canonical and mason-null-ls canonical) and neither one work for me...

This is with the latest versions of both null-ls and mason-null-ls.

bartdorsey commented 1 year ago

Actually so I made it work but I had to put it inside my lsp's on_attach....

jay-babu commented 1 year ago

Can you share the relevant configuration before doing what you did with the lsp handlers?

icewind commented 1 year ago

Same for me. The first option when mason-null-ls is the source of truth doesn't work for me. In that case null-ls just doesn't start. I assume they are checking if there are any sources in the configuration and if none, they skip initialization. Need to check it though. Anyway, the only option that worked for me is to disable automatic setup and clean up ensure_installed like this

local nls = require("null-ls")
nls.setup({
    sources = {
        nls.builtins.formatting.stylua,
        nls.builtins.formatting.prettierd,
        nls.builtins.diagnostics.eslint_d,
        nls.builtins.diagnostics.cspell,
    },
})
require("mason-null-ls").setup({
    automatic_installation = true,
})

Also, in my case it was order-dependent. I got it working only calling to mason-null-ls after null-ls setup.

jay-babu commented 1 year ago

Same for me. The first option when mason-null-ls is the source of truth doesn't work for me. In that case null-ls just doesn't start. I assume they are checking if there are any sources in the configuration and if none, they skip initialization. Need to check it though. Anyway, the only option that worked for me is to disable automatic setup and clean up ensure_installed like this

local nls = require("null-ls")
nls.setup({
  sources = {
      nls.builtins.formatting.stylua,
      nls.builtins.formatting.prettierd,
      nls.builtins.diagnostics.eslint_d,
      nls.builtins.diagnostics.cspell,
  },
})
require("mason-null-ls").setup({
  automatic_installation = true,
})

Also, in my case it was order-dependent. I got it working only calling to mason-null-ls after null-ls setup.

can you share the config you had tried with?

if you are using automatic_installation, order will matter. first null-ls then mason-null-ls

jay-babu commented 1 year ago

this is my config. assume null-ls got setup beforehand. i use lazy.nvim. does this work for you?

    {
        "jay-babu/mason-null-ls.nvim",
        opts = {
            ensure_installed = {
                "black",
                "google_java_format",
                "eslint_d",
                "flake8",
                "hadolint",
                "isort",
                "protolint",
                "shfmt",
                "staticcheck",
                "stylua",
                "hadolint",
                "ansiblelint",
                "rustfmt",
                "gitsigns",
                "trim_whitespace",
                "todo_comments",
            },
            handlers = {
                shellcheck = function()
                    local null_ls = require("null-ls")
                    null_ls.register(
                        null_ls.builtins.diagnostics.shellcheck.with({ diagnostics_format = "#{m} [#(c)]" })
                    )
                end,
            },
        },
    },
icewind commented 1 year ago

Not sure I understood how it should be set up from the readme, but I've tried it like this

require("null-ls").setup()
require("mason-null-ls").setup({
    ensure_installed = { "stylua", "cspell", "prettierd", "eslint" },
    automatic_setup = true,
    automatic_installation = true,
})
require("mason-null-ls").setup_handlers()
jay-babu commented 1 year ago

try the below

require("null-ls").setup()
require("mason-null-ls").setup({
    ensure_installed = { "stylua", "cspell", "prettierd", "eslint" },
    automatic_setup = true,
        handlers = {}
})
icewind commented 1 year ago

Thank you. Adding empty handlers table fixed it. Seems like it works as expected. Thanks again for help and the plugin! Great work!

bartdorsey commented 1 year ago

I think the docs definitely need a better example of how to use this with lsp_config or lsp-zero.

jay-babu commented 1 year ago

This isn't a lsp? Unsure how that would help

ralgar commented 1 year ago

EDIT: This can be disregarded. Not sure if it was an update to this plugin, or my switch to lazy.nvim, but either way the issue is resolved for me.

I've been having the same problem since v2.0. Can't for the life of me get automatic_setup working again for some reason. When I install cppcheck, open a C++ source file, and call :NullLsInfo it says there are no sources attached.

My config is a little different since I'm using user.nvim, but this is basically the same as I had it for v1.2, minus the change in setup_handlers. What I have here seems to mimic the example given above as well.

use({
    'jose-elias-alvarez/null-ls.nvim',
    config = function()
        require('null-ls').setup()
    end
})
user.flush()

use({
    'jay-babu/mason-null-ls.nvim',
    config = function()
        require('mason-null-ls').setup({
            -- Automatically configure packages on install
            automatic_setup = true,
            handlers = {}
        })
    end
})
user.flush()

Any help would be greatly appreciated.