Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion web/mta_highlighting/generate-lua-tmlanguage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand Down Expand Up @@ -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!`);
}

Expand Down
20 changes: 12 additions & 8 deletions web/public/mta-keywords_linker.js
Original file line number Diff line number Diff line change
@@ -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 }) => {
Expand All @@ -16,8 +16,6 @@ function extractFunctions() {
}, []) || [];
}

const allFunctions = new Set(extractFunctions());

function initKeywordLinker() {
function onDomReady() {
const spans = [
Expand All @@ -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();