Skip to content

Commit ea4a418

Browse files
committed
MTA keywords improvement
From now on, keywords are generated based on the elements and types directories instead of a static array.
1 parent 53a13d8 commit ea4a418

File tree

8 files changed

+13
-4
lines changed

8 files changed

+13
-4
lines changed

types/bool.yaml

Whitespace-only changes.

types/boolean.yaml

Whitespace-only changes.

types/element.yaml

Whitespace-only changes.

types/float.yaml

Whitespace-only changes.

types/int.yaml

Whitespace-only changes.

types/number.yaml

Whitespace-only changes.

types/string.yaml

Whitespace-only changes.

web/mta_highlighting/generate-lua-tmlanguage.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ const __filename = fileURLToPath(import.meta.url);
88
const __dirname = path.dirname(__filename);
99

1010
const functionsDir = path.resolve(__dirname, '../../functions');
11+
const elementsDir = path.resolve(__dirname, '../../elements');
12+
const typesDir = path.resolve(__dirname, '../../types');
13+
1114
const basePath = path.resolve(__dirname, './lua-base.tmLanguage.json');
1215
const outputPath = path.resolve(__dirname, '../src/grammars/lua-mta.tmLanguage.json');
1316
const publicPath = path.resolve(__dirname, '../public/grammars/lua-mta.tmLanguage.json');
1417

15-
const mtaKeywords = ['string','bool','boolean','number','int','float','element','player','vehicle','ped','object','building'];
16-
1718
function extractFunctionsWithScope(yamlContent) {
1819
if (yamlContent.shared?.name) {
1920
return [{ name: yamlContent.shared.name, scope: 'support.function.mta-shared' }];
@@ -40,16 +41,24 @@ async function generateTmLanguage() {
4041
items.flatMap(extractFunctionsWithScope).forEach(({ name, scope }) => functionsMap[scope].add(name));
4142
});
4243

44+
const elementFiles = await glob('**/*.yaml', { cwd: elementsDir, absolute: true });
45+
const elementKeywords = elementFiles.map(file => path.basename(file, '.yaml'));
46+
47+
const typeFiles = await glob('**/*.yaml', { cwd: typesDir, absolute: true });
48+
const typeKeywords = typeFiles.map(file => path.basename(file, '.yaml'));
49+
4350
const patterns = Object.entries(functionsMap)
4451
.filter(([, namesSet]) => namesSet.size > 0)
4552
.map(([scope, namesSet]) => ({
4653
match: `\\b(${Array.from(namesSet).join('|')})\\b`,
4754
name: scope,
4855
}));
4956

50-
if (mtaKeywords.length > 0) {
57+
const allKeywords = [...elementKeywords, ...typeKeywords];
58+
59+
if (allKeywords.length > 0) {
5160
patterns.push({
52-
match: `\\b(${mtaKeywords.join('|')})\\b`,
61+
match: `\\b(${allKeywords.join('|')})\\b`,
5362
name: 'keyword.mta',
5463
});
5564
}

0 commit comments

Comments
 (0)