"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.deactivate = exports.activate = void 0; const vscode = __importStar(require("vscode")); // Tree-sitter parser for Baba Yaga (optional) let parser; let BabaYagaLanguage; async function activate(context) { console.log('Baba Yaga extension is now active!'); // Initialize Tree-sitter parser (optional) const enableTreeSitter = vscode.workspace.getConfiguration('baba-yaga').get('enableTreeSitter'); if (enableTreeSitter) { try { const Parser = require('tree-sitter'); Parser.init(); // Note: tree-sitter-baba-yaga grammar would need to be built separately // For now, we'll use basic features without Tree-sitter console.log('Tree-sitter enabled but grammar not available'); } catch (error) { console.warn('Tree-sitter not available, using basic features:', error); } } // Register commands context.subscriptions.push(vscode.commands.registerCommand('baba-yaga.showTypeInfo', showTypeInfo), vscode.commands.registerCommand('baba-yaga.goToDefinition', goToDefinition), vscode.commands.registerCommand('baba-yaga.findReferences', findReferences), vscode.commands.registerCommand('baba-yaga.showFunctionSignature', showFunctionSignature)); // Register language features if (vscode.workspace.getConfiguration('baba-yaga').get('enableTypeHints')) { context.subscriptions.push(vscode.languages.registerHoverProvider('baba-yaga', new BabaYagaHoverProvider()), vscode.languages.registerCompletionItemProvider('baba-yaga', new BabaYagaCompletionProvider(), '.', ':', '>')); } if (vscode.workspace.getConfiguration('baba-yaga').get('enableFunctionReferences')) { context.subscriptions.push(vscode.languages.registerDefinitionProvider('baba-yaga', new BabaYagaDefinitionProvider()), vscode.languages.registerReferenceProvider('baba-yaga', new BabaYagaReferenceProvider())); } if (vscode.workspace.getConfiguration('baba-yaga').get('enableErrorChecking')) { context.subscriptions.push(vscode.languages.registerDiagnosticCollection('baba-yaga', new BabaYagaDiagnosticProvider())); } } exports.activate = activate; function deactivate() { } exports.deactivate = deactivate; // Built-in functions and their signatures const builtinFunctions = new Map([ ['io.out', { name: 'io.out', kind: 'function', signature: 'io.out(value: any) -> void', description: 'Print value to console' }], ['io.in', { name: 'io.in', kind: 'function', signature: 'io.in() -> String', description: 'Read input from console' }], ['map', { name: 'map', kind: 'function', signature: 'map(func: (T) -> U, list: [T]) -> [U]', description: 'Apply function to each element' }], ['filter', { name: 'filter', kind: 'function', signature: 'filter(pred: (T) -> Bool, list: [T]) -> [T]', description: 'Filter list by predicate' }], ['reduce', { name: 'reduce', kind: 'function', signature: 'reduce(func: (acc: T, item: T) -> T, init: T, list: [T]) -> T', description: 'Fold list to single value' }], ['append', { name: 'append', kind: 'function', signature: 'append(list: [T], item: T) -> [T]', description: 'Add item to end of list' }], ['set', { name: 'set', kind: 'function', signature: 'set(table: Table, key: String, value: any) -> Table', description: 'Set table property' }], ['merge', { name: 'merge', kind: 'function', signature: 'merge(table1: Table, table2: Table) -> Table', description: 'Merge two tables' }], ['shape', { name: 'shape', kind: 'function', signature: 'shape(value: any) -> Table', description: 'Get value metadata' }] ]); // String functions const stringFunctions = ['concat', 'split', 'join', 'length', 'substring', 'replace', 'trim', 'upper', 'lower']; stringFunctions.forEach(func => { builtinFunctions.set(`str.${func}`, { name: `str.${func}`, kind: 'function', signature: `str.${func}(...args) -> String`, description: `String ${func} operation` }); }); // Math functions const mathFunctions = ['abs', 'sign', 'floor', 'ceil', 'round', 'trunc', 'min', 'max', 'clamp', 'pow', 'sqrt', 'exp', 'log', 'sin', 'cos', 'tan', 'asin', 'acos', 'atan', 'atan2', 'deg', 'rad', 'random', 'randomInt']; mathFunctions.forEach(func => { builtinFunctions.set(`math.${func}`, { name: `math.${func}`, kind: 'function', signature: `math.${func}(...args) -> Number`, description: `Math ${func} operation` }); }); // Keywords const keywords = new Map([ ['when', { name: 'when', kind: 'keyword', description: 'Pattern matching expression' }], ['then', { name: 'then', kind: 'keyword', description: 'Pattern match result' }], ['is', { name: 'is', kind: 'keyword', description: 'Pattern match operator' }], ['Ok', { name: 'Ok', kind: 'keyword', description: 'Success result constructor' }], ['Err', { name: 'Err', kind: 'keyword', description: 'Error result constructor' }], ['true', { name: 'true', kind: 'keyword', description: 'Boolean true value' }], ['false', { name: 'false', kind: 'keyword', description: 'Boolean false value' }], ['PI', { name: 'PI', kind: 'keyword', description: 'Mathematical constant π' }], ['INFINITY', { name: 'INFINITY', kind: 'keyword', description: 'Positive infinity' }], ['and', { name: 'and', kind: 'keyword', description: 'Logical AND operator' }], ['or', { name: 'or', kind: 'keyword', description: 'Logical OR operator' }], ['xor', { name: 'xor', kind: 'keyword', description: 'Logical XOR operator' }] ]); // Types const types = new Map([ ['Bool', { name: 'Bool', kind: 'type', description: 'Boolean type (true/false)' }], ['Int', { name: 'Int', kind: 'type', description: 'Integer type' }], ['Float', { name: 'Float', kind: 'type', description: 'Floating-point type' }], ['String', { name: 'String', kind: 'type', description: 'String type' }], ['List', { name: 'List', kind: 'type', description: 'List type [T]' }], ['Table', { name: 'Table', kind: 'type', description: 'Table type {key: value}' }], ['Result', { name: 'Result', kind: 'type', description: 'Result type (Ok T | Err String)' }], ['Number', { name: 'Number', kind: 'type', description: 'Numeric supertype (Int | Float)' }] ]); // Hover Provider class BabaYagaHoverProvider { provideHover(document, position, token) { const wordRange = document.getWordRangeAtPosition(position); if (!wordRange) return null; const word = document.getText(wordRange); // Check built-in functions const builtin = builtinFunctions.get(word); if (builtin) { return new vscode.Hover([ `**${builtin.name}**`, `\`${builtin.signature}\``, builtin.description || '' ]); } // Check keywords const keyword = keywords.get(word); if (keyword) { return new vscode.Hover([ `**${keyword.name}** (keyword)`, keyword.description || '' ]); } // Check types const type = types.get(word); if (type) { return new vscode.Hover([ `**${type.name}** (type)`, type.description || '' ]); } // Check for function definitions in the document const functionDef = findFunctionDefinition(document, word); if (functionDef) { return new vscode.Hover([ `**${word}** (function)`, `\`${functionDef.signature}\``, functionDef.description || '' ]); } return null; } } // Completion Provider class BabaYagaCompletionProvider { provideCompletionItems(document, position, token, context) { const items = []; // Add built-in functions builtinFunctions.forEach((func, name) => { const item = new vscode.CompletionItem(name, vscode.CompletionItemKind.Function); item.detail = func.signature; item.documentation = func.description; items.push(item); }); // Add keywords keywords.forEach((keyword, name) => { const item = new vscode.CompletionItem(name, vscode.CompletionItemKind.Keyword); item.documentation = keyword.description; items.push(item); }); // Add types types.forEach((type, name) => { const item = new vscode.CompletionItem(name, vscode.CompletionItemKind.TypeParameter); item.documentation = type.description; items.push(item); }); // Add operators const operators = ['+', '-', '*', '/', '%', '=', '!=', '>', '<', '>=', '<=', '->', '..', ':', 'and', 'or', 'xor']; operators.forEach(op => { const item = new vscode.CompletionItem(op, vscode.CompletionItemKind.Operator); items.push(item); }); return items; } } // Definition Provider class BabaYagaDefinitionProvider { provideDefinition(document, position, token) { const wordRange = document.getWordRangeAtPosition(position); if (!wordRange) return null; const word = document.getText(wordRange); // Find function definition in the document const functionDef = findFunctionDefinition(document, word); if (functionDef) { return new vscode.Location(document.uri, functionDef.range); } return null; } } // Reference Provider class BabaYagaReferenceProvider { provideReferences(document, position, context, token) { const wordRange = document.getWordRangeAtPosition(position); if (!wordRange) return null; const word = document.getText(wordRange); const references = []; // Find all references in the document const text = document.getText(); const regex = new RegExp(`\\b${word}\\b`, 'g'); let match; while ((match = regex.exec(text)) !== null) { const startPos = document.positionAt(match.index); const endPos = document.positionAt(match.index + match[0].length); references.push(new vscode.Location(document.uri, new vscode.Range(startPos, endPos))); } return references; } } // Diagnostic Provider class BabaYagaDiagnosticProvider { constructor() { this.diagnosticCollection = vscode.languages.createDiagnosticCollection('baba-yaga'); vscode.workspace.onDidChangeTextDocument(this.onDidChangeTextDocument, this); } onDidChangeTextDocument(event) { if (event.document.languageId === 'baba-yaga') { this.updateDiagnostics(event.document); } } updateDiagnostics(document) { const diagnostics = []; const text = document.getText(); // Basic syntax checking const lines = text.split('\n'); lines.forEach((line, index) => { // Check for missing semicolons if (line.trim() && !line.trim().startsWith('//') && !line.trim().endsWith(';') && !line.trim().endsWith('{') && !line.trim().endsWith('}')) { const range = new vscode.Range(index, line.length, index, line.length); diagnostics.push(new vscode.Diagnostic(range, 'Missing semicolon', vscode.DiagnosticSeverity.Warning)); } }); this.diagnosticCollection.set(document.uri, diagnostics); } } // Helper functions function findFunctionDefinition(document, functionName) { const text = document.getText(); const lines = text.split('\n'); for (let i = 0; i < lines.length; i++) { const line = lines[i]; const match = line.match(new RegExp(`\\b${functionName}\\s*:\\s*(.+?)\\s*->\\s*(.+?)\\s*;`)); if (match) { const signature = `${functionName} : ${match[1]} -> ${match[2]}`; const startPos = document.positionAt(text.indexOf(line)); const endPos = document.positionAt(text.indexOf(line) + line.length); return { signature, range: new vscode.Range(startPos, endPos), description: `Function defined at line ${i + 1}` }; } } return null; } // Command implementations async function showTypeInfo() { const editor = vscode.window.activeTextEditor; if (!editor || editor.document.languageId !== 'baba-yaga') return; const position = editor.selection.active; const wordRange = editor.document.getWordRangeAtPosition(position); if (!wordRange) return; const word = editor.document.getText(wordRange); const type = builtinFunctions.get(word) || keywords.get(word) || types.get(word); if (type) { vscode.window.showInformationMessage(`${word}: ${type.description || type.signature || type.name}`); } } async function goToDefinition() { const editor = vscode.window.activeTextEditor; if (!editor || editor.document.languageId !== 'baba-yaga') return; const position = editor.selection.active; const wordRange = editor.document.getWordRangeAtPosition(position); if (!wordRange) return; const word = editor.document.getText(wordRange); const functionDef = findFunctionDefinition(editor.document, word); if (functionDef) { editor.selection = new vscode.Selection(functionDef.range.start, functionDef.range.end); editor.revealRange(functionDef.range); } } async function findReferences() { const editor = vscode.window.activeTextEditor; if (!editor || editor.document.languageId !== 'baba-yaga') return; const position = editor.selection.active; const wordRange = editor.document.getWordRangeAtPosition(position); if (!wordRange) return; const word = editor.document.getText(wordRange); await vscode.commands.executeCommand('editor.action.referenceSearch.trigger'); } async function showFunctionSignature() { const editor = vscode.window.activeTextEditor; if (!editor || editor.document.languageId !== 'baba-yaga') return; const position = editor.selection.active; const wordRange = editor.document.getWordRangeAtPosition(position); if (!wordRange) return; const word = editor.document.getText(wordRange); const builtin = builtinFunctions.get(word); if (builtin) { vscode.window.showInformationMessage(`${word}: ${builtin.signature}`); } } //# sourceMappingURL=extension.js.map