jose-elias-alvarez / nvim-lsp-ts-utils

Utilities to improve the TypeScript development experience for Neovim's built-in LSP client.
The Unlicense
438 stars 18 forks source link

[FEATURE REQUEST] Add an option to disable typescript-language-server hints #55

Closed nawordar closed 3 years ago

nawordar commented 3 years ago

Issues

Feature description

typescript-language-server in combination with a linter such as ESLint results in duplicated diagnostics, such as the diagnostic about unused variables. Both VSCode and coc offer such an option, but it is not yet built in typescript-language-server (see: https://github.com/neovim/nvim-lspconfig/issues/997).

Help

Yes, but I don't know how to start. I would need guidance

Implementation help

I have made a crude implementation in my config:

lspconfig.typescript.setup {
  on_attach = function(client, bufnr)
    on_attach(client, bufnr)

    client.handlers['textDocument/publishDiagnostics'] =
      function(err, method, result, client_id, buf_nr, config)
        local filtered_diagnostics = {}
        for _, diagnostic in ipairs(result.diagnostics) do
          if diagnostic.source ~= 'typescript' or diagnostic.severity ~= 4 then
            table.insert(filtered_diagnostics, diagnostic)
          end
        end
        result.diagnostics = filtered_diagnostics

        return vim.lsp.diagnostic.on_publish_diagnostics(
          err,
          method,
          result,
          client_id,
          buf_nr,
          config
        )
      end
  end,
}

I'm not sure where I would need to put it. client.lua seems to be the most fitting place. Maybe checking for an appropriate option inside require('nvim-lsp-ts-utils.client').setup and then setting the wrapper would be a good idea?

jose-elias-alvarez commented 3 years ago

Sure, I think it makes sense to implement this here, and I agree that that's the right approach. Your implementation looks good – let me look into this a bit more and I'll see what makes sense.

Edit: I think it would also be nice if we could make it easier for users to filter diagnostics by level, since I know a common complaint re: typescript-language-server is the inability to filter out things like the CommonJS module diagnostic.