|
| 1 | +# ts-error-translator.nvim |
| 2 | + |
| 3 | +**Generated:** 2026-01-03 | **Commit:** c1e6a55 | **Branch:** main |
| 4 | + |
| 5 | +Neovim plugin translating TypeScript errors to human-readable messages. Port of Matt Pocock's VSCode extension. |
| 6 | + |
| 7 | +## Structure |
| 8 | + |
| 9 | +``` |
| 10 | +lua/ts-error-translator/ |
| 11 | + init.lua -- Public API: setup(), parse_errors() |
| 12 | + diagnostic.lua -- Wraps vim.lsp.handlers["textDocument/publishDiagnostics"] |
| 13 | + parser.lua -- Core logic, LRU-cached |
| 14 | + matcher.lua -- vim.regex pattern matching |
| 15 | + db.lua -- GENERATED: error code -> translation lookup |
| 16 | + lru.lua -- LRU cache (100 entries) |
| 17 | + utils.lua -- fill_body_with_items() |
| 18 | +
|
| 19 | +errors/ -- 67 markdown files, source data for db.lua |
| 20 | +tests/spec/ -- Plenary test specs (*_spec.lua) |
| 21 | +tests/fixtures/ -- Real TS files triggering specific errors |
| 22 | +``` |
| 23 | + |
| 24 | +## Where to Look |
| 25 | + |
| 26 | +| Task | Location | |
| 27 | +|------|----------| |
| 28 | +| Add error translation | `errors/{code}.md` then `make build` | |
| 29 | +| Plugin config/setup | `lua/ts-error-translator/init.lua` | |
| 30 | +| LSP integration | `lua/ts-error-translator/diagnostic.lua` | |
| 31 | +| Error parsing | `lua/ts-error-translator/parser.lua` | |
| 32 | +| Pattern matching | `lua/ts-error-translator/matcher.lua` | |
| 33 | + |
| 34 | +## Module Flow |
| 35 | + |
| 36 | +``` |
| 37 | +setup() -> diagnostic.setup() -> wraps LSP handler |
| 38 | + | |
| 39 | + v |
| 40 | + parser.parse_errors() |
| 41 | + | |
| 42 | + +------------+------------+ |
| 43 | + | | | |
| 44 | + db.lua matcher.lua lru.lua |
| 45 | +``` |
| 46 | + |
| 47 | +## Anti-Patterns |
| 48 | + |
| 49 | +- **NEVER edit `db.lua`** - auto-generated from `tsErrorMessages.json` + `errors/*.md` |
| 50 | +- **DEPRECATED:** `auto_override_publish_diagnostics` -> use `auto_attach` |
| 51 | +- **DEPRECATED:** `"tsserver"` LSP name -> use `"ts_ls"` |
| 52 | + |
| 53 | +## Conventions |
| 54 | + |
| 55 | +| Rule | Detail | |
| 56 | +|------|--------| |
| 57 | +| Indent | 2 spaces | |
| 58 | +| Line width | 120 chars | |
| 59 | +| Quotes | Double preferred | |
| 60 | +| Type annotations | `---@class`, `---@param`, `---@return` | |
| 61 | +| Module pattern | `local M = {}` ... `return M` | |
| 62 | +| Error handling | `pcall` for graceful fallbacks | |
| 63 | +| Code lookup | O(1) via `[Tt][Ss](%d+)` pattern extraction | |
| 64 | + |
| 65 | +## Commands |
| 66 | + |
| 67 | +```bash |
| 68 | +make build # Regenerate db.lua from errors/*.md |
| 69 | +make test # Run all tests |
| 70 | +make test-file FILE=... # Run single test file |
| 71 | +``` |
| 72 | + |
| 73 | +## Testing |
| 74 | + |
| 75 | +- Framework: plenary.nvim (busted-style) |
| 76 | +- Run: `nvim --headless -u tests/minimal_init.vim -c "PlenaryBustedDirectory tests/spec/"` |
| 77 | +- Assertions: `assert.equals`, `assert.are.same`, `assert.is_not_nil` |
| 78 | +- Mocking: save/restore `vim.lsp.*` in before_each/after_each |
| 79 | + |
| 80 | +## CI |
| 81 | + |
| 82 | +- Matrix: `{ubuntu, macos}` x `{stable, nightly}` Neovim |
| 83 | +- Steps: npm install -> make build -> make test |
| 84 | +- Daily sync: checks upstream for new error templates |
| 85 | + |
| 86 | +## Notes |
| 87 | + |
| 88 | +- No `plugin/` dir - requires explicit `setup()` call |
| 89 | +- No `:help` docs - README only |
| 90 | +- Health check missing (`lua/ts-error-translator/health.lua`) |
| 91 | +- Typo in init.lua:23 "deprecrated" -> "deprecated" |
| 92 | +- `check-ts-errors.yml` references `error_templates/` but repo uses `errors/` |
0 commit comments