-
Notifications
You must be signed in to change notification settings - Fork 10
Custom syntax highlighting & clickable keywords #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Fernando-A-Rocha
merged 8 commits into
multitheftauto:main
from
FileEX:feature/custom_syntax_highlighting
May 25, 2025
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a38b9f8
Custom syntax highlighting
FileEX 3f8e03b
auto run generate-lua-tmlanguage
FileEX e48cd01
Fix syntax highlight
FileEX ff0f65b
Clickable keywords and functions
FileEX 9ed8a79
Ignore tmLanguage
FileEX 259a7cd
Merge branch 'main' into feature/custom_syntax_highlighting
Nico8340 40f2a21
Merge branch 'main' into feature/custom_syntax_highlighting
Nico8340 22b7a14
Merge branch 'main' into feature/custom_syntax_highlighting
Nico8340 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,6 @@ pnpm-debug.log* | |
|
||
# macOS-specific files | ||
.DS_Store | ||
|
||
# tmLanguage file | ||
src/grammars/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import fs from 'fs'; | ||
|
||
export default { | ||
themes: [ | ||
JSON.parse(fs.readFileSync('./src/themes/mtasa_lua-theme_dark.json', 'utf-8')), | ||
JSON.parse(fs.readFileSync('./src/themes/mtasa_lua-theme_light.json', 'utf-8')), | ||
], | ||
shiki: { | ||
langs: [ | ||
{ | ||
id: 'lua', | ||
scopeName: 'source.lua.mta', | ||
...JSON.parse(fs.readFileSync('./src/grammars/lua-mta.tmLanguage.json', 'utf-8')), | ||
}, | ||
], | ||
}, | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import yaml from 'js-yaml'; | ||
import { glob } from 'glob'; | ||
import { fileURLToPath } from 'url'; | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
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 mtaKeywords = ['string','bool','boolean','number','int','float','element','player','vehicle','ped','object','building']; | ||
|
||
function extractFunctionsWithScope(yamlContent) { | ||
if (yamlContent.shared?.name) { | ||
return [{ name: yamlContent.shared.name, scope: 'support.function.mta-shared' }]; | ||
} else if (yamlContent.client?.name) { | ||
return [{ name: yamlContent.client.name, scope: 'support.function.mta-client' }]; | ||
} else if (yamlContent.server?.name) { | ||
return [{ name: yamlContent.server.name, scope: 'support.function.mta-server' }]; | ||
} | ||
return []; | ||
} | ||
|
||
async function generateTmLanguage() { | ||
const files = await glob('**/*.yaml', { cwd: functionsDir, absolute: true }); | ||
|
||
const functionsMap = Object.fromEntries( | ||
['shared', 'server', 'client'].map(scope => [`support.function.mta-${scope}`, new Set()]) | ||
); | ||
|
||
files.forEach(file => { | ||
const yamlContent = yaml.load(fs.readFileSync(file, 'utf-8')); | ||
console.log('Processing file:', file); | ||
|
||
const items = Array.isArray(yamlContent) ? yamlContent : [yamlContent]; | ||
items.flatMap(extractFunctionsWithScope).forEach(({ name, scope }) => functionsMap[scope].add(name)); | ||
}); | ||
|
||
const patterns = Object.entries(functionsMap) | ||
.filter(([, namesSet]) => namesSet.size > 0) | ||
.map(([scope, namesSet]) => ({ | ||
match: `\\b(${Array.from(namesSet).join('|')})\\b`, | ||
name: scope, | ||
})); | ||
|
||
if (mtaKeywords.length > 0) { | ||
patterns.push({ | ||
match: `\\b(${mtaKeywords.join('|')})\\b`, | ||
name: 'keyword.mta', | ||
}); | ||
} | ||
|
||
const baseGrammar = JSON.parse(fs.readFileSync(basePath, 'utf-8')); | ||
baseGrammar.patterns = [...patterns, ...(baseGrammar.patterns || [])]; | ||
|
||
fs.writeFileSync(outputPath, JSON.stringify(baseGrammar, null, 2)); | ||
console.log(`Done!`); | ||
} | ||
|
||
generateTmLanguage(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@echo off | ||
node generate-lua-tmlanguage.js | ||
pause |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.