Skip to content

Commit cee7130

Browse files
FileEXNico8340
andauthored
Fix clickable keywords on build (#17)
Co-authored-by: Nico <[email protected]>
1 parent a9d1e45 commit cee7130

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

web/mta_highlighting/generate-lua-tmlanguage.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const __dirname = path.dirname(__filename);
1010
const functionsDir = path.resolve(__dirname, '../../functions');
1111
const basePath = path.resolve(__dirname, './lua-base.tmLanguage.json');
1212
const outputPath = path.resolve(__dirname, '../src/grammars/lua-mta.tmLanguage.json');
13+
const publicPath = path.resolve(__dirname, '../public/lua-mta.tmLanguage.json');
1314

1415
const mtaKeywords = ['string','bool','boolean','number','int','float','element','player','vehicle','ped','object','building'];
1516

@@ -58,8 +59,11 @@ async function generateTmLanguage() {
5859

5960
// Ensure the directory exists
6061
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
61-
6262
fs.writeFileSync(outputPath, JSON.stringify(baseGrammar, null, 2));
63+
64+
// Create file also in public directory for clickable keywords (public/mta-keywords_linker.js)
65+
fs.copyFileSync(outputPath, publicPath);
66+
6367
console.log(`Done!`);
6468
}
6569

web/public/mta-keywords_linker.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import tmLanguage from "../src/grammars/lua-mta.tmLanguage.json";
1+
let allFunctions = new Set();
22

3-
function extractFunctions() {
3+
function extractFunctions(tmLanguage) {
44
const wantedScopes = new Set([
55
"support.function.mta-shared",
66
"support.function.mta-server",
77
"support.function.mta-client",
8-
'keyword.mta'
8+
"keyword.mta"
99
]);
1010

1111
return tmLanguage.patterns?.reduce((funcs, { match, name }) => {
@@ -16,8 +16,6 @@ function extractFunctions() {
1616
}, []) || [];
1717
}
1818

19-
const allFunctions = new Set(extractFunctions());
20-
2119
function initKeywordLinker() {
2220
function onDomReady() {
2321
const spans = [
@@ -33,9 +31,15 @@ function initKeywordLinker() {
3331
});
3432
}
3533

36-
document.readyState === "loading"
37-
? window.addEventListener("DOMContentLoaded", onDomReady)
38-
: onDomReady();
34+
fetch('/lua-mta.tmLanguage.json')
35+
.then(res => res.json())
36+
.then(json => {
37+
allFunctions = new Set(extractFunctions(json));
38+
document.readyState === "loading"
39+
? window.addEventListener("DOMContentLoaded", onDomReady)
40+
: onDomReady();
41+
})
42+
.catch(err => console.error("Failed to load JSON grammar:", err));
3943
}
4044

4145
initKeywordLinker();

0 commit comments

Comments
 (0)