diff --git a/web/mta_highlighting/generate-lua-tmlanguage.js b/web/mta_highlighting/generate-lua-tmlanguage.js index 88f91f5b..8eec6699 100644 --- a/web/mta_highlighting/generate-lua-tmlanguage.js +++ b/web/mta_highlighting/generate-lua-tmlanguage.js @@ -10,6 +10,7 @@ const __dirname = path.dirname(__filename); const functionsDir = path.resolve(__dirname, '../../functions'); const basePath = path.resolve(__dirname, './lua-base.tmLanguage.json'); const outputPath = path.resolve(__dirname, '../src/grammars/lua-mta.tmLanguage.json'); +const publicPath = path.resolve(__dirname, '../public/lua-mta.tmLanguage.json'); const mtaKeywords = ['string','bool','boolean','number','int','float','element','player','vehicle','ped','object','building']; @@ -58,8 +59,11 @@ async function generateTmLanguage() { // Ensure the directory exists fs.mkdirSync(path.dirname(outputPath), { recursive: true }); - fs.writeFileSync(outputPath, JSON.stringify(baseGrammar, null, 2)); + + // Create file also in public directory for clickable keywords (public/mta-keywords_linker.js) + fs.copyFileSync(outputPath, publicPath); + console.log(`Done!`); } diff --git a/web/public/mta-keywords_linker.js b/web/public/mta-keywords_linker.js index 599e3ff3..2eb91d45 100644 --- a/web/public/mta-keywords_linker.js +++ b/web/public/mta-keywords_linker.js @@ -1,11 +1,11 @@ -import tmLanguage from "../src/grammars/lua-mta.tmLanguage.json"; +let allFunctions = new Set(); -function extractFunctions() { +function extractFunctions(tmLanguage) { const wantedScopes = new Set([ "support.function.mta-shared", "support.function.mta-server", "support.function.mta-client", - 'keyword.mta' + "keyword.mta" ]); return tmLanguage.patterns?.reduce((funcs, { match, name }) => { @@ -16,8 +16,6 @@ function extractFunctions() { }, []) || []; } -const allFunctions = new Set(extractFunctions()); - function initKeywordLinker() { function onDomReady() { const spans = [ @@ -33,9 +31,15 @@ function initKeywordLinker() { }); } - document.readyState === "loading" - ? window.addEventListener("DOMContentLoaded", onDomReady) - : onDomReady(); + fetch('/lua-mta.tmLanguage.json') + .then(res => res.json()) + .then(json => { + allFunctions = new Set(extractFunctions(json)); + document.readyState === "loading" + ? window.addEventListener("DOMContentLoaded", onDomReady) + : onDomReady(); + }) + .catch(err => console.error("Failed to load JSON grammar:", err)); } initKeywordLinker();