Skip to content

Commit 2dca715

Browse files
Copilotdmmulroy
andauthored
Set up Copilot instructions (#42)
* Initial plan * Add .github/copilot-instructions.md with repository-specific guidance Co-authored-by: dmmulroy <2755722+dmmulroy@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: dmmulroy <2755722+dmmulroy@users.noreply.github.com>
1 parent 17ec46d commit 2dca715

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

.github/copilot-instructions.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Copilot Instructions for ts-error-translator.nvim
2+
3+
This is a Neovim plugin written in Lua that translates TypeScript error messages into human-readable explanations. It's a port of [Matt Pocock's ts-error-translator for VSCode](https://github.com/mattpocock/ts-error-translator).
4+
5+
## Project Structure
6+
7+
```
8+
lua/ts-error-translator/
9+
init.lua -- Public API and plugin setup
10+
parser.lua -- Core parsing logic (extracts TS codes, O(1) lookup)
11+
matcher.lua -- Pattern matching with vim.regex
12+
utils.lua -- Helper functions
13+
lru.lua -- LRU cache implementation
14+
diagnostic.lua -- vim.diagnostic integration
15+
db.lua -- Error database indexed by code (auto-generated)
16+
```
17+
18+
## Code Style
19+
20+
- Follow the [StyLua](https://github.com/JohnnyMorganz/StyLua) formatter configuration in `.stylua.toml`
21+
- Use 2 spaces for indentation
22+
- Maximum line width of 120 characters
23+
- Use double quotes for strings
24+
- Add type annotations using `@class`, `@field`, `@param`, `@return` comments for public APIs
25+
- Include `---@diagnostic disable:` comments when necessary to suppress known false positives
26+
27+
## Building
28+
29+
The error database (`lua/ts-error-translator/db.lua`) is auto-generated from:
30+
- `tsErrorMessages.json` (TypeScript error patterns)
31+
- `errors/*.md` (improved human-readable messages)
32+
33+
To rebuild the database:
34+
```bash
35+
make build
36+
# or: node build-lua-db.js
37+
```
38+
39+
**Important**: Never manually edit `lua/ts-error-translator/db.lua` - it's generated code.
40+
41+
## Testing
42+
43+
Tests use [plenary.nvim](https://github.com/nvim-lua/plenary.nvim) test framework.
44+
45+
Run all tests:
46+
```bash
47+
make test
48+
```
49+
50+
Run a specific test file:
51+
```bash
52+
make test-file FILE=tests/spec/parser_spec.lua
53+
```
54+
55+
Tests are located in `tests/spec/` and follow the pattern `*_spec.lua`.
56+
57+
## Key Conventions
58+
59+
- The plugin uses O(1) lookup via error codes extracted from messages
60+
- Error codes are extracted using the pattern `[Tt][Ss](%d+)`
61+
- The LRU cache improves performance for repeated lookups
62+
- Public API functions should be exposed through `init.lua`
63+
- Use `pcall` for error handling to provide graceful fallbacks
64+
65+
## Adding New Error Translations
66+
67+
1. Create a new markdown file in `errors/` named `{error_code}.md`
68+
2. Include frontmatter and the improved message body
69+
3. Run `make build` to regenerate `db.lua`
70+
71+
## Dependencies
72+
73+
- **Runtime**: No external dependencies (uses native vim.regex)
74+
- **Build**: Node.js with `front-matter` package
75+
- **Testing**: plenary.nvim

0 commit comments

Comments
 (0)