frostplexx / mason-bridge.nvim

Automatically register linters and formatters installed in mason.nvim
MIT License
32 stars 2 forks source link

lua selene doesn't load because lua-lsp-server is already acting as linter #3

Closed Zeioth closed 4 months ago

Zeioth commented 5 months ago

Before anything else, please be aware this is my first time using this plugin, and I'm trying to get it right

Config

{
  "frostplexx/mason-bridge.nvim",
  dependencies = { "mfussenegger/nvim-lint", "stevearc/conform.nvim" },
  event = "User BaseFile",
  opts = {},
  config = function(_, opts)
    require("mason-bridge").setup(opts)
    -- Bridge lint and conform.
    require("lint").linters_by_ft = require("mason-bridge").get_linters()
    require("conform").setup({
      formatters_by_ft = require("mason-bridge").get_formatters(),
    })
  end
},

On lua, selene is not loaded

I'm using the next mason packages with the former config screenshot_2024-05-25_00-27-16_014805369

But only lua-ls and stylua load correctly. Selene doesn't seem to be loading and the diagnostics used come from lua-ls. Is this the intended behavior? (if there is already a linter, don't load more linters), or it's my config not correct?

Thank you.

frostplexx commented 5 months ago

In your case the selene is the only linter you have installed. lua-ls is the language server and stylua is a formatter. I got linters in your config working by adding the missing autocommand as described in the nvuim-lint README

return {
    "frostplexx/mason-bridge.nvim",
    dependencies = { "mfussenegger/nvim-lint", "stevearc/conform.nvim" },
    event = { "BufWritePost", "BufNewFile", "BufEnter" },
    opts = {},
    config = function(_, opts)
        require("mason-bridge").setup(opts)
        -- Bridge lint and conform.
        require("conform").setup({
            formatters_by_ft = require("mason-bridge").get_formatters(),
        })

        local lint = require("lint")
        lint.linters_by_ft = require("mason-bridge").get_linters()
        local lint_autogroup = vim.api.nvim_create_augroup("lint", { clear = true })
        vim.api.nvim_create_autocmd({ "bufenter", "bufwritepost", "insertleave" }, {
            group = lint_autogroup,
            callback = function()
                lint.try_lint()
            end,
        })
    end,
}

I also changed the event at witch the plugins are loaded as the ones you posted didn't work for me. Lastly you can check if mason-bridge is generating the correct tables by running either lua print(vim.inspect(require("mason-bridge").get_linters())) or lua print(vim.inspect(require("mason-bridge").get_formatters())) Example output of my get_linters():

{
  javascript = { "eslint_d" },
  javascriptreact = { "eslint_d" },
  json = { "jsonlint" },
  lua = { "luacheck", "selene" },
  luau = { "selene" },
  typescript = { "eslint_d" },
  typescriptreact = { "eslint_d" }
}

Though I'm not sure how nvim-lint handles multiple defined linters as there is no info about that in the README and form my testing it seems to only apply the first one in the list

Zeioth commented 4 months ago

Thank you so much @frostplexx with your config selene lints correctly.