bash-lsp / bash-language-server

A language server for Bash

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Don't enable shellcheck linting by default

Zeioth opened this issue · comments

What is the problem this feature will solve?

On neovim, when installing bash-language-server along with shellcheck, this triggers linting two times.

What is the feature you are proposing to solve the problem?

Make shellcheck linting disabled by default, and opt-in. As linting is the responsability of a linter, not the responsability of a lsp server.

Screenshot

screenshot_2023-10-15_16-56-14_110873179

Ok after further research I managed to disable it with

local lsp_opts = {}
if server_name == "bashls" then -- by default disable shellcheck
  lsp_opts.settings = { bashIde = { shellcheckPath = "" } }
end

And while that keep the lsp capabilities, it disables the bash-language-server code actions for code fixes, which I find super valuable. So I'm closing this.

In case someone is interested, this is how I made compatilbe bash-language-server and shellcheck on my neovim config:

null-ls

--  null-ls [lsp code formatting]
--  https://github.com/nvimtools/none-ls.nvim
{
  "nvimtools/none-ls.nvim",
  dependencies = {
    {
      "jay-babu/mason-null-ls.nvim",
      cmd = { "NullLsInstall", "NullLsUninstall" },
      opts = { handlers = {} },
    },
  },
  event = "BufEnter",
  opts = function()
    local nls = require "null-ls"
    return {
      sources = {
        -- You can customize your formatters here.
        nls.builtins.formatting.beautysh.with {
          command = "beautysh",
          args = { "--indent-size=2", "$FILENAME" },
        },
        -- TODO: Disable the next feature once this has been merged.
        -- https://github.com/bash-lsp/bash-language-server/issues/933
        nls.builtins.code_actions.shellcheck,
        nls.builtins.diagnostics.shellcheck.with { diagnostics_format = "" },
      },
      on_attach = require("base.utils.lsp").on_attach,
    }
  end,
  config = function(_, opts)
    local nls = require "null-ls"
    nls.setup(opts)

    -- When running :LspStart, ensure null-ls starts too
    vim.api.nvim_create_autocmd({ "LspAttach" }, {
      desc = "Ensure null-ls run its sources a lsp client starts",
      callback = function()
        pcall(function() require("null-ls").enable({}) end)
      end,
    })

  end
},

LSP config

if server_name == "bashls" then -- by default use mason shellcheck path
  lsp_opts.settings = { bashIde = { shellcheckPath = vim.fn.stdpath "data" .. "/mason/bin/shellcheck" } }
end

This way bash-language-server has all its normal capabilities and aditionally:

  • Mason install shellcheck for us. (to eliminate external dependencies)
  • Null ls disable diagnostics, but enable code actions. (to prevent double diagnostics + adding code actions for silencing rules)

Screenshot

screenshot_2023-10-16_01-48-35_133417388