Skip to content

Commit

Permalink
feat(lsp): add ts-error-translator.nvim with nice lazy loading (#774)
Browse files Browse the repository at this point in the history
  • Loading branch information
mehalter committed Mar 1, 2024
1 parent 4c21b72 commit 089a798
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lua/astrocommunity/lsp/ts-error-translator-nvim/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# ts-error-translator.nvim

A Neovim port of [Matt Pocock's ts-error-translator for VSCode](https://github.com/mattpocock/ts-error-translator) for turning messy and confusing TypeScript errors into plain English.

**Repository:** <https://github.com/dmmulroy/ts-error-translator.nvim>
24 changes: 24 additions & 0 deletions lua/astrocommunity/lsp/ts-error-translator-nvim/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
return {
-- TODO: move back to upstream after PR: https://github.com/dmmulroy/ts-error-translator.nvim/pull/18
-- "dmmulroy/ts-error-translator.nvim",
"mehalter/ts-error-translator.nvim",
branch = "reuse_existing_handler",
lazy = true,
dependencies = {
"AstroNvim/astrolsp",
---@param opts AstroLSPOpts
opts = function(_, opts)
if not opts.lsp_handlers then opts.lsp_handlers = {} end
local event = "textDocument/publishDiagnostics"
local orig = opts.lsp_handlers[event] or vim.lsp.handlers[event]
opts.lsp_handlers[event] = function(err, result, ctx, config)
local client = vim.lsp.get_client_by_id(ctx.client_id)
if client and vim.tbl_contains({ "tsserver", "vtsls" }, client.name) then
require("ts-error-translator").translate_diagnostics(err, result, ctx, config)
end
orig(err, result, ctx, config)
end
end,
},
opts = { auto_override_publish_diagnostics = false },
}

0 comments on commit 089a798

Please sign in to comment.