Skip to content

Commit d792813

Browse files
authored
2.0 (#36)
* rewrite * wip * tests + ci/cd * remove .github from .gitignore
1 parent c367530 commit d792813

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+11821
-303
lines changed

.github/workflows/ci.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main, master]
6+
pull_request:
7+
branches: [main, master]
8+
workflow_dispatch:
9+
10+
jobs:
11+
test:
12+
runs-on: ${{ matrix.os }}
13+
strategy:
14+
matrix:
15+
os: [ubuntu-latest, macos-latest]
16+
nvim-version: [stable, nightly]
17+
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
22+
- name: Setup Node.js
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: '20'
26+
27+
- name: Install dependencies
28+
run: npm install
29+
30+
- name: Build database
31+
run: make build
32+
33+
- name: Install Neovim
34+
uses: rhysd/action-setup-vim@v1
35+
with:
36+
neovim: true
37+
version: ${{ matrix.nvim-version }}
38+
39+
- name: Install plenary.nvim
40+
run: |
41+
mkdir -p ~/.local/share/nvim/site/pack/vendor/start
42+
git clone --depth=1 https://github.com/nvim-lua/plenary.nvim ~/.local/share/nvim/site/pack/vendor/start/plenary.nvim
43+
44+
- name: Run tests
45+
run: make test
46+
47+
- name: Upload test results
48+
if: failure()
49+
uses: actions/upload-artifact@v4
50+
with:
51+
name: test-results-${{ matrix.os }}-${{ matrix.nvim-version }}
52+
path: |
53+
*.log
54+
test-*.xml
55+
retention-days: 7

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
.luarc.json
2-
.git/
3-
.github/
2+
node_modules

Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.PHONY: test test-file build
2+
3+
test:
4+
XDG_CONFIG_HOME=/tmp nvim --headless -u tests/minimal_init.vim -c "PlenaryBustedDirectory tests/spec/" -c "quit"
5+
6+
test-file:
7+
@if [ -z "$(FILE)" ]; then \
8+
echo "Usage: make test-file FILE=tests/spec/parser_spec.lua"; \
9+
exit 1; \
10+
fi
11+
XDG_CONFIG_HOME=/tmp nvim --headless -u tests/minimal_init.vim -c "PlenaryBustedFile $(FILE)" -c "quit"
12+
13+
build:
14+
node build-lua-db.js

README.md

Lines changed: 95 additions & 17 deletions

build-lua-db.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const fm = require('front-matter');
4+
5+
const dbJson = require('./tsErrorMessages.json');
6+
const errorsDir = './errors';
7+
8+
const results = [];
9+
10+
// Read markdown files
11+
const mdFiles = fs.readdirSync(errorsDir).filter(f => f.endsWith('.md'));
12+
13+
for (const file of mdFiles) {
14+
const code = parseInt(file.replace('.md', ''));
15+
const content = fs.readFileSync(path.join(errorsDir, file), 'utf8');
16+
const parsed = fm(content);
17+
18+
// Find pattern in JSON by code
19+
const entry = Object.entries(dbJson).find(([_, v]) => v.code === code);
20+
if (!entry) {
21+
console.warn(`No pattern found for code ${code}`);
22+
continue;
23+
}
24+
25+
const [pattern, { category }] = entry;
26+
27+
results.push({
28+
pattern,
29+
code,
30+
category,
31+
improved_message: parsed.body.trim()
32+
});
33+
}
34+
35+
// Sort by code
36+
results.sort((a, b) => a.code - b.code);
37+
38+
console.log(`Generating db.lua with ${results.length} errors...`);
39+
40+
// Generate Lua - need to escape strings properly
41+
function luaStringEscape(str) {
42+
return str
43+
.replace(/\\/g, '\\\\')
44+
.replace(/\n/g, '\\n')
45+
.replace(/\r/g, '\\r')
46+
.replace(/"/g, '\\"');
47+
}
48+
49+
let lua = 'return {\n';
50+
for (const err of results) {
51+
lua += ` [${err.code}] = {\n`;
52+
lua += ` pattern = "${luaStringEscape(err.pattern)}",\n`;
53+
lua += ` category = "${err.category}",\n`;
54+
lua += ` improved_message = "${luaStringEscape(err.improved_message)}"\n`;
55+
lua += ' },\n';
56+
}
57+
lua += '}\n';
58+
59+
const outputPath = './lua/ts-error-translator/db.lua';
60+
fs.writeFileSync(outputPath, lua);
61+
console.log(`Generated ${outputPath}`);

lua/ts-error-translator/error_templates/1002.md renamed to errors/1002.md

lua/ts-error-translator/error_templates/1003.md renamed to errors/1003.md

lua/ts-error-translator/error_templates/1006.md renamed to errors/1006.md

lua/ts-error-translator/error_templates/1009.md renamed to errors/1009.md

lua/ts-error-translator/error_templates/1014.md renamed to errors/1014.md

0 commit comments

Comments
 (0)