Skip to content

Commit 94ab4b3

Browse files
Copilot0xrinegade
andcommitted
Update to Zig 0.14.1 and modernize code patterns
Co-authored-by: 0xrinegade <[email protected]>
1 parent a2cc724 commit 94ab4b3

File tree

3 files changed

+37
-11
lines changed

3 files changed

+37
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ const result = await useMcpTool("zig", "get_recommendations", {
193193
var i: u32 = 0;
194194
while (true) {
195195
if (i >= 100) break;
196-
try list.append(@intCast(u8, i));
196+
try list.append(@intCast(i));
197197
i += 1;
198198
}
199199
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "zig-mcp-server",
3-
"version": "0.1.0",
4-
"description": "zig ai 10x dev assistant",
3+
"version": "0.2.0",
4+
"description": "zig ai 10x dev assistant - updated for Zig 0.14.1",
55
"private": true,
66
"type": "module",
77
"bin": {

src/index.ts

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ZigServer {
1818
this.server = new Server(
1919
{
2020
name: 'zig-mcp-server',
21-
version: '0.1.0',
21+
version: '0.2.0',
2222
},
2323
{
2424
capabilities: {
@@ -230,8 +230,8 @@ class ZigServer {
230230

231231
private async fetchZigDocs(section: 'language' | 'std'): Promise<string> {
232232
try {
233-
// Fetch from Zig's official documentation
234-
const response = await axios.get(`https://ziglang.org/documentation/master/${section === 'language' ? 'index' : 'std'}.html`);
233+
// Fetch from Zig's official documentation for version 0.14.1
234+
const response = await axios.get(`https://ziglang.org/documentation/0.14.1/${section === 'language' ? 'index' : 'std'}.html`);
235235
return response.data;
236236
} catch (error) {
237237
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
@@ -344,19 +344,25 @@ ${analysis.allocations}
344344
345345
private analyzeMemoryUsage(code: string): string {
346346
const patterns = {
347-
heapAlloc: /std\.(ArrayList|StringHashMap|AutoHashMap)/g,
347+
heapAlloc: /std\.(ArrayList|StringHashMap|AutoHashMap|HashMap)/g,
348348
stackAlloc: /var\s+\w+\s*:\s*\[(\d+)\]/g,
349-
slices: /\[\](?:u8|i32|f64)/g,
349+
slices: /\[\](?:u8|i32|f64|usize|isize)/g,
350+
multiArrayList: /std\.MultiArrayList/g,
351+
boundedArray: /std\.BoundedArray/g,
350352
};
351353
352354
const heapAllocs = (code.match(patterns.heapAlloc) || []).length;
353355
const stackAllocs = (code.match(patterns.stackAlloc) || []).length;
354356
const sliceUsage = (code.match(patterns.slices) || []).length;
357+
const multiArrayLists = (code.match(patterns.multiArrayList) || []).length;
358+
const boundedArrays = (code.match(patterns.boundedArray) || []).length;
355359
356360
return `
357361
- Heap Allocations: ${heapAllocs} detected
358362
- Stack Allocations: ${stackAllocs} detected
359363
- Slice Usage: ${sliceUsage} instances
364+
- MultiArrayList: ${multiArrayLists} instances
365+
- BoundedArray: ${boundedArrays} instances
360366
- Memory Profile: ${heapAllocs > stackAllocs ? 'Heap-heavy' : 'Stack-optimized'}
361367
`.trim();
362368
}
@@ -515,7 +521,12 @@ pub const MyStruct = struct {
515521
}
516522

517523
pub fn deinit(self: *MyStruct) void {
518-
// Cleanup
524+
// Cleanup allocated resources
525+
_ = self; // suppress unused variable warning
526+
}
527+
528+
pub fn getData(self: *const MyStruct) []const u8 {
529+
return self.data;
519530
}
520531
};
521532
`.trim();
@@ -530,6 +541,7 @@ pub const MyStruct = struct {
530541
${fnHeader} {
531542
${requirements.errorHandling ? 'if (input.len == 0) return Error.InvalidInput;' : ''}
532543
// Function implementation
544+
_ = input; // suppress unused parameter warning if not used
533545
}
534546
`.trim();
535547
}
@@ -616,6 +628,14 @@ ${analysis.performance}
616628
if (code.includes('std.fmt.allocPrint')) {
617629
patterns.push('- Consider using formatters or bufPrint when possible');
618630
}
631+
632+
// Check for outdated Zig syntax (pre-0.11)
633+
if (code.match(/@intCast\(\s*\w+\s*,/)) {
634+
patterns.push('- Update @intCast syntax: use @intCast(value) instead of @intCast(Type, value)');
635+
}
636+
if (code.match(/@floatCast\(\s*\w+\s*,/)) {
637+
patterns.push('- Update @floatCast syntax: use @floatCast(value) instead of @floatCast(Type, value)');
638+
}
619639

620640
return patterns.length > 0 ? patterns.join('\n') : '- No significant pattern issues detected';
621641
}
@@ -662,16 +682,22 @@ ${analysis.performance}
662682
recommendations.push('- Use comptime when possible');
663683
recommendations.push('- Consider using packed structs for memory optimization');
664684
recommendations.push('- Implement custom allocators for specific use cases');
685+
recommendations.push('- Use @inline for small hot functions');
686+
recommendations.push('- Consider using @Vector for SIMD operations');
665687
}
666688
if (prompt.toLowerCase().includes('safety')) {
667689
recommendations.push('- Add bounds checking for array access');
668-
recommendations.push('- Use explicit error handling');
669-
recommendations.push('- Implement proper resource cleanup');
690+
recommendations.push('- Use explicit error handling with try/catch');
691+
recommendations.push('- Implement proper resource cleanup with defer');
692+
recommendations.push('- Use const where possible to prevent mutations');
693+
recommendations.push('- Avoid undefined behavior with proper initialization');
670694
}
671695
if (prompt.toLowerCase().includes('maintainability')) {
672696
recommendations.push('- Add comprehensive documentation');
673697
recommendations.push('- Break down complex functions');
674698
recommendations.push('- Use meaningful variable names');
699+
recommendations.push('- Organize code into modules and namespaces');
700+
recommendations.push('- Write unit tests for public functions');
675701
}
676702

677703
return recommendations.join('\n');

0 commit comments

Comments
 (0)