Skip to content

Commit

Permalink
hinon
Browse files Browse the repository at this point in the history
  • Loading branch information
TheWhiteWord committed Dec 23, 2024
1 parent ebbbfcb commit cdd308b
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 25 deletions.
7 changes: 7 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": []
}
8 changes: 6 additions & 2 deletions js/test_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,23 @@ console.log('Starting tests...');

// Test system initialization
try {
debugger; // Add breakpoint here
debugger; // Breakpoint 1: Before initialization
const initResult = system_init(testMd);
debugger; // Breakpoint 2: After initialization
console.log('Initialization test:', initResult);
} catch (error) {
debugger; // Add breakpoint for errors
debugger; // Breakpoint 3: If error occurs
console.error('Initialization failed:', error);
}

// Test function execution
try {
debugger; // Breakpoint 4: Before function execution
const execResult = execute('test_function', { input: 'hello world' });
debugger; // Breakpoint 5: After function execution
console.log('Execution test:', execResult);
} catch (error) {
debugger; // Breakpoint 6: If error occurs
console.error('Execution failed:', error);
}

Expand Down
114 changes: 91 additions & 23 deletions vscode-extension/extension.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,121 @@
const vscode = require('vscode');
const { system_init, execute, navigateWarmhole } = require('../js/core_logic');

// Track active system state
let systemState = null;
let statusBarItem;
let activeWarmhole = null;

function activate(context) {
console.log('READMEs extension is active');

// Create status bar item
statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
statusBarItem.text = "READMEs: Ready";
statusBarItem.show();

// Register text decoration type for warmholes
const warmholeDecoration = vscode.window.createTextEditorDecorationType({
backgroundColor: 'rgba(100, 100, 255, 0.2)',
border: '1px solid rgba(100, 100, 255, 0.5)'
});

// Initialize system when opening a markdown file
vscode.workspace.onDidOpenTextDocument(doc => {
if (doc.languageId === 'markdown') {
systemState = system_init(doc.getText());
try {
systemState = system_init(doc.getText());
statusBarItem.text = `READMEs: ${Object.keys(systemState.functions).length} functions`;
highlightWarmholes(vscode.window.activeTextEditor, warmholeDecoration);
} catch (error) {
vscode.window.showErrorMessage(`Initialization failed: ${error.message}`);
}
}
});

// Update on editor changes
vscode.workspace.onDidChangeTextDocument(event => {
if (event.document.languageId === 'markdown') {
highlightWarmholes(vscode.window.activeTextEditor, warmholeDecoration);
}
});

// Register execute command
// Register execute command with quick pick
let executeCommand = vscode.commands.registerCommand('readmes.execute', async () => {
const functionName = await vscode.window.showInputBox({
prompt: 'Enter function name'
});
const input = await vscode.window.showInputBox({
prompt: 'Enter input'
if (!systemState?.functions) {
vscode.window.showErrorMessage('System not initialized');
return;
}

const functionNames = Object.keys(systemState.functions);
const selected = await vscode.window.showQuickPick(functionNames, {
placeHolder: 'Select function to execute'
});

try {
const result = execute(functionName, { input });
vscode.window.showInformationMessage(`Result: ${result.result}`);
} catch (error) {
vscode.window.showErrorMessage(error.message);

if (selected) {
const input = await vscode.window.showInputBox({
prompt: `Enter input for ${selected}`
});

try {
const result = execute(selected, { input });
vscode.window.showInformationMessage(`Result: ${result.result}`);
} catch (error) {
vscode.window.showErrorMessage(error.message);
}
}
});

// Register navigate command
// Register navigate command with quick pick
let navigateCommand = vscode.commands.registerCommand('readmes.navigate', async () => {
const warmholeId = await vscode.window.showInputBox({
prompt: 'Enter warmhole ID'
if (!systemState?.warmholes) {
vscode.window.showErrorMessage('System not initialized');
return;
}

const warmholeIds = Object.keys(systemState.warmholes);
const selected = await vscode.window.showQuickPick(warmholeIds, {
placeHolder: 'Select warmhole to navigate'
});

try {
const result = navigateWarmhole(warmholeId);
vscode.window.showInformationMessage(`Navigated to: ${result.to}`);
} catch (error) {
vscode.window.showErrorMessage(error.message);
if (selected) {
try {
const result = navigateWarmhole(selected);
activeWarmhole = result.to;
statusBarItem.text = `READMEs: At ${activeWarmhole}`;
vscode.window.showInformationMessage(`Navigated to: ${result.to}`);
} catch (error) {
vscode.window.showErrorMessage(error.message);
}
}
});

context.subscriptions.push(executeCommand, navigateCommand);
context.subscriptions.push(executeCommand, navigateCommand, statusBarItem);
}

function highlightWarmholes(editor, decoration) {
if (!editor) return;

const text = editor.document.getText();
const warmholeRegex = /# Warmhole:\s+(\w+)[^\n]*/g;
const decorations = [];

let match;
while ((match = warmholeRegex.exec(text)) !== null) {
const startPos = editor.document.positionAt(match.index);
const endPos = editor.document.positionAt(match.index + match[0].length);
const decoration = { range: new vscode.Range(startPos, endPos) };
decorations.push(decoration);
}

editor.setDecorations(decoration, decorations);
}

function deactivate() {}
function deactivate() {
if (statusBarItem) {
statusBarItem.dispose();
}
}

module.exports = {
activate,
Expand Down

0 comments on commit cdd308b

Please sign in to comment.