Skip to content

Commit

Permalink
attempting errormessages
Browse files Browse the repository at this point in the history
  • Loading branch information
sauppb committed Jul 18, 2023
1 parent bfdb687 commit f651d97
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 153 deletions.
8 changes: 4 additions & 4 deletions public/features.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

.completed {
color: white;
background-color: green;
background-color: purple;
border-radius: 5px;
padding: 3px 6px;
}
Expand All @@ -56,7 +56,7 @@

.unlikely-change {
color: white;
background-color: purple;
background-color: green;
border-radius: 5px;
padding: 3px 6px;
}
Expand Down Expand Up @@ -107,13 +107,13 @@ <h2>Completed Features</h2>
<h5>The following are features that are considered to be working:</h5>
<div class="legend">
<div class="legend-item">
<span class="completed">Green</span> - Stable but unfinished
<span class="completed">Purple</span> - Stable but unfinished
</div>
<div class="legend-item">
<span class="upgraded">Blue</span> - Finished but will be upgraded soon
</div>
<div class="legend-item">
<span class="unlikely-change">Purple</span> - Finished and unlikely to change
<span class="unlikely-change">Green</span> - Finished and unlikely to change
</div>
</div>
</div>
Expand Down
10 changes: 4 additions & 6 deletions src/milestone1.js → src/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
// import { highlightError, indextoAceRange } from "./milestone2";
// import { textEditor } from "./milestone2";
// import { block } from "blockly/core/tooltip";
import { sendRuntimeError } from "./milestone2";
import { printBuffer } from "./milestone2";
import { addToPrintBuffer } from "./milestone2";
import { sendRuntimeError } from "./lexer-parser";
import { printBuffer } from "./lexer-parser";
import { addToPrintBuffer } from "./lexer-parser";


var scopes = {};
// export var printBuffer = "";
// export var errorOutput = "";
// export var blockErrorsBuffer = {};




Expand Down
107 changes: 51 additions & 56 deletions src/milestone2.js → src/lexer-parser.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import ace from 'ace-builds';
// import { createExecutable } from './milestone1';
// import { printBuffer } from './milestone1';
// import { clearOutput } from './milestone1';
// import { variables } from 'blockly/blocks';
// import { textError } from './milestone1';



export const textEditor = ace.edit("aceCode", {fontSize: 16});
Expand All @@ -28,11 +24,54 @@ export function clearOutput() {
}


export function textError(type, error, startIndex, endIndex){
var ranges = indextoAceRange(startIndex, endIndex);
errorOutput += `${type} error occured on line line ${ranges[0]}: ${error}<br>`;
// highlightError(ranges, error);
}
// export function textError(type, error, startIndex, endIndex){

// if (endIndex ?? 0 < startIndex){
// endIndex = textEditor?.getValue().length - 1;
// }
// var ranges = indextoAceRange(startIndex, endIndex);
// errorOutput += `${type} error occured on line line ${ranges[0]}: ${error}<br>`;
// var range = new AceRange(rangeArray[0], rangeArray[1], rangeArray[2], rangeArray[3]);
// highlightError(range);
// }


// export function highlightError(range) {
// const marker = document.createElement('div');
// marker.className = 'ace_error';
// marker.style.position = 'absolute';
// marker.style.borderBottom = '1px solid red';
// marker.style.pointerEvents = 'none';
// marker.style.width = '100%';
// marker.style.marginBottom = '-1px';
// marker.style.zIndex = '1';

// const session = textEditor?.getSession();
// const line = range.start.row;
// const rowHeight = session.getRowLength(line) * session.getScreenLineHeight(line);
// marker.style.height = rowHeight + 'px';

// const markerLayer = session.getMarkerLayer('ace_error');
// markerLayer.drawSingleLineMarker(marker, range.start, range.end, session);

// textEditor?.renderer.scrollCursorIntoView({ row: line, column: 0 }, 0.5);
// }

// export function textError(type, error, startIndex, endIndex) {
// const editorValue = textEditor?.getValue();
// if (!editorValue || !startIndex || !endIndex) {
// console.error('Invalid parameters');
// return;
// }

// const range = new AceRange(
// startIndex.row || 0,
// startIndex.column || 0,
// endIndex.row || editorValue.length - 1,
// endIndex.column || editorValue.length - 1
// );
// highlightError(range);
// }



Expand All @@ -46,62 +85,18 @@ export function addBlockErrors(workspace){
}

