about summary refs log tree commit diff stats
path: root/js/baba-yaga/dev/vscode/README.md
blob: c144519278d7648b981bd189570ce750093238f3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# Baba Yaga VS Code Extension

Advanced language support for the Baba Yaga programming language with Tree-sitter parsing, type hints, function references, and intelligent code completion.

## Features

### **Core Language Support**
- **Syntax Highlighting**: Full support for all Baba Yaga syntax elements
- **File Association**: Automatic detection of `.baba` files
- **Bracket Matching**: Auto-closing brackets, parentheses, and braces
- **Comment Handling**: Toggle line and block comments
- **Indentation**: Smart indentation for Baba Yaga code structure

### **Intelligent Features**
- **Type Hints**: Multiple display modes - hover, inline, or above expressions (Elm-style)
- **Function References**: Go to definition (F12) and find all references (Shift+F12)
- **Auto-completion**: Context-aware suggestions for functions, keywords, and types
- **Error Checking**: Real-time syntax validation and error detection
- **Code Snippets**: Quick templates for common patterns
- **Markdown Support**: Syntax highlighting in Baba Yaga code blocks

### **Advanced Capabilities**
- **Tree-sitter Parsing**: Accurate syntax tree for better analysis
- **Function Signatures**: Detailed parameter and return type information
- **Built-in Function Support**: Complete coverage of `io.*`, `str.*`, `math.*` functions
- **Pattern Matching**: Special support for `when` expressions
- **Result Type Handling**: Intelligent handling of `Ok`/`Err` patterns

## Installation

### Method 1: Build from Source
```bash
cd dev/vscode
npm install
npm run compile
vsce package
# Install the generated .vsix file in VS Code
```

### Method 2: Development Mode
```bash
cd dev/vscode
npm install
npm run watch
# Press F5 in VS Code to launch extension in development mode
```

### Method 3: Manual Installation
1. Copy the extension files to your VS Code extensions directory
2. Restart VS Code
3. Open a `.baba` file to activate the extension

## Configuration

The extension provides several configuration options in VS Code settings:

```json
{
  "baba-yaga.enableTypeHints": true,
  "baba-yaga.enableFunctionReferences": true,
  "baba-yaga.enableAutoComplete": true,
  "baba-yaga.enableErrorChecking": true,
  "baba-yaga.enableMarkdownSupport": true,
  "baba-yaga.typeHintMode": "above"
}
```

### Configuration Options
- **`enableTypeHints`**: Show type hints and function signatures on hover
- **`enableFunctionReferences`**: Enable go-to-definition and find references
- **`enableAutoComplete`**: Enable intelligent code completion
- **`enableErrorChecking`**: Enable real-time error checking (disabled by default to prevent false semicolon warnings)
- **`enableMarkdownSupport`**: Enable syntax highlighting in Markdown code blocks
- **`typeHintMode`**: Type hint display mode - see below for details

### Type Hint Modes

The extension supports three different type hint display modes:

#### **`"none"` - Hover Only**
```baba
result : add(5, 3);  // No visual hints, hover to see types
```
- Type information only appears when hovering over symbols
- Clean, minimal interface
- Best for experienced developers who don't need constant type reminders

#### **`"inline"` - After Expressions**
```baba
result : add(5, 3); : Int
greeting : str.concat("Hello", name); : String
```
- Type hints appear directly after expressions
- Compact display
- Good for quick type reference without breaking code flow

#### **`"above"` - Elm Style (Default)**
```baba
        : Int
result : add(5, 3);
                    : String
greeting : str.concat("Hello", name);
```
- Type hints appear above expressions, right-aligned
- Clean separation between types and code
- Matches Elm language conventions
- Most readable for complex type signatures

## Usage

### Basic Syntax Highlighting
Open any `.baba` file and enjoy full syntax highlighting with:
- Keywords: `when`, `then`, `is`, `Ok`, `Err`, `true`, `false`, etc.
- Types: `Bool`, `Int`, `Float`, `String`, `List`, `Table`, `Result`, `Number`
- Operators: `->`, `=>`, `+`, `-`, `*`, `/`, `%`, `=`, `!=`, `>`, `<`, `>=`, `<=`, `..`
- Built-in functions: Complete `io.*`, `str.*`, `math.*` function sets

### Type Hints and Documentation
- **Hover over any symbol** to see detailed type information
- **Built-in functions** show signatures and descriptions
- **Custom functions** display their definitions and parameters
- **Keywords and types** provide helpful documentation

### Function References
- **F12**: Go to function definition
- **Shift+F12**: Find all references to a function
- **Ctrl+Shift+Space**: Show type information
- **Works with both built-in and custom functions**

### Auto-completion
- **Context-aware suggestions** for functions, keywords, and types
- **Function signatures** in completion details
- **Built-in function documentation** in tooltips
- **Trigger characters**: `.`, `:`, `>`

### Code Snippets
Use these snippets to speed up development:

| Snippet | Description | Example |
|---------|-------------|---------|
| `func` | Function definition | `myFunc : x -> x + 1;` |
| `tfunc` | Typed function | `add : (x: Int, y: Int) -> Int -> x + y;` |
| `when` | When expression | `when x is 1 then "One" _ then "Other";` |
| `result` | Result handling | `when result is Ok v then v Err e then 0;` |
| `list` | List creation | `[1, 2, 3]` |
| `table` | Table creation | `{name: "value"}` |
| `map` | Map function | `map (x -> x * 2) list` |
| `filter` | Filter function | `filter (x -> x > 0) list` |
| `reduce` | Reduce function | `reduce (acc x -> acc + x) 0 list` |

