Skip to content

Commit 09e18e1

Browse files
committed
feat: basic syntax checking
Signed-off-by: Gordon Smith <GordonJSmith@gmail.com>
1 parent e32c8a6 commit 09e18e1

27 files changed

Lines changed: 5057 additions & 1237 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,5 @@ dist/
7777
*.vsix
7878
*.tmLanguage.json
7979
!/syntaxes/*.tmLanguage.json
80+
types/
81+
out/

.vscode/settings.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
{
22
"editor.formatOnSave": true,
3-
"editor.defaultFormatter": "esbenp.prettier-vscode",
3+
"editor.defaultFormatter": "vscode.typescript-language-features",
44
"editor.codeActionsOnSave": {
55
"source.fixAll.eslint": "explicit"
66
},
77
"[typescript]": {
8-
"editor.defaultFormatter": "esbenp.prettier-vscode",
8+
"editor.defaultFormatter": "vscode.typescript-language-features",
99
"editor.formatOnSave": true
1010
},
1111
"[javascript]": {
12-
"editor.defaultFormatter": "esbenp.prettier-vscode",
12+
"editor.defaultFormatter": "vscode.typescript-language-features",
1313
"editor.formatOnSave": true
1414
},
1515
"[json]": {
16-
"editor.defaultFormatter": "esbenp.prettier-vscode",
16+
"editor.defaultFormatter": "vscode.json-language-features",
1717
"editor.formatOnSave": true
1818
},
1919
"[jsonc]": {
20-
"editor.defaultFormatter": "esbenp.prettier-vscode",
20+
"editor.defaultFormatter": "vscode.json-language-features",
2121
"editor.formatOnSave": true
2222
}
2323
}

.vscode/tasks.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,26 @@
22
"version": "2.0.0",
33
"tasks": [
44
{
5-
"label": "watch",
65
"type": "npm",
7-
"script": "watch",
6+
"label": "gen-watch",
7+
"script": "gen-watch",
8+
"problemMatcher": ["$tsc-watch"],
9+
"presentation": {
10+
"group": "build"
11+
}
12+
},
13+
{
14+
"type": "npm",
15+
"label": "build-watch",
16+
"script": "build-watch",
817
"problemMatcher": [],
918
"presentation": {
1019
"group": "build"
1120
}
1221
},
1322
{
1423
"label": "build",
15-
"dependsOn": ["watch"],
24+
"dependsOn": ["build-watch", "gen-watch"],
1625
"group": {
1726
"kind": "build",
1827
"isDefault": true

.vscodeignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
.vscode-test/**
33
.github/
44
.gitignore
5+
node_modules/
56
tests/
67
commitlint.config.js
78
src/**

README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,57 @@ This extension provides:
1414
- [Snippets](https://code.visualstudio.com/docs/editor/userdefinedsnippets) for worlds and interfaces.
1515
- Basic markdown highlighting in comments.
1616
- Simple list-based autocomplete.
17+
- **WIT Syntax Checking**: Validate WIT files for common syntax errors and provide diagnostics.
18+
19+
### Syntax Validation and Error Display
20+
21+
The extension provides comprehensive WIT syntax validation with error display in VS Code's PROBLEMS pane:
22+
23+
#### Automatic Validation
24+
- **On File Save**: Automatically validates WIT files when saved
25+
- **On File Open**: Validates WIT files when opened in the editor
26+
- **Real-time Feedback**: Errors appear immediately in the PROBLEMS pane
27+
28+
#### Manual Commands
29+
- **WIT: Check Syntax** (`Ctrl+Shift+P` → "WIT: Check Syntax")
30+
- Validates the currently active WIT file
31+
- Shows detailed error information in notifications
32+
- Displays errors in the PROBLEMS pane
33+
34+
- **WIT: Check Syntax in Workspace** (`Ctrl+Shift+P` → "WIT: Check Syntax in Workspace")
35+
- Validates all WIT files in the workspace
36+
- Shows progress notification during validation
37+
- Provides summary of results
38+
- Creates detailed report in output channel
39+
40+
#### Error Information
41+
When validation fails, the extension displays:
42+
- **Error location**: Precise line and column numbers
43+
- **Error message**: Detailed description of the syntax error
44+
- **Context**: Additional information about the error
45+
- **Related information**: Links to relevant documentation or context
46+
47+
#### PROBLEMS Pane Integration
48+
- Errors appear automatically in VS Code's PROBLEMS pane
49+
- Click on any error to jump directly to the problematic line
50+
- Errors are cleared automatically when files are fixed or closed
51+
- Supports multiple files with errors simultaneously
52+
53+
### Code Completion
54+
55+
The extension offers intelligent code completion for WIT files:
56+
57+
- **Context-aware suggestions**: Provides completion items based on the current context
58+
- **Keyword snippets**: Includes common WIT keywords and constructs
59+
- **Custom snippets**: User-defined snippets for faster coding
60+
61+
### Command Palette Integration
62+
63+
Easily access extension features through the Command Palette:
64+
65+
- **WIT: Check Syntax**: Validate the current file's syntax
66+
- **WIT: Check Syntax in Workspace**: Validate all WIT files in the workspace
67+
- **WIT: Show Output Channel**: Display the extension's output channel
1768

1869
## Installation
1970

TESTING.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Testing with Vitest
2+
3+
This project now uses [Vitest](https://vitest.dev/) for unit testing, providing a fast and modern testing experience with excellent TypeScript support.
4+
5+
## Available Test Scripts
6+
7+
- `npm run test:unit` - Run all unit tests once
8+
- `npm run test:unit:watch` - Run tests in watch mode (reruns when files change)
9+
- `npm run test:unit:ui` - Open the Vitest UI for interactive testing
10+
- `npm test` - Run the full test suite (lint, format check, build, package, grammar tests, and unit tests)
11+
12+
## Test Structure
13+
14+
### Unit Tests
15+
- Located in `tests/` directory
16+
- Use `.test.ts` or `.spec.ts` suffix
17+
- Written using Vitest's `describe`, `it`, and `expect` APIs
18+
19+
### Current Tests
20+
- `tests/errorParser.test.ts` - Tests for WIT error parsing functionality
21+
22+
## Writing Tests
23+
24+
```typescript
25+
import { describe, it, expect } from 'vitest';
26+
import { yourFunction } from '../src/yourModule';
27+
28+
describe('Your Module', () => {
29+
it('should do something', () => {
30+
const result = yourFunction('input');
31+
expect(result).toBe('expected output');
32+
});
33+
});
34+
```
35+
36+
## Error Parser Tests
37+
38+
The `errorParser.test.ts` file contains comprehensive tests for the WIT error parsing regex, including:
39+
40+
- Extraction from real WIT error stacks
41+
- Handling invalid/malformed stacks
42+
- Edge cases with large line/column numbers
43+
- Different file path formats
44+
- Stacks with and without "Caused by" sections
45+
46+
## Configuration
47+
48+
The Vitest configuration is in `vitest.config.ts` and includes:
49+
- TypeScript support out of the box
50+
- Node.js environment
51+
- Path aliases for cleaner imports
52+
- Automatic file discovery for tests
53+
54+
## VS Code Integration
55+
56+
Vitest works great with VS Code. You can:
57+
1. Install the [Vitest extension](https://marketplace.visualstudio.com/items?itemName=ZixuanChen.vitest-explorer)
58+
2. Run tests directly from the editor
59+
3. See test results inline
60+
4. Debug tests with breakpoints

commitlint.config.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)