jay-babu / mason-null-ls.nvim

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

Lazy plugin manager #52

Closed Pakrohk closed 1 year ago

Pakrohk commented 1 year ago

I feel that maybe the problem is due to my lack of knowledge, but I did the following for Lazy.nvim.

{
     "jay-babu/mason-null-ls.nvim",
     dependencies = {
            "williamboman/mason.nvim",
            "jose-elias-alvarez/null-ls.nvim",},
     lazy = false,
             config = function()
             require("packages.null-ls")
                 end,
},

What happens is that mason, null-ls and mason-null-ls are installed correctly and are even activated in the initial run (in staline the name of the formater package can be seen), but if you want to do the formatting operation Do it, you will encounter the null-ls not found message.

My English writing is not very interesting, please forgive me.

jay-babu commented 1 year ago

Can you send what this require("packages.null-ls") contains?

Pakrohk commented 1 year ago

Can you send what this require("packages.null-ls") contains?

Yes, why not :

local null_ls = require("null-ls")
local nvim_lsp = require("lspconfig")
local mason_null_ls = require("mason-null-ls")
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})

local on_attach = function(client, bufnr)
    if client.supports_method("textDocument/formatting") then
        vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
        vim.api.nvim_create_autocmd("BufWritePre", {
            group = augroup,
            buffer = bufnr,
            callback = function()
                vim.lsp.buf.format({ bufnr = bufnr })
            end,
        })
    end
end

    -- null-ls server Configure
    local b = null_ls.builtins
    local packages = {
        b.diagnostics.mypy,
        b.diagnostics.shellcheck.with({ diagnostics_format = "#{m} [#{c}]" }),
        b.formatting.black,
        b.formatting.dart_format,
        b.formatting.isort,
        b.formatting.prettier,
        b.formatting.shfmt,
        b.formatting.sql_formatter,
        b.formatting.stylua,
        b.completion.spell,
    }

    -- Null-ls Config
    null_ls.setup({
        on_attach = on_attach,
        debug = true,
        sources = packages,
    })

    -- Mason Package Manager config for null-ls
    mason_null_ls.setup({
        ensure_installed = {
            -- Write your desired package here instead of above (for people who don't like the automatic system and use space + f)
            -- for example "black"
        },
        automatic_installation = true,
        automatic_setup = false,
    })

    nvim_lsp.format_on_save = {
        pattern = { "*.lua", "*.py", "*.go" },
    }
jay-babu commented 1 year ago

do you setup mason somewhere else?

Pakrohk commented 1 year ago

do you setup mason somewhere else?

Yes I have done this in my lspconfig file. https://github.com/Pakrohk-DotFiles/NvPak/blob/Move_to_lazy/lua/packages/lspconfig.lua

We are migrating from Packer to Lazy.nvim, really the way Lazy behaves is a bit complicated to begin with.

Pakrohk commented 1 year ago
{
    "jay-babu/mason-null-ls.nvim",
    event = { "BufReadPre", "BufNewFile" },
    dependencies = {
        "williamboman/mason.nvim",
        "jose-elias-alvarez/null-ls.nvim",
        },
    config = function()
        ....
        ....
    end,
},

Well, to call the plugin, the above method must be followed

jay-babu commented 1 year ago

Sorry for the delay @Pakrohk, were you able to get it working?

Pakrohk commented 1 year ago

Sorry for the delay @Pakrohk, were you able to get it working?

Yes, in the method I mentioned in the previous message, the problem was fixed and it works fine.

Pakrohk commented 1 year ago

I think it's better to add lazy to the readme.

ecosse3 commented 1 year ago

@Pakrohk Already created #54