VSCode Grammar / Autocompletion support for ".Script.txt"
files.
For more information about ManiaScript, see https://doc.maniaplanet.com/maniascript and https://wiki.trackmania.io
This is rewritten and enhanced for typescript, based on MattMcFarland/vscode-maniascript.
You need to extract doc.h
from Trackmania to get the latest ManiaScript API completions working with the extension.
- Create a new folder: use
c:\tmdev
for example to hold the documentation, but it can be anywhere. - Make a new shortcut for the game executable (you find it in your uplay folder) and give it some fancy name (like "trackmania - gendocs") set the starting parameters to following:
trackmania.exe /generatescriptdoc=c:\tmdev\doc.h
- Run your shortcut. if successfull, you get a window saying: press anykey to continue.
- Double check
doc.h
is generated atc:\tmdev\
Next thing is to configure the extension.
- Easiest way to get settings is to
Ctrl + P
and start typing> settings
, other way around is from File->Preferences->Settings->Extensions->ManiaScript. - Add following lines to the settings.json:
"maniascript.apidocPath": "C:\\tmdev\\doc.h",
"maniascript.useManiaplanetApi": false,
you can match the color decorators to your theme by adding:
"workbench.colorCustomizations": {
"maniascript.constColor": "#4FC1FF",
"maniascript.structColor": "#4ec9b0"
}
- All done!
You can use context menu at xml files to preview the manialink, and as well use the command: Ctrl + P
-> > Maniascript: Preview Manialink
List of prefixes what you can expand with tab-key, most of them are quite obvious:
#Include
#Setting
#Const
#Command
#Struct
declare
for
foreach
switch
if
elif
while
Snippet | Description |
---|---|
main |
generate main function with documentation block |
fnc |
generate function declaration with documentation block |
decontrol |
to fast declare CMlcontrol with Page.GetFirstChild |
new |
generate new instance of struct |
PageGet |
generate (Page.GetFirstChild("controltext") as CMlControl) block |
ve2 |
generate vec2 notation <float,float> |
ve3 |
enerate vec3 notation <float, float, float> |
in3 |
generate int3 notation <int,int,int> |
You can set the autocomplete namespace root using two ways:
- Either having Requirecontext at 1st line (which can be a comment too)
#RequireContext CMlScriptIngame
- or having custom context comment block:
/** @context CMlScriptIngame */
I added background color for template strings, so it's easier to spot where templates starts and ends.
TemplateStrings """stringcontent {{{variable}}}"""
are working as normal. Scripts in a templatestring xml will autocomplete as well. Just be sure to have <script><!--
at same line, the regex parser can't figureout if the comment block is next line..sorry for this inconvienience.
You can now force annotate the language used in template strings. Single line template string will try to detect xml opening tag, if so the templatestring is cast to use XML language. For multiline templatestrings use annotations:
Language | Annotation |
---|---|
XML | """//xml |
Manialink XML | """//manialink or """ |
ManiaScript | """//maniascript or """//ms or """//! |
Just add folder to workspace to get libraries load relatively from those directories. so if you have
#Include "Mylib/external.Script.Txt" as MyLib
be sure that MyLib is folder inside workspace library.
AutoCompleting from structure aliasses works as well, example:
#Struct externalLib::myStruct as structAlias
Manialink autocomplete and validation I recently have opened as well a github repository for holding and updating the manialink xsd. You can find it here https://github.com/reaby/manialink-xsd and I'm accepting pull requests, in case you think something is missing :)
Just install XML extension by RedHat for vscode and use this template:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<?xml-model href="https://raw.githubusercontent.com/reaby/manialink-xsd/main/manialink_v3.xsd" ?>
<manialink version="3">
<-- your manialink content here -->
</manialink>
You need just following support extension to activate: Better Jinja Just change the template language at jinja-html, you get instant support for maniascript and jinja2! Twig and jinja2 syntaxes are so close to same, so you can use jinja2-html for twig templates as well :)
You can find the most recent version of the plugin at https://github.com/reaby/maniascript-support Colorizer, currently at patch#4 branch: https://github.com/reaby/ManiaScript.tmLanguage