Skip to content

Commit

Permalink
Fix formatting quirks + migrate from webpack to Rollup (#117)
Browse files Browse the repository at this point in the history
The new version of `wasm-pack` does not work well with `webpack` (the current bundler), so we now take `Rollup` instead. The `wasm` module must now be loaded explicitly in `formatter/index.js`. On the side, fix some quirks of the formatter regarding CONSTRUCT and FROM.
  • Loading branch information
IoannisNezis authored Nov 25, 2024
1 parent 19ebc1f commit 24a43bf
Show file tree
Hide file tree
Showing 7 changed files with 438 additions and 1,339 deletions.
8 changes: 2 additions & 6 deletions backend/static/js/qleverUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,8 @@ $(document).ready(function () {

// Attach format funtion to formatButton.
const formatButton = $("#formatButton");
formatButton.click(async function() {
formatter.then((formatter_fulfilled) => {
editor.setValue(formatter_fulfilled.format(editor.getValue()));
}).catch(() => {
console.error("Could not load formatter library");
});
formatButton.click(function() {
editor.setValue(format(editor.getValue()));
})

// When clicking "Execute", do the following:
Expand Down
5 changes: 4 additions & 1 deletion backend/templates/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<!-- WASM formatter -->
<script src="{% static "js/formatter/index.js" %}"></script>
<script type="module">
import { format } from "{% static '/wasm/formatter/index.js' %}";
window.format = format;
</script>

<!-- Our own JavaScript code for this demo -->
<script src="{% static "js/helper.js" %}"></script>
Expand Down
14 changes: 12 additions & 2 deletions formatter/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { format_raw } from "@ioannisnezis/sparql-language-server"
import init, { format_raw } from 'sparql-language-server/sparql_language_server_web.js';
import wasmModule from 'sparql-language-server/sparql_language_server_web_bg.wasm';

console.info("Loading WebAssembly module...")
wasmModule().then((mod) => {
console.info("Initializing WebAssembly module...")
init(mod).then(() => console.log("WebAssembly module ready!"))
});

function format(text) {

export function format(text) {
return format_raw(text);
}

export { format }
Loading

0 comments on commit 24a43bf

Please sign in to comment.