### Error Checking
- **Real-time validation** of syntax
- **Missing semicolon detection**
- **Basic type checking** for function calls
- **Pattern matching validation**

## Commands

The extension provides several commands accessible via the command palette:

- **`Baba Yaga: Show Type Information`**: Display type info for current symbol
- **`Baba Yaga: Go to Definition`**: Navigate to function definition
- **`Baba Yaga: Find References`**: Find all references to current symbol
- **`Baba Yaga: Show Function Signature`**: Display function signature

## Keybindings

Default keybindings for Baba Yaga files:

- **F12**: Go to definition
- **Shift+F12**: Find references
- **Ctrl+Shift+Space**: Show type information

## Built-in Function Support

The extension provides complete support for all Baba Yaga built-in functions:

### IO Functions
- `io.out(value)` - Print to console
- `io.in()` - Read from console

### String Functions
- `str.concat(str1, str2)` - String concatenation
- `str.split(str, delimiter)` - Split string
- `str.join(list, separator)` - Join list to string
- `str.length(str)` - String length
- `str.substring(str, start, end)` - Extract substring
- `str.replace(str, old, new)` - Replace substring
- `str.trim(str)` - Remove whitespace
- `str.upper(str)` - Convert to uppercase
- `str.lower(str)` - Convert to lowercase

### Math Functions
- `math.abs(x)` - Absolute value
- `math.sign(x)` - Sign function
- `math.floor(x)`, `math.ceil(x)`, `math.round(x)`, `math.trunc(x)` - Rounding functions
- `math.min(x, y)`, `math.max(x, y)`, `math.clamp(x, lo, hi)` - Min/max functions
- `math.pow(x, y)`, `math.sqrt(x)`, `math.exp(x)`, `math.log(x)` - Power and log functions
- `math.sin(x)`, `math.cos(x)`, `math.tan(x)` - Trigonometric functions
- `math.asin(x)`, `math.acos(x)`, `math.atan(x)`, `math.atan2(y, x)` - Inverse trig functions
- `math.deg(x)`, `math.rad(x)` - Angle conversion
- `math.random()` - Random number (0-1)
- `math.randomInt(lo, hi)` - Random integer

### List Functions
- `map(func, list)` - Apply function to each element
- `filter(pred, list)` - Filter by predicate
- `reduce(func, init, list)` - Fold to single value
- `append(list, item)` - Add item to end
- `set(table, key, value)` - Set table property
- `merge(table1, table2)` - Merge tables
- `shape(value)` - Get value metadata

## Development

### Building the Extension
```bash
cd dev/vscode
npm install
npm run compile
```

### Running Tests
```bash
npm test
```

### Debugging
1. Open the extension in VS Code
2. Press F5 to launch extension in development mode
3. Open a `.baba` file to test features

### File Structure
```
dev/vscode/
├── src/
│   └── extension.ts          # Main extension code
├── syntaxes/
│   └── baba-yaga.tmLanguage.json  # TextMate grammar
├── snippets/
│   └── baba-yaga.json        # Code snippets
├── language-configuration.json    # Language configuration
├── package.json              # Extension manifest
├── tsconfig.json             # TypeScript configuration
└── README.md                 # This file
```

## Troubleshooting

### Extension Not Loading
1. Check VS Code version (requires 1.74.0+)
2. Verify TypeScript compilation: `npm run compile`
3. Check extension logs: Help > Toggle Developer Tools

### Tree-sitter Not Working
1. Ensure `tree-sitter-baba-yaga` is installed
2. Check console for parser initialization errors
3. Extension falls back to basic features if Tree-sitter unavailable

### Type Hints Not Showing
1. Verify `baba-yaga.enableTypeHints` is enabled
2. Hover over symbols, not whitespace
3. Check that the symbol is recognized

### Auto-completion Issues
1. Ensure `baba-yaga.enableAutoComplete` is enabled
2. Type trigger characters (`.`, `:`, `>`)
3. Check for syntax errors in the file

### Linting Errors (False Positives)
If you see JavaScript/TypeScript linting errors in `.baba` files (like missing semicolon warnings):

1. **Install the extension properly** - Ensure the Baba Yaga extension is active
2. **Check file association** - Verify `.baba` files are recognized as "Baba Yaga" language
3. **Disable conflicting extensions** - Turn off ESLint, TypeScript, or other JavaScript linters
4. **Workspace settings** - Add this to your workspace `.vscode/settings.json`:

```json
{
  "files.associations": {
    "*.baba": "baba-yaga"
  },
  "eslint.validate": [
    "javascript",
    "javascriptreact", 
    "typescript",
    "typescriptreact"
  ],
  "[baba-yaga]": {
    "editor.formatOnSave": false,
    "editor.codeActionsOnSave": {}
  }
}
```

5. **Restart VS Code** - After making changes to settings

**Note**: Baba Yaga doesn't use semicolons in the same way as JavaScript. The extension should handle this automatically, but if you see false linting errors, the above steps should resolve them.

## Contributing

To contribute to the extension:

1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests if applicable
5. Submit a pull request

## License

This extension is provided under the same license as the main Baba Yaga project.