intelliwacc ide #43

Merged
gc1523 merged 9 commits from intelliwacc-ide into master 2025-03-14 13:22:53 +00:00
43 changed files with 804 additions and 1152 deletions
Showing only changes of commit bad6e47e46 - Show all commits

View File

@@ -4,7 +4,6 @@ import parsley.Parsley
import parsley.generic.ErrorBridge import parsley.generic.ErrorBridge
import parsley.ap._ import parsley.ap._
import parsley.position._ import parsley.position._
import parsley.syntax.zipped._
import cats.data.NonEmptyList import cats.data.NonEmptyList
object ast { object ast {

View File

@@ -1,22 +1,26 @@
// Developed using the VSC language extension tutorial
// https://code.visualstudio.com/api/language-extensions/overview
const vscode = require('vscode'); const vscode = require('vscode');
const { execSync } = require('child_process');
const { parse } = require('path');
function activate(context) { function activate(context) {
console.log('IntelliWACC is now active!'); console.log('IntelliWACC is now active!');
// Create a DiagnosticCollection for error highlighting
let diagnosticCollection = vscode.languages.createDiagnosticCollection('wacc'); let diagnosticCollection = vscode.languages.createDiagnosticCollection('wacc');
context.subscriptions.push(diagnosticCollection); context.subscriptions.push(diagnosticCollection);
// Listen for document saves and run error checking
vscode.workspace.onDidSaveTextDocument((document) => { vscode.workspace.onDidSaveTextDocument((document) => {
if (document.languageId !== 'wacc') return; if (document.languageId !== 'wacc') return;
let diagnostics = []; let diagnostics = [];
let errors = runCompilerAndGetErrors(document.getText()); let errors = generateErrors(document.getText());
errors.forEach(error => { errors.forEach(error => {
let range = new vscode.Range(error.line, error.column, error.line, error.column + 1); console.log(error);
let diagnostic = new vscode.Diagnostic(range, error.message, vscode.DiagnosticSeverity.Error); let range = new vscode.Range(error.line - 1 , error.column - 1, error.line - 1, error.column + error.size);
let diagnostic = new vscode.Diagnostic(range, error.errorMessage, vscode.DiagnosticSeverity.Error);
diagnostics.push(diagnostic); diagnostics.push(diagnostic);
}); });
@@ -28,8 +32,35 @@ function deactivate() {
console.log('IntelliWACC is deactivating...'); console.log('IntelliWACC is deactivating...');
} }
function runCompilerAndGetErrors(code) { function generateErrors(code) {
// COMPILER INTEGRATION try {
const fs = require('fs');
const tmpFilePath = '/tmp/temp_wacc_file.wacc';
fs.writeFileSync(tmpFilePath, code);
let output;
try {
// currently only works if the wacc compiler exe is in the parent directory
output = execSync(`../wacc_exe ${tmpFilePath}`, { encoding: 'utf8', stdio: 'pipe' });
} catch (err) {
output = err.stdout;
}
let errors = [];
errorRegex = /\(line ([\d]+), column ([\d]+)\):\n([^>]+)([^\^]+)([\^]+)\n([^\n]+)([^\(]*)/g
while((match = errorRegex.exec(output)) !== null) {
console.log(match[5]);
errors.push({
line: parseInt(match[1], 10),
column: parseInt(match[2], 10),
errorMessage: match[3].trim(),
size: match[5].length - 1
});
}
return errors;
} catch (err) {
console.error('Error running compiler:', err);
return [];
}
} }
module.exports = { module.exports = {