export function sendRuntimeError(errormessage, blockjson){
if (typeof(blockjson.startIndex !== 'undefined') && typeof(blockjson.endIndex !== 'undefined')){
textError('runtime', errormessage, blockjson.startIndex, blockjson.endIndex);
}
textError('runtime', errormessage, blockjson.startIndex, blockjson.endIndex);
if (typeof(blockjson.blockid !== 'undefined')){
blockErrorsBuffer[blockjson.blockid] = errormessage + '<br>';
}


}



// needs tested
export function highlightError(rangeArray, errorMessage) {
// Get the session from the editor
var session = textEditor?.getSession();

// Convert the range array to an Ace Range object
var range = new AceRange(rangeArray[0], rangeArray[1], rangeArray[2], rangeArray[3]);

// Create a marker for the error range
var marker = session.addMarker(range, "error-marker", "text");

// Create a div element for the error message tooltip
var tooltip = document.createElement('div');
tooltip.className = 'error-tooltip';
tooltip.textContent = errorMessage;

// Calculate the line height based on the editor's font size
var lineHeight = parseInt(textEditor?.renderer?.lineHeight, 10);
}

// Create the marker element and add the tooltip
var markerElement = document.createElement('div');
markerElement.className = 'ace_error-marker';
markerElement.style.top = range.start.row * lineHeight + 'px';
markerElement.style.height = lineHeight + 'px';
markerElement.appendChild(tooltip);

try {
// Find the marker layer's parent container
var markerLayer = session.getMarkerLayer("error-marker");
markerLayer?.element.appendChild(markerElement);

// Add a mouse hover effect to display the error message
markerElement.addEventListener('mouseenter', function() {
tooltip.style.display = 'block';
});

markerElement.addEventListener('mouseleave', function() {
tooltip.style.display = 'none';
});
}
catch(error) {
console.log('error adding the hover effect');
}
}



Expand Down
20 changes: 11 additions & 9 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ import Blockly from 'blockly';
import {praxlyDefaultTheme } from "./theme"
import { PraxlyDark } from './theme';
import {toolbox} from './toolbox';
import { textEditor } from './milestone2';
import { textEditor } from './lexer-parser';

import { tree2text } from './tree2text';
import {definePraxlyBlocks} from './newBlocks';
import { makeGenerator } from './generators';
import { blocks2tree } from './generators';
import { createExecutable } from './milestone1';
import { printBuffer } from './milestone2';
import { clearOutput } from './milestone2';
import { createExecutable } from './ast';
import { printBuffer } from './lexer-parser';
import { clearOutput } from './lexer-parser';
import ace from 'ace-builds';
import "ace-builds/src-min-noconflict/theme-twilight";
import "ace-builds/src-min-noconflict/theme-katzenmilch";
import { tree2blocks } from './tree2blocks';
import { errorOutput } from './milestone2';
import { text2tree } from './milestone2';
import { errorOutput } from './lexer-parser';
import { text2tree } from './lexer-parser';
import { generateUrl, loadFromUrl } from './share';
import { colour } from 'blockly/blocks';

Expand All @@ -37,7 +37,7 @@ const blockUpdatesButton = document.getElementById('blockUpdates');
let darkMode = false;
let live = true;

runButton.addEventListener('click', () => {
runButton.addEventListener('mouseup', () => {
clearOutput();
// mainTree = blocks2tree(workspace, praxlyGenerator);
if (mainTree === null){
Expand Down Expand Up @@ -178,21 +178,23 @@ darkModeButton.addEventListener('click', ()=> {
);

blockUpdatesButton.innerText = 'block updates: live ';
workspace.addChangeListener( turnBlocksToCode);
workspace.addChangeListener( turnBlocksToCode);
textEditor.addEventListener("input", turnCodeToBLocks);


blockUpdatesButton.addEventListener('click', () => {

if (!live){
runButton.removeEventListener('mousedown', turnCodeToBLocks);
blockUpdatesButton.innerText = 'block updates: live ';
workspace.addChangeListener( turnBlocksToCode);
textEditor.addEventListener("input", turnCodeToBLocks);
live = true;
} else {
blockUpdatesButton.innerText = 'block updates: on run (not implimented yet)';
workspace.removeChangeListener(turnBlocksToCode);
blockUpdatesButton.innerText = 'block updates: on save (not implimented yet)';
textEditor.removeEventListener("input", turnCodeToBLocks);
runButton.addEventListener('mousedown', turnCodeToBLocks);
live = false;
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/share.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import { textEditor } from "./milestone2";
import { textEditor } from "./lexer-parser";

export function generateUrl() {
// yank the text in ace
Expand Down
Loading

0 comments on commit f651d97

Please sign in to comment.