docs: Update tree-sitter

Updated web-tree-sitter and the devicetree grammar.

web-tree-sitter now supports a custom function to locate its .wasm file,
so performing a string replace is no longer necessary to get it to work
with Docusaurus' Webpack configuration. We now check when tree-sitter is
locating its .wasm file and provide the Webpack-adjusted URL.
This commit is contained in:
Joel Spadin
2023-04-23 16:55:01 -05:00
committed by Pete Johanson
parent c6bf95a901
commit dae020787e
5 changed files with 22 additions and 39 deletions

View File

@@ -2,10 +2,23 @@ import Parser from "web-tree-sitter";
import { Codes, Behaviors } from "./data/keymap-upgrade";
const TREE_SITTER_WASM_URL = new URL(
"/node_modules/web-tree-sitter/tree-sitter.wasm",
import.meta.url
);
let Devicetree;
export async function initParser() {
await Parser.init();
await Parser.init({
locateFile: (path, prefix) => {
// When locating tree-sitter.wasm, use a path that Webpack can map to the correct URL.
if (path == "tree-sitter.wasm") {
return TREE_SITTER_WASM_URL.href;
}
return prefix + path;
},
});
Devicetree = await Parser.Language.load("/tree-sitter-devicetree.wasm");
}