forked from kofal.net/zmk
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:
committed by
Pete Johanson
parent
c6bf95a901
commit
dae020787e
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user