LSP for eslint is not showing any of the errors or warnings — assistance debugging needed

Hello! I have been using nvim-lspconfig quite joyfully with solargraph (Ruby) as well as lua_ls. Love it!

However, I’m having trouble getting it to work with eslint. When I open an offensive file (one with linting errors), I don’t see anything! I need assistance debugging my setup and not sure where to turn next. Here is what I’ve looked at so far:

First, I can confirm via :LspInfo that the eslint client is attached to the buffer.

2 client(s) attached to this buffer:

Client: GitHub Copilot (id: 1, bufnr: [1])
 # ...

Client: eslint (id: 2, bufnr: [1])
	filetypes:       javascript, javascriptreact, typescript, typescriptreact, vue
	autostart:       true
	root directory:  /Users/damon/Project/my-project
	cmd:             /Users/damon/.local/share/nvim/mason/bin/vscode-eslint-language-server --stdio

Second, if I use vim-dispatch to run eslint on the file (e.g., :Dispatch yarn eslint %) I can see the errors in the quickfix window. So the file has errors.

Third, if I run :EslintFixAll in the buffer, it actually does fix the offending file in the buffer correctly! So this part is working.

That’s as far as I’ve gotten. Any ideas on how to debug this?


config


return {
  "neovim/nvim-lspconfig",

  dependencies = {
    "williamboman/mason.nvim",
    "williamboman/mason-lspconfig.nvim",
  },

  config = function()
    local lspconfig = require("lspconfig")
    local mason = require("mason")
    local mason_lspconfig = require("mason-lspconfig")

    mason.setup()

    mason_lspconfig.setup({
      ensure_installed = {
        "eslint",
        "lua_ls",
        "volar",
      },
    })

    local on_attach = function(client, bufnr)
      vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc")

      -- Mappings
      local bufopts = { noremap = true, silent = true, buffer = bufnr }
      vim.keymap.set("n", "gd", vim.lsp.buf.definition, bufopts)
      vim.keymap.set("n", "K", vim.lsp.buf.hover, bufopts)
      vim.keymap.set("n", "<space>f", function()
        vim.lsp.buf.format({ async = true })
      end, bufopts)
    end

    local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities())

    lspconfig.lua_ls.setup {
      -- ...
    }

    lspconfig.solargraph.setup {
      -- ...
    }

    lspconfig.eslint.setup {
      on_attach = on_attach,
      capabilities = capabilities,
      settings = {
        validate = "on",
        packageManager = "yarn",
      },
      root_dir = lspconfig.util.root_pattern(".eslintrc.js", ".eslintrc.json", "package.json"),
      filetypes = { "javascript", "javascriptreact", "typescript", "typescriptreact", "vue" },
    }

    vim.api.nvim_set_keymap('n', '[d', '<CMD>lua vim.diagnostic.goto_prev()<CR>', { noremap = true, silent = true })
    vim.api.nvim_set_keymap('n', ']d', '<CMD>lua vim.diagnostic.goto_next()<CR>', { noremap = true, silent = true })
  end,
}

1 Like

This suddenly stopped working for me a few days ago too. I’m guessing something happened with what mason installs because when I manually add and setup GitHub - MunifTanjim/eslint.nvim: ESLint plugin for Neovim's built-in LSP client. it starts working again.

Thanks for your response. I was hoping there would be a way to utilize it without relying on null-ls since that project was archived. I’ve been getting by without for now but sure would be nice to figure out how to get that working. Appreciate